, .
, , .
,
before foo => sub {
}
:
my $orig = *package::foo;
*package::foo = sub {
$beforetrigger->( @args );
return $orig->( @args );
}
.
, , 2 subs, "A", BuildMenu, , "B", BuildMenu, .
, , :
First Call ->
A ->
before ->
apply roles ->
replace A with B
<
A body ->
<
Subsequent Call
B -> something
Etc, , , , .
around foo => sub {
my ( $orig, $self , @args ) = @_;
my $wrapped_sub = $self->can('foo');
my $rval = $wrapped_sub->( $self, @args );
return $wrapped_sub->( $self, @args );
}
, , $wrapped_sub - , , ,... , , , - .
, , , sub, sub, , , , , " " , =)