http://qs321.pair.com?node_id=1153992


in reply to Autoclearing all accessors in a Mouse/Moose class

has is a subroutine as any other. You can call it in a loop, you can pass variables as its arguments.
for my $attr (qw( country customer_number ticket_type )) { my $reader = "get_$attr"; my $clearer = "clear_$attr"; has $attr => ( is => 'rw', reader => $reader, writer => "set_$attr", predicate => "has_$attr", clearer => $clearer, trigger => sub { my ($self) = @_; if (! defined $self->$reader || $self->$reader eq '' ) + { $self->$clearer; } } ); }

Notice I switched the two conditions in the || to prevent warnings about undefined.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,