From: Yuval Kogman Date: Sun, 10 Aug 2008 21:01:07 +0000 (+0000) Subject: simplfy get_all_package_symbols X-Git-Tag: 0_64_01~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b16217dda005ba1dc4a1f96366e992d867d702d4;p=gitmo%2FClass-MOP.git simplfy get_all_package_symbols --- diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index 2e8f6c2..1874dea 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -235,22 +235,35 @@ sub list_all_package_symbols { sub get_all_package_symbols { my ($self, $type_filter) = @_; my $namespace = $self->namespace; - return %{$namespace} unless defined $type_filter; - - # NOTE: - # or we can filter based on - # type (SCALAR|ARRAY|HASH|CODE) - no strict 'refs'; - return map { - $_ => (ref($namespace->{$_}) eq 'SCALAR' - ? ($type_filter eq 'CODE' ? \&{$self->name . '::' . $_} : undef) - : *{$namespace->{$_}}{$type_filter}) - } grep { - (ref($namespace->{$_}) - ? (ref($namespace->{$_}) eq 'SCALAR' && $type_filter eq 'CODE') - : (ref(\$namespace->{$_}) eq 'GLOB' - && defined(*{$namespace->{$_}}{$type_filter}))); - } keys %{$namespace}; + return %$namespace unless defined $type_filter; + + my @ret; + + if ( $type_filter eq 'CODE' ) { + my $pkg = $self->name; + foreach my $key ( keys %$namespace ) { + my $value = $namespace->{$key}; + if ( ref $value ) { + no strict 'refs'; + push @ret, $key => \&{"${pkg}::$key"}; + } elsif ( ref(\$value) eq 'GLOB' ) { + if ( my $ref = *{$value}{CODE} ) { + push @ret, $key, $ref; + } + } + } + } else { + foreach my $key ( keys %$namespace ) { + my $value = $namespace->{$key}; + if ( ref(\$value) eq 'GLOB' ) { + if ( my $ref = *{$value}{$type_filter} ) { + push @ret, $key => $ref; + } + } + } + } + + return @ret; } 1;