package Psh
::Strategy
::Eval
;
All input will be evaluated by the perl interpreter without
@Psh::Strategy
::Eval
::ISA
=('Psh::Strategy');
sub new
{ Psh
::Strategy
::new
(@_) }
return Psh
::Strategy
::CONSUME_TOKENS
;
return 'perl evaluation';
if( $_[4]) { # we are second or later in a pipe
$todo=~ s/\} ?([qg])\s*$/\}/;
if( $mods eq 'q' ) { # non-print mode
$code='while(<STDIN>) { @_= split /\s+/; '.$todo.' ; }';
} elsif( $mods eq 'g') { # grep mode
$code='while(<STDIN>) { @_= split /\s+/; print $_ if eval { '.$todo.' }; } ';
$code='while(<STDIN>) { @_= split /\s+/; '.$todo.' ; print $_ if $_; }';
return (1,sub {return 1,Psh
::PerlEval
::protected_eval
($code,'eval'); }, [], 0, undef);
local @Psh::tmp
= Psh
::PerlEval
::protected_eval
($todo,'eval');
return ((@Psh::tmp
&& $Psh::tmp
[0])?
1:0, @Psh::tmp
);