saberworks has asked for the wisdom of the Perl Monks concerning the following question:
The problem I'm having is that in a persistent environment (under plackup, where my modules aren't reloaded on each web request) in this list of code references one of them somehow goes undef during execution so that upon the next request Dancer dies with a runtime error (because $_ is undef and it's trying to call $_->(@args)).$_->(@args) foreach @{$self->get_hooks_for($hook_name)};
after:$VAR1 = [ sub { "DUMMY" }, sub { "DUMMY" } ];
If I change the original line in the Dancer module to this the error goes away:$VAR1 = [ sub { "DUMMY" }, undef ];
This is really odd to me because I can't think of a way executing a coderef will turn it into undef. It seems like some issue with $_ getting overwritten somehow but I don't know how that could happen. I tried to repro this on a blank project by setting $_ to all sorts of values but wasn't able to.foreach my $hook (@{ $self->get_hooks_for($hook_name) }) { $hook->(@args); }
The "get_hooks_for" method does this: $self->hooks->{$hook_name} || []; And the "hooks" method is magically created like this: __PACKAGE__->attributes(qw/ hooks registered_hooks/); Thanks for any help.my @hooks = @{ $self->get_hooks_for($hook_name) }; $_->(@args) foreach @hooks;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there something that can turn a coderef undef from inside the coderef?
by BrowserUk (Patriarch) on Jun 10, 2011 at 23:51 UTC | |
|
Re: Is there something that can turn a coderef undef from inside the coderef?
by AnomalousMonk (Archbishop) on Jun 11, 2011 at 00:10 UTC | |
|
Re: Is there something that can turn a coderef undef from inside the coderef?
by saberworks (Curate) on Jun 12, 2011 at 00:05 UTC | |
by FunkyMonk (Bishop) on Jun 12, 2011 at 00:33 UTC | |
by planetscape (Chancellor) on Jun 12, 2011 at 20:37 UTC | |
|
Re: Is there something that can turn a coderef undef from inside the coderef?
by Anonymous Monk on Jun 13, 2011 at 12:42 UTC |