in reply to Autoclearing all accessors in a Mouse/Moose class
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,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Autoclearing all accessors in a Mouse/Moose class
by yulivee07 (Sexton) on Jan 29, 2016 at 14:48 UTC |