http://www.perlmonks.org?node_id=1022647


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