in reply to Re^4: OUR declaration
in thread OUR declaration
I'll bring this up on the mod_perl dev list. I don't think we should advise people to use such a crazy construct.
The problems people encounter with ModPerl::Registry are usually not caused by inner subroutines, but rather by closures. The closures were always there, but were never noticed before in a non-persistent environment. Consider this:
my $q = CGI->new; show_name(); sub show_name { print $q->param('name'); }
This code will break when run in mod_perl because it forms a closure around $q, making it a private variable for the show_name() sub after compilation.
This problem can be fixed by making $q an our variable, but that's a poor programming practice, giving $q a large scope and persistence that it should not have. The correct fix is to pass the variables that the sub requires:
my $q = CGI->new; show_name($q); sub show_name { my $q = shift; print $q->param('name'); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: OUR declaration
by ikegami (Patriarch) on Sep 25, 2006 at 15:51 UTC | |
by perrin (Chancellor) on Sep 25, 2006 at 16:09 UTC | |
by ikegami (Patriarch) on Sep 25, 2006 at 16:29 UTC | |
by perrin (Chancellor) on Sep 25, 2006 at 16:43 UTC | |
by ikegami (Patriarch) on Sep 25, 2006 at 16:56 UTC | |
|