Psh/Strategy/Eval.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 48 CC 5 SCAR 28.7
CC
5
Cov
0%
execute
30.0
new
2.0
consumes
2.0
CRAP 17.6
1 package Psh::Strategy::Eval;
2  
3 =item * C<eval>
4  
5 All input will be evaluated by the perl interpreter without
6 any conditions.
7  
8 =cut
9  
10 require Psh::Strategy;
11  
12 @Psh::Strategy::Eval::ISA=('Psh::Strategy');
13  
14 sub new { Psh::Strategy::new(@_) }
15  
16 sub consumes {
17 return Psh::Strategy::CONSUME_TOKENS;
18 }
19  
20 sub applies {
21 return 'perl evaluation';
22 }
23  
24 sub execute {
25 my $todo= ${$_[1]};
26  
27 if( $_[4]) { # we are second or later in a pipe
28 my $code;
29 $todo=~ s/\} ?([qg])\s*$/\}/;
30 my $mods= $1 || '';
31 if( $mods eq 'q' ) { # non-print mode
32 $code='while(<STDIN>) { @_= split /\s+/; '.$todo.' ; }';
33 } elsif( $mods eq 'g') { # grep mode
34 $code='while(<STDIN>) { @_= split /\s+/; print $_ if eval { '.$todo.' }; } ';
35 } else {
36 $code='while(<STDIN>) { @_= split /\s+/; '.$todo.' ; print $_ if $_; }';
37 }
38 return (1,sub {return 1,Psh::PerlEval::protected_eval($code,'eval'); }, [], 0, undef);
39 } else {
40 return (1,sub {
41 local @Psh::tmp= Psh::PerlEval::protected_eval($todo,'eval');
42 return ((@Psh::tmp && $Psh::tmp[0])?1:0, @Psh::tmp);
43 }, [], 0, undef);
44 }
45 }
46  
47 1;