See the F<t/Sub-Op-LexicalSub> directory that implements a complete example.
+=head1 CAVEATS
+
+Preexistent definitions of a sub whose name is handled by L<Sub::Op> are restored at the end of the lexical scope in which the module is used.
+But if you define a sub in the scope of action of L<Sub::Op> with a name that is currently being replaced, the new declaration will be obliterated at the scope end.
+
=head1 DEPENDENCIES
L<perl> 5.10.
use blib 't/Sub-Op-LexicalSub';
-use Test::More tests => 2 * ((2 + 2) * 4 + (1 + 2) * 5) + (2 + 2) + 4;
+use Test::More tests => 2 * ((2 + 2) * 4 + (1 + 2) * 5) + 2 * (2 + 2) + 4;
our $call_foo;
sub foo { ok $call_foo, 'the preexistent foo was called' }
sub X () { 1 }
+our $call_blech;
+sub blech { ok $call_blech, 'initial blech was called' };
+
our $called;
{
}
$test .= "{\n$code\n}\n";
$test .= "}\n";
- for my $name (grep +{ map +($_, 1), qw/foo bar/ }->{ $_ }, @names) {
+ for my $name (grep +{ map +($_, 1), qw/foo bar blech/ }->{ $_ }, @names) {
$test .= <<" CHECK_SUB"
{
local \$call_$name = 1;
is X, 2, 'constant overriding';
----
X # 2 # [ ]
+####
+no warnings 'redefine';
+sub blech { fail 'redefined blech was called' }
+BEGIN { $call_blech = 0 }
+blech 7;
+BEGIN { $call_blech = 1 }
+----
+blech # () # [ 7 ]