/dev/urandom has asked for the wisdom of the Perl Monks concerning the following question:
Unfortunately, the module is still loaded after I finish my work, and I don't know how to stop this. Or is there a way to have my subroutine get called whenever a module is loaded?my ($coderef, $filename) = @_; my $result; @INC = grep {$_ ne $self->{__connector}} @INC; require $filename; # try to overwrite a method here unshift @INC, $self->{__connector};
I'm not even sure whether the first 2 lines are able to actually copy the subroutine, instead of just aliasing it, which is another problem in itself. But what I noticed what, that the inner sub did not overwrite the one in the IWL::Script module*setScript = *IWL::Script::setScript; delete $::{'IWL::'}{'Script::'}{'setScript'}; no warnings qw(redefine); sub IWL::Script::setScript { my ($self, $param) = @_; if (ref $param eq 'CODE') { *setScript{CODE}->($self, $p2js->covert($param)); } else { *setScript{CODE}->($self, $param); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Notification on module load, and redefinition of module methods.
by lodin (Hermit) on Feb 01, 2008 at 17:10 UTC | |
by /dev/urandom (Beadle) on Feb 01, 2008 at 20:17 UTC | |
by lodin (Hermit) on Feb 04, 2008 at 18:05 UTC |