Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Overriding Subroutines in Packageby Tetramin (Sexton) |
on Oct 07, 2001 at 19:15 UTC ( [id://117311]=perlquestion: print w/replies, xml ) | Need Help?? |
Tetramin has asked for the wisdom of the Perl Monks concerning the following question: I am writing on a template module that allows embedding perl code which is then evaled within the modues namespace. As a side effect the templates can override a subroutines like in
Running as CGI there is no problem with it. But embedding perl in HTML makes more sense when running under mod_perl. With mod_perl the modified subroutine stays modified. If someone does *HSP::echo = sub{ die }; then the system doesn't work anymore because it allways dies when it wants to print something out. I know that I can make a subroutine private by saying my $sub = sub{ something private }; but since the templates are eval()ed in the same namespace it would also be possible to undef $sub. Am I lost now? Does someone know of a way how to protect a subroutine from being overridden? Something like this would be ideal maybe together with die "You are not allowed to override this subroutine".
Back to
Seekers of Perl Wisdom
|
|