Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://296999]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2017-02-27 22:11 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (393 votes). Check out past polls.