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
*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 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Overriding Subroutines in Package
by merlyn (Sage) on Oct 07, 2001 at 19:21 UTC | |
by Tetramin (Sexton) on Oct 07, 2001 at 19:40 UTC | |
by merlyn (Sage) on Oct 07, 2001 at 19:52 UTC | |
by Tetramin (Sexton) on Oct 07, 2001 at 23:22 UTC |