一時的なオーバーライド (Foo.pm) package Foo; use strict; use warnings; sub bar { my $baz = shift; $baz * 2; } 1; (hoge.pl) #!/usr/bin/perl use strict; use warnings; use Perl6::Say; use Foo; say Foo::bar(3); # 6 { no warnings 'redefine'; local *Foo::bar = sub { my $baz = shift; $baz ** 2; }; say Foo::bar(3); # 9 } say Foo::bar(3); # 6 関数を、local で一時的に上書きする。 no warnings 'redefine'; は関数の再定義を許してね、という宣言。 no warnin
![Perl の関数をオーバーライドする](https://cdn-ak-scissors.b.st-hatena.com/image/square/4644130890c08da2ce60cc24d89ce5318904794c/height=288;version=1;width=512/https%3A%2F%2Fimg.bayashi.net%2Ffavicon.png)