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
*HSP::echo = sub { do something other than it normally would };
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".sub echo : protected { do something }
In reply to Overriding Subroutines in Package by Tetramin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |