Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Last active April 29, 2022 16:30
Show Gist options
  • Save jjn1056/4f300ee251e4ff28879e879c3b068d78 to your computer and use it in GitHub Desktop.
Save jjn1056/4f300ee251e4ff28879e879c3b068d78 to your computer and use it in GitHub Desktop.
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