summaryrefslogtreecommitdiffstats
path: root/lib/Package/Stash.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-11-12 03:20:16 -0600
committerJesse Luehrs <doy@tozt.net>2010-11-12 03:20:16 -0600
commitd1f721b320d72e83c0cb24c45fe9995a6dcf29c2 (patch)
tree05ec14dbf1dfdf829b18ee44623d9b9e2098e0b1 /lib/Package/Stash.pm
parentf75437398a7a18f7852b0151f7cb808dbeb06d0a (diff)
downloadpackage-stash-d1f721b320d72e83c0cb24c45fe9995a6dcf29c2.tar.gz
package-stash-d1f721b320d72e83c0cb24c45fe9995a6dcf29c2.zip
fix list_all_package_symbols
Diffstat (limited to 'lib/Package/Stash.pm')
-rw-r--r--lib/Package/Stash.pm20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm
index 132f687..4f1db68 100644
--- a/lib/Package/Stash.pm
+++ b/lib/Package/Stash.pm
@@ -381,7 +381,9 @@ sub remove_package_symbol {
Returns a list of package variable names in the package, without sigils. If a
C<type_filter> is passed, it is used to select package variables of a given
type, where valid types are the slots of a typeglob ('SCALAR', 'CODE', 'HASH',
-etc).
+etc). Note that if the package contained any C<BEGIN> blocks, perl will leave
+an empty typeglob in the C<BEGIN> slot, so this will show up if no filter is
+used (and similarly for C<INIT>, C<END>, etc).
=cut
@@ -399,10 +401,20 @@ sub list_all_package_symbols {
# any non-typeglob in the symbol table is a constant or stub
ref(\$namespace->{$_}) ne 'GLOB'
# regular subs are stored in the CODE slot of the typeglob
- || defined(*{$namespace->{$_}}{CODE});
+ || defined(*{$namespace->{$_}}{CODE})
+ } keys %{$namespace};
+ }
+ elsif ($type_filter eq 'SCALAR') {
+ return grep {
+ ref(\$namespace->{$_}) eq 'GLOB'
+ && defined(${*{$namespace->{$_}}{'SCALAR'}})
+ } keys %{$namespace};
+ }
+ else {
+ return grep {
+ ref(\$namespace->{$_}) eq 'GLOB'
+ && defined(*{$namespace->{$_}}{$type_filter})
} keys %{$namespace};
- } else {
- return grep { *{$namespace->{$_}}{$type_filter} } keys %{$namespace};
}
}