Skip to content

Commit

Permalink
No strict vars for one-liners
Browse files Browse the repository at this point in the history
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
doherty committed Apr 23, 2011
1 parent 78e59a8 commit 2227e69
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/perl5i/2.pm
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions t/command_line_wrapper.t
Expand Up @@ -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;

0 comments on commit 2227e69

Please sign in to comment.