| 1 | package Psh::Builtins::Symbols; |
| 2 | |
| 3 | require Psh::Util; |
| 4 | |
| 5 | =item * C<symbols [package]> |
| 6 | |
| 7 | Print out the symbols of each type used by a package. Note: in testing, |
| 8 | it bears out that the filehandles are present as scalars, and that arrays |
| 9 | are also present as scalars. The former is not particularly surprising, |
| 10 | since they are implemented as tied objects. But, use vars qw(@X) causes |
| 11 | both @X and $X to show up in this display. This remains mysterious. |
| 12 | |
| 13 | =cut |
| 14 | |
| 15 | sub bi_symbols |
| 16 | { |
| 17 | my $pack = shift; |
| 18 | my (@ref, @scalar, @array, @hash, @code, @glob, @handle); |
| 19 | my @sym; |
| 20 | |
| 21 | $pack ||= $Psh::PerlEval::current_package; |
| 22 | |
| 23 | { |
| 24 | no strict qw(refs); |
| 25 | @sym = keys %{*{"${pack}::"}}; |
| 26 | } |
| 27 | |
| 28 | for my $sym (sort @sym) { |
| 29 | next unless $sym =~ m/^[a-zA-Z]/; # Skip some special variables |
| 30 | next if $sym =~ m/::$/; # Skip all package hashes |
| 31 | |
| 32 | { |
| 33 | no strict qw(refs); |
| 34 | |
| 35 | push @ref, "\$$sym" if ref *{"${pack}::$sym"}{SCALAR} eq 'REF'; |
| 36 | push @scalar, "\$$sym" if ref *{"${pack}::$sym"}{SCALAR} eq 'SCALAR'; |
| 37 | push @array, "\@$sym" if ref *{"${pack}::$sym"}{ARRAY} eq 'ARRAY'; |
| 38 | push @hash, "\%$sym" if ref *{"${pack}::$sym"}{HASH} eq 'HASH'; |
| 39 | push @code, "\&$sym" if ref *{"${pack}::$sym"}{CODE} eq 'CODE'; |
| 40 | push @handle, "$sym" if ref *{"${pack}::$sym"}{FILEHANDLE}; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | Psh::Util::print_out("Package: ".$pack."\n"); |
| 45 | Psh::Util::print_out("Reference: ", join(' ', @ref), "\n"); |
| 46 | Psh::Util::print_out("Scalar: ", join(' ', @scalar), "\n"); |
| 47 | Psh::Util::print_out("Array: ", join(' ', @array), "\n"); |
| 48 | Psh::Util::print_out("Hash: ", join(' ', @hash), "\n"); |
| 49 | Psh::Util::print_out("Code: ", join(' ', @code), "\n"); |
| 50 | Psh::Util::print_out("Handle: ", join(' ', @handle), "\n"); |
| 51 | return (1,undef); |
| 52 | } |
| 53 | |
| 54 | 1; |