Sub attributes provide a fairly nice alternative...
use 5.014; package Foo { sub new { bless [] } use Attribute::Handlers; use Class::Method::Modifiers qw(before); sub City :ATTR { my $method = substr *{$_[1]}, 1; before $method => sub { my ($self) = @_; print "** Preparing...\n"; push @{$self}, 'money'; print "** Ready to continue...\n"; }; } sub Berlin :City { my $self = shift; print "> I'm in Berlin!\n"; } sub Paris :City { my $self = shift; print "> I'm in Paris!\n"; } }; my $obj = Foo->new; $obj->Berlin(); say "# Self contains: @{$obj}";
In reply to Re^3: Calling an intermediate method
by tobyink
in thread Calling an intermediate method
by trizen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |