Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | package Psh::Builtins::Function; |
2 | ||
3 | require Psh::PerlEval; | |
4 | require Psh::Support::Functions; | |
5 | ||
6 | =item * C<function> | |
7 | ||
8 | Function tries to emulate the functionality of bash's function builtin | |
9 | ||
10 | =cut | |
11 | ||
12 | sub bi_function | |
13 | { | |
14 | $_[0]=~/^\s*(\S+)\s*\{(.*)\}\s*$/s; | |
15 | my $name=$1; | |
16 | my $def= $2; | |
17 | if ($name and $def) { | |
18 | Psh::Support::Functions::add_function($name,$def); | |
19 | Psh::PerlEval::protected_eval(qq[sub $name { Psh::Support::Functions::call_function($name); }], 'eval'); | |
20 | } | |
21 | return (1,undef); | |
22 | } | |
23 | ||
24 | 1; |