Permalink
Browse files

No strict vars for one-liners

This disables strict vars for one-liners using the perl5i
executable, or when perl5i is loaded manually:
    perl -Mperl5i::latest -e '$fun="yay"; say $fun;'

Fixes #63
  • Loading branch information...
1 parent 78e59a8 commit 2227e6994f468fd6f7142ec4cc99cbd4ca79e6c7 @doherty committed Apr 23, 2011
Showing with 16 additions and 3 deletions.
  1. +11 −3 lib/perl5i/2.pm
  2. +5 −0 t/command_line_wrapper.t
View
@@ -48,12 +48,20 @@ sub import {
mro::set_mro( $caller, 'c3' );
load_in_caller( $caller => (
- ["CLASS"], ["File::chdir"],
- [English => qw(-no_match_vars)],
- ["Want" => qw(want)], ["Try::Tiny"], ["Perl6::Caller"], ["Carp"],
+ ['CLASS'],
+ ['File::chdir'],
+ ['English' => qw(-no_match_vars)],
+ ['Want' => qw(want)],
+ ['Try::Tiny'],
+ ['Perl6::Caller'],
+ ['Carp'],
['perl5i::2::Signatures'],
['Child' => qw(child)],
) );
+ # no strict vars for oneliners - GH #63
+ strict::unimport($class, 'vars')
+ if $class eq 'perl5i::cmd'
+ or $0 eq '-e';
# Have to call both or it won't work.
true::import($class);
View
@@ -59,4 +59,9 @@ is capture { system @perl5icmd, "-e", q[print __FILE__] }, "-e", '__FILE__
is `$perl5icmd $file`, "Hello\n", "program in a file";
}
+# Check it doesn't have strict vars on
+is capture {system @perl5icmd, '-e', q($fun="yay"; say $fun;)}, "yay\n", 'no strict vars for perl5i';
+is capture {system ($^X, '-Ilib', '-Mperl5i::latest', '-e', q|$fun="yay"; say $fun;|)},
+ "yay\n", q{no strict vars for perl -Mperl5i::latest -e '...'};
+
done_testing;

1 comment on commit 2227e69

Please avoid reformatting code as part of a larger commit. Makes it harder to review.

Please sign in to comment.