Check strict vars functionality __END__ # no strict, should build & run ok. Fred ; my $fred ; $b = "fred" ; $a = $$b ; EXPECT ######## use strict qw(subs refs) ; $fred ; EXPECT ######## use strict ; no strict 'vars' ; $fred ; EXPECT ######## # strict vars - no error use strict 'vars' ; use vars qw( $freddy) ; local $abc::joe ; my $fred ; my $b = \$fred ; $Fred::ABC = 1 ; $freddy = 2 ; EXPECT ######## # strict vars - error use strict ; $fred ; EXPECT Global symbol "$fred" requires explicit package name at - line 4. Execution of - aborted due to compilation errors. ######## # strict vars - error use strict 'vars' ; $fred ; EXPECT Global symbol "$fred" requires explicit package name at - line 4. Execution of - aborted due to compilation errors. ######## # strict vars - error use strict 'vars' ; local $fred ; EXPECT Global symbol "$fred" requires explicit package name at - line 4. Execution of - aborted due to compilation errors. ######## # Check compile time scope of strict vars pragma use strict 'vars' ; { no strict ; $joe = 1 ; } $joe = 1 ; EXPECT Variable "$joe" is not imported at - line 8. Global symbol "$joe" requires explicit package name at - line 8. Execution of - aborted due to compilation errors. ######## # Check compile time scope of strict vars pragma no strict; { use strict 'vars' ; $joe = 1 ; } $joe = 1 ; EXPECT Global symbol "$joe" requires explicit package name at - line 6. Execution of - aborted due to compilation errors. ######## --FILE-- abc $joe = 1 ; 1; --FILE-- use strict 'vars' ; require "./abc"; EXPECT ######## --FILE-- abc use strict 'vars' ; 1; --FILE-- require "./abc"; $joe = 1 ; EXPECT ######## --FILE-- abc use strict 'vars' ; $joe = 1 ; 1; --FILE-- $joe = 1 ; require "./abc"; EXPECT Variable "$joe" is not imported at ./abc line 2. Global symbol "$joe" requires explicit package name at ./abc line 2. Compilation failed in require at - line 2. ######## --FILE-- abc.pm use strict 'vars' ; $joe = 1 ; 1; --FILE-- $joe = 1 ; use abc; EXPECT Variable "$joe" is not imported at abc.pm line 2. Global symbol "$joe" requires explicit package name at abc.pm line 2. Compilation failed in require at - line 2. BEGIN failed--compilation aborted at - line 2. ######## # Check scope of pragma with eval no strict ; eval { $joe = 1 ; }; print STDERR $@; $joe = 1 ; EXPECT ######## # Check scope of pragma with eval no strict ; eval { use strict 'vars' ; $joe = 1 ; }; print STDERR $@; $joe = 1 ; EXPECT Global symbol "$joe" requires explicit package name at - line 6. Execution of - aborted due to compilation errors. ######## # Check scope of pragma with eval use strict 'vars' ; eval { $joe = 1 ; }; print STDERR $@; $joe = 1 ; EXPECT Global symbol "$joe" requires explicit package name at - line 5. Global symbol "$joe" requires explicit package name at - line 8. Execution of - aborted due to compilation errors. ######## # Check scope of pragma with eval use strict 'vars' ; eval { no strict ; $joe = 1 ; }; print STDERR $@; $joe = 1 ; EXPECT Variable "$joe" is not imported at - line 9. Global symbol "$joe" requires explicit package name at - line 9. Execution of - aborted due to compilation errors. ######## # Check scope of pragma with eval no strict ; eval ' $joe = 1 ; '; print STDERR $@ ; $joe = 1 ; EXPECT ######## # Check scope of pragma with eval no strict ; eval q[ use strict 'vars' ; $joe = 1 ; ]; print STDERR $@; EXPECT Global symbol "$joe" requires explicit package name at (eval 1) line 3. ######## # Check scope of pragma with eval use strict 'vars' ; eval ' $joe = 1 ; '; print STDERR $@ ; EXPECT Global symbol "$joe" requires explicit package name at (eval 1) line 2. ######## # Check scope of pragma with eval use strict 'vars' ; eval ' no strict ; $joe = 1 ; '; print STDERR $@; $joe = 1 ; EXPECT Global symbol "$joe" requires explicit package name at - line 8. Execution of - aborted due to compilation errors. ######## # Check if multiple evals produce same errors use strict 'vars'; my $ret = eval q{ print $x; }; print $@; print "ok 1\n" unless defined $ret; $ret = eval q{ print $x; }; print $@; print "ok 2\n" unless defined $ret; EXPECT Global symbol "$x" requires explicit package name at (eval 1) line 1. ok 1 Global symbol "$x" requires explicit package name at (eval 2) line 1. ok 2 ######## # strict vars with outer our - no error use strict 'vars' ; our $freddy; local $abc::joe ; my $fred ; my $b = \$fred ; $Fred::ABC = 1 ; $freddy = 2 ; EXPECT ######## # strict vars with inner our - no error use strict 'vars' ; sub foo { our $fred; $fred; } EXPECT ######## # strict vars with outer our, inner use - no error use strict 'vars' ; our $fred; sub foo { $fred; } EXPECT ######## # strict vars with nested our - no error use strict 'vars' ; our $fred; sub foo { our $fred; $fred; } $fred ; EXPECT ######## # strict vars with elapsed our - error use strict 'vars' ; sub foo { our $fred; $fred; } $fred ; EXPECT Variable "$fred" is not imported at - line 8. Global symbol "$fred" requires explicit package name at - line 8. Execution of - aborted due to compilation errors. ######## # nested our with local - no error $fred = 1; use strict 'vars'; { local our $fred = 2; print $fred,"\n"; } print our $fred,"\n"; EXPECT 2 1