Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Perl's equivalent to Python's hasattr and getattr? (class variable details)

by rlb3 (Deacon)
on Jul 28, 2005 at 20:03 UTC ( [id://479182]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^2: Perl's equivalent to Python's hasattr and getattr? (class variable details)
in thread Perl's equivalent to Python's hasattr and getattr? (class variable details)

Class::Accessor is built using the symbol table. Here is the _mk_accessors as an example.

{ no strict 'refs'; sub _mk_accessors { my($self, $maker, @fields) = @_; my $class = ref $self || $self; # So we don't have to do lots of lookups inside the loop. $maker = $self->can($maker) unless ref $maker; foreach my $field (@fields) { if( $field eq 'DESTROY' ) { require Carp; &Carp::carp("Having a data accessor named DESTROY in +". "'$class' is unwise."); } my $accessor = $self->$maker($field); my $alias = "_${field}_accessor"; *{$class."\:\:$field"} = $accessor unless defined &{$class."\:\:$field"}; *{$class."\:\:$alias"} = $accessor unless defined &{$class."\:\:$alias"}; } } }
  • Comment on Re^3: Perl's equivalent to Python's hasattr and getattr? (class variable details)
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://479182]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.