in reply to Moose attribute predicate alternative

I do not know Moose in detail, so I cannot comment on the design. To not repeat yourself (DRY), though, you can use method names in variables:
for my $att (qw/x y w h/) { my $predicate = "has_$att"; $attr{$att} = $self->$att if $self->$predicate; }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Moose attribute predicate alternative
by tobyink (Canon) on Jul 04, 2013 at 14:35 UTC

    Or even:

    $attr{$_} = $self->$_ if $self->${\"has_$_"} for qw/x y w h/;
    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
        ++$a and print $a for qw/ x y y y /;
Re^2: Moose attribute predicate alternative
by antmico (Novice) on Jul 04, 2013 at 15:53 UTC
    Thanks for the suggestion, that removes the repetition that was primarily bothering me. Thanks all.