Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: How do YOU do OO in Perl? (constant offsets)

by tye (Sage)
on Oct 06, 2003 at 16:50 UTC ( #296999=note: print w/ replies, xml ) Need Help??

in reply to How do YOU do OO in Perl?

I'm partial to const subs and namespace purity:

package My::Class; use vars qw( $VERSION ); BEGIN { $VERSION= 1.01 } package My::Class::_implement; BEGIN { my $offset= 0; for my $member ( qw( FOO BAR BAZ BIF ) ) { eval "sub $member() { $offset }; 1" or die "eval failed: $@"; $offset++; } } sub My::Class::GetObjectPackage { my $class= shift(@_); return $class . "::Object"; } sub My::Class::new { my $class= shift(@_); bless [], $class->GetObjectPackage(); } sub My::Class::Object::Foo { my $self= shift(@_); my $value= $self->[FOO]; $self->[FOO]= shift(@_) if @_; return $value; }

                - tye

Comment on Re: How do YOU do OO in Perl? (constant offsets)
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://296999]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2015-11-27 15:38 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (731 votes), past polls