Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / Psh / Strategy / Eval.pm
CommitLineData
86530b38
AT
1package Psh::Strategy::Eval;
2
3=item * C<eval>
4
5All input will be evaluated by the perl interpreter without
6any conditions.
7
8=cut
9
10require Psh::Strategy;
11
12@Psh::Strategy::Eval::ISA=('Psh::Strategy');
13
14sub new { Psh::Strategy::new(@_) }
15
16sub consumes {
17 return Psh::Strategy::CONSUME_TOKENS;
18}
19
20sub applies {
21 return 'perl evaluation';
22}
23
24sub 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
471;