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 / Fallback_builtin.pm
CommitLineData
86530b38
AT
1package Psh::Strategy::Fallback_builtin;
2
3=item * C<fallback_builtin>
4
5If the first word of the input line is a "fallback builtin" provided
6for operating systems that do not have common binaries -- such as "ls",
7"env", etc, then call the associated subroutine like an ordinary
8builtin. If you want all of these commands to be executed within the
9shell, you can move this strategy ahead of executable.
10
11=cut
12
13require Psh::Strategy;
14
15@Psh::Strategy::Fallback_builtin::ISA=('Psh::Strategy');
16
17my %fallback_builtin = ('ls'=>1, 'env'=>1 );
18
19sub new { Psh::Strategy::new(@_) }
20
21sub consumes {
22 return Psh::Strategy::CONSUME_TOKENS;
23}
24
25sub runs_before {
26 return qw(executable);
27}
28
29sub 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
38sub 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
511;