From e88665a5772fd94a541366c984ecbade0b39fc95 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 29 Nov 2011 14:07:30 -0600 Subject: better diagnostics for get_symbol issues on bare anon stashes --- lib/Package/Stash/PP.pm | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lib/Package/Stash/PP.pm') diff --git a/lib/Package/Stash/PP.pm b/lib/Package/Stash/PP.pm index 4996c39..8d95840 100644 --- a/lib/Package/Stash/PP.pm +++ b/lib/Package/Stash/PP.pm @@ -88,6 +88,10 @@ sub namespace { } } +sub _is_anon { + return !defined $_[0]->{package}; +} + { my %SIGIL_MAP = ( '$' => 'SCALAR', @@ -270,19 +274,25 @@ sub get_symbol { } else { if ($type eq 'CODE') { + if (BROKEN_GLOB_ASSIGNMENT || !$self->_is_anon) { + no strict 'refs'; + return \&{ $self->name . '::' . $name }; + } + # XXX we should really be able to support arbitrary anonymous # stashes here... (not just via Package::Anon) - if (!BROKEN_GLOB_ASSIGNMENT - && blessed($namespace) - && $namespace->isa('Package::Anon')) { - # ->can will call gv_init for us + if (blessed($namespace) && $namespace->isa('Package::Anon')) { + # ->can will call gv_init for us, which inflates the glob + # don't know how to do this in general $namespace->bless(\(my $foo))->can($name); - return *{ $namespace->{$name} }{CODE}; } else { - no strict 'refs'; - return \&{ $self->name . '::' . $name }; + confess "Don't know how to inflate a " . ref($entry_ref) + . " into a full coderef (perhaps you could use" + . " Package::Anon instead of a bare stash?)" } + + return *{ $namespace->{$name} }{CODE}; } else { return undef; -- cgit v1.2.3-54-g00ecf