go ahead... be a heretic | |
PerlMonks |
Is it legal to create subs in a module?by Anonymous Monk |
on Oct 11, 2001 at 19:18 UTC ( [id://118229]=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: Hello, Still working on my module. It works but I'm wondering if I've done something thats not programatically correct. In part of the module it creates subs that return the value the subs name was set to in the object hash. All that really does is make it where instead of getting the value as the following: $obj->{"blah"};You can get the value via: $obj->blahThe subs are created after a validity check via the folowing eval: eval "sub $action { my \$pkg = shift; return(\$pkg->{\"$action\"}); }";This all works fine, kinda. In my t/module.t the subs seem to be hanging around even after I undef($obj). This confuses me. I am creating a new object at the start: $obj = new Object(qw(blah good));Do some tests, then undef($obj). I attempt to create a new $obj in a manner that should fail but its not failing the way I'm expecting it to. $obj = new Object(qw(blah reserved));It should come back and tell me the option reserved is a reserved word. Instead it comes back with the following error/warning: Subroutine blah redefined at (eval 7) line 1I thought undef($obj) would clear things up but aparently its not. Why are the first defined subs sticking around? TIA
Back to
Seekers of Perl Wisdom
|
|