| 1 | package Psh::Builtins::Export; |
| 2 | |
| 3 | require Psh::Support::Env; |
| 4 | require Psh::Options; |
| 5 | require Psh::Util; |
| 6 | |
| 7 | =item * C<export VAR [=VALUE]> |
| 8 | |
| 9 | Just like setenv, below, except that it also ties the variable (in the |
| 10 | Perl sense) so that subsequent changes to the variable automatically |
| 11 | affect the environment. Variables who are lists and appear in option |
| 12 | 'array_exports' will also by tied to the array of the same name. |
| 13 | Note that the variable must be specified without any Perl specifier |
| 14 | like C<$> or C<@>. |
| 15 | |
| 16 | =cut |
| 17 | |
| 18 | sub bi_export |
| 19 | { |
| 20 | my $var = Psh::Support::Env::do_setenv(@_); |
| 21 | if ($var) { |
| 22 | my @result = Psh::PerlEval::protected_eval("tied(\$$var)"); |
| 23 | my $oldtie = $result[0]; |
| 24 | if (defined($oldtie)) { |
| 25 | if (ref($oldtie) ne 'Env') { |
| 26 | Psh::Util::print_warning_i18n('bi_export_tied',$var,$oldtie); |
| 27 | } |
| 28 | } else { |
| 29 | Psh::PerlEval::protected_eval("use Env '$var';"); |
| 30 | my $ae= Psh::Options::get_option('array_exports'); |
| 31 | if( $ae and $ae->{$var}) { |
| 32 | eval { |
| 33 | require Env::Array; |
| 34 | }; |
| 35 | if( ! $@) { |
| 36 | Psh::PerlEval::protected_eval("use Env::Array qw($var $ae->{var});",'hide'); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } else { |
| 41 | Psh::Util::print_error_i18n('usage_export'); |
| 42 | return (0,undef); |
| 43 | } |
| 44 | return (1,undef); |
| 45 | } |
| 46 | |
| 47 | 1; |
| 48 | |