Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Variables in Common parent class

by tobyink (Abbot)
on Mar 10, 2013 at 06:34 UTC ( #1022647=note: print w/ replies, xml ) Need Help??


in reply to Re: Variables in Common parent class
in thread Variables in Common parent class

All generally good advice, but for the constructors in the children, I'd prefer:

sub new { my ($class, %params) = @_; my $self = $class->SUPER::new(%params); $self->{block_name} = $params{'block name'}; return $self; }

This ensures that the parent constructor is called as a method (and thus obeys inheritance).

There's no need to re-bless $self.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re^2: Variables in Common parent class
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2015-07-30 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls