Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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 avoiding work at the Monastery: (11)
As of 2015-10-07 11:15 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (179 votes), past polls