Last active
April 29, 2022 16:30
-
-
Save jjn1056/4f300ee251e4ff28879e879c3b068d78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use warnings; | |
use strict; | |
use Class::Method::Modifiers; | |
sub myfunc1 { | |
return join(' ', @_); | |
} | |
sub myfunc2 { | |
return join(' ', @_) .' | '. myfunc1('a','b') | |
} | |
warn myfunc2(1,2); | |
*oldmyfunc1 = \&myfunc1; | |
around 'myfunc2', sub { | |
my $sub = shift; | |
my $arg_to_forward = shift; | |
local *myfunc1; | |
*myfunc1 = sub { &oldmyfunc1(@_, $arg_to_forward) }; | |
return $sub->(@_); | |
}; | |
warn myfunc2('c',1,2); | |
__END__ | |
$ perl test.pl | |
1 2 | a b at test.pl line 13. | |
1 2 | a b c at test.pl line 24. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment