Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by tye (Sage)
on Oct 06, 2003 at 16:50 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://296999]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-29 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found