Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How do YOU do OO in Perl?

by Juerd (Abbot)
on Oct 10, 2003 at 06:54 UTC ( #298179=note: print w/ replies, xml ) Need Help??


in reply to How do YOU do OO in Perl?

My OO style is simple and clean, thanks to Attribute::Property:

package Some::Class; sub new : New { my ($self) = @_; exists $self->{$_} or croak "Mandatory argument '$_' missing" for qw(id foo); return $self; } sub id : Property { /^\d+\z/ } sub foo : Property; sub bar : Property; sub blah : Property { $_ < 50 } sub _private : method { my ($self) = @_; ... } sub do_something : method { my ($self, $quux) = @_; ... }
And this is how you use this Some::Class:
my $thing = Some::Class->new( id => 15, foo => "Hello" ); $thing->foo =~ s/e/a/; $thing->id++; $thing->do_something($$); $thing->blah = 10; $thing->blah = 60; # dies
See also $foo->bar = 14; and $foo->bar = 14; revisited: Attribute::Property.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


Comment on Re: How do YOU do OO in Perl?
Select or Download Code
Re: Re: How do YOU do OO in Perl?
by batkins (Chaplain) on Oct 10, 2003 at 10:26 UTC
    That's very clean, indeed. I think I'll try combining it with Acme::Dot. Thanks for the info.

    Bill

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-08-21 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (136 votes), past polls