Psh/Strategy/Fallback_builtin.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 44 CC 2 SCAR 11.0
CC
2
Cov
0%
applies
6.0
new
2.0
consumes
2.0
CRAP 3.0
1 package Psh::Strategy::Fallback_builtin;
2  
3 =item * C<fallback_builtin>
4  
5 If the first word of the input line is a "fallback builtin" provided
6 for operating systems that do not have common binaries -- such as "ls",
7 "env", etc, then call the associated subroutine like an ordinary
8 builtin. If you want all of these commands to be executed within the
9 shell, you can move this strategy ahead of executable.
10  
11 =cut
12  
13 require Psh::Strategy;
14  
15 @Psh::Strategy::Fallback_builtin::ISA=('Psh::Strategy');
16  
17 my %fallback_builtin = ('ls'=>1, 'env'=>1 );
18  
19 sub new { Psh::Strategy::new(@_) }
20  
21 sub consumes {
22 return Psh::Strategy::CONSUME_TOKENS;
23 }
24  
25 sub runs_before {
26 return qw(executable);
27 }
28  
29 sub applies {
30 my $fnname = ${$_[2]}[0];
31 if( $fallback_builtin{$fnname}) {
32 eval 'use Psh::Builtins::Fallback::'.ucfirst($fnname);
33 return $fnname;
34 }
35 return '';
36 }
37  
38 sub execute {
39 my $self= shift;
40 my $line= ${shift()};
41 my @words= @{shift()};
42 my $command= shift;
43 shift @words;
44 my $rest= join(' ',@words);
45  
46 no strict 'refs';
47 $coderef= *{"Psh::Builtins::Fallback::".ucfirst($command)."::bi_$command"};
48 return (1,sub { &{$coderef}($rest,\@words); },[], 0, undef );
49 }
50  
51 1;