1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
use Test::More tests => 6;
package Foo1 {
use constant BAR => 7;
sub baz { BAR }
}
BEGIN {
no warnings 'redefine';
is( Foo1::baz, 7, 'Constant set right initially' );
*Foo1::BAR = sub { 42 };
is( Foo1::baz, 7, 'Constants are inlined' );
}
package Foo2 {
use unconstant;
use constant BAR => 7;
sub baz { BAR }
}
BEGIN {
no warnings 'redefine';
is( Foo2::baz, 7, 'Constant set right initially' );
*Foo2::BAR = sub { 42 };
is( Foo2::baz, 42, 'Constant not inlined' );
}
package Foo3 {
use unconstant;
no unconstant;
use constant BAR => 7;
sub baz { BAR }
}
BEGIN {
no warnings 'redefine';
is( Foo3::baz, 7, 'Constant set right initially' );
*Foo3::BAR = sub { 42 };
is( Foo3::baz, 7, 'Constant are inlined again after use of [no constant]' );
}
1;
|