develooper Front page | perl.perl5.porters | Postings from October 2005

attributes.pm doc typo?

Thread Next
From:
Jeff 'japhy' Pinyan
Date:
October 28, 2005 09:59
Subject:
attributes.pm doc typo?
Message ID:
Pine.LNX.4.61.0510281246480.25597@perlmonk.org
Quoth the POD:

"FETCH_type_ATTRIBUTES

This method receives a single argument, which is a reference to the 
variable or subroutine for which package-defined attributes are desired. 
The expected return value is a list of associated attributes. This list 
may be empty."

Um, is that so?

   use strict;
   use warnings;
   use attributes ();

   {
     package Tie::StopWatch;

     sub TIESCALAR { my $class = shift; bless \time, $class }
     sub FETCH { my $self = shift; time - $$self; }
     sub STORE { my $self = shift; $$self = @_ ? shift : time }

     my %attr;

     sub FETCH_SCALAR_ATTRIBUTES {
       print "FETCH: <@_>\n";
       my ($pkg, $var) = @_;
       return keys %{ $attr{$var} };
     }

     sub MODIFY_SCALAR_ATTRIBUTES {
       my $pkg = shift;
       my $var = shift;
       my @bad;

       for (@_) {
         if ($_ eq 'Timer') {
           $attr{ tie $$var, 'Tie::StopWatch' }{$_} = 1;
         }
         else {
           push @bad, $_;
         }
       }

       return @bad;
     }
   }

   my Tie::StopWatch $x :Timer;
   print "tied \$x: <@{[ attributes::get(tied $x) ]}>\n";

Running this yields:

   FETCH: <Tie::StopWatch Tie::StopWatch=SCALAR(0x8198924)>
   tied $x: <Timer>

Unless the POD has been corrected already (pending 5.8.8), this needs a 
patch.  Now, looking at the code, I see:

     my $stash = _guess_stash $svref;
     $stash = caller unless defined $stash;
     my $pkgmeth;
     $pkgmeth = UNIVERSAL::can($stash, "FETCH_${svtype}_ATTRIBUTES")
         if defined $stash && $stash ne '';
     return $pkgmeth ?
                 (_fetch_attrs($svref), $pkgmeth->($stash, $svref)) :
                 (_fetch_attrs($svref))

So $stash is the package that the reference resides in, right?  Once this 
has been confirmed for me, I can produce a doc patch.

-- 
Jeff "japhy" Pinyan        %  How can we ever be the sold short or
RPI Acacia Brother #734    %  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %    -- Meister Eckhart

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About