| 1 | package Psh::Support::Functions; | ||
| 2 | |||
| 3 | require Psh; | ||
| 4 | |||
| 5 | my %functions=(); | ||
| 6 | |||
| 7 | sub add_function { | ||
| 8 | my $name= shift; | ||
| 9 | my $text= shift; | ||
| 10 | $functions{$name}= [map { $_."\n" } split /\n/, $text]; | ||
| 11 | } | ||
| 12 | |||
| 13 | sub call_function { | ||
| 14 | my $name= shift; | ||
| 15 | Psh::process_variable($functions{$name}) if $functions{$name}; | ||
| 16 | } | ||
| 17 | |||
| 18 | sub remove_function { | ||
| 19 | my $name= shift; | ||
| 20 | delete $functions{$name}; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub get_function { | ||
| 24 | my $name= shift; | ||
| 25 | return $functions{$name}; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub list { | ||
| 29 | return sort keys %functions; | ||
| 30 | } | ||
| 31 | |||
| 32 | 1; |