Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://296999]
help
Chatterbox?
[LanX]: hmm   Chatterbox FAQ doesn't talk about breaking up long words
[marto]: breakin' up is hard to do
[LanX]: 123456789012345678 90 123456789012345678 901234567890
LanX should break up with false friends ;)
[Discipulus]: last hour of cb breaks it differently..

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-07-24 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (350 votes). Check out past polls.