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

Re: Moose and OOP in Perl

by tobyink (Canon)
on May 09, 2013 at 21:35 UTC ( [id://1032851]=note: print w/replies, xml ) Need Help??


in reply to Moose and OOP in Perl

moritz' answer is perfectly good. Here's another in the spirit of TIMTOWTDI. It uses builders instead of defaults. (Slightly slower object construction, but generally considered a cleaner way of doing things in terms of making it easier for subclassing.)

my @ldap_attrs = qw( ssl host port retry timeout version loginID loginPW logging ); use constant { _build_ssl => 1, _build_port => 12345, _build_timeout => 42, }; has $_ => ( is => "rw", reader => "get_$_", writer => "set_$_", required => 0, __PACKAGE__->can("_build_$_") ? (builder => "_build_$_") : (), ) for @ldap_attrs;
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2024-04-23 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found