criticisms, comments on newest module please

Peter Scott peter at PSDT.com
Wed Jan 22 14:45:44 CST 2003


At 12:28 PM 1/22/03 -0800, nkuipers wrote:
> >sub AUTOLOAD {
> >         (my $meth = our $AUTOLOAD) =~ s/.*:://;  # Untested
> >         {id => 1, desc => 1, seq => 1}->{$meth} and return $_[0]->{$meth};
> >         carp "Called undefined subroutine \"$meth\"";
> >}
>
>A couple of questions here.  First, is it common practice to catch accessor
>methods with AUTOLOAD()?

More or less.  There are various modules that encapsulate this for you, 
and they add the trick that once a method is called, they instantiate 
an actual subroutine to do that job so the next time it's called it 
goes straight to the real method.  Like to see Java or C++ do that...

>Second, I'm not familiar with the
>{id=>1,...}->{$meth} notation.  Is this effectively the same as
>
>my %validcalls = (id=>1,desc=>1,seq=>1);
>$validcalls{$meth} ? return $_[0]->$meth : carp ...;

Yep.  Here's how to read it: got an arrow, so there's 
dereferencing.  Right hand side is {}, so left hand side must be 
reference to hash.  And indeed it is, to an anonymous hash.  Nothing 
you haven't seen before.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/




More information about the Victoria-pm mailing list