[cgiapp] params, params, params...
Joshua Miller
unrtst at gmail.com
Wed Feb 13 18:40:27 EST 2008
On Feb 13, 2008 6:29 PM, Mark Knoop <mark at rawcane.net> wrote:
> >
> > Having said that, I can understand you might want a variable whose value
> > happens to come from one of several sources. I think such logic would
> > fit in your super class, and be stored in CGI::App's param() cache,
> > rather than inventing another (4th) location for such a cache. That 4
> > alone tells you it's overkill.
> >
>
> Is it bad policy to add properties to the CGI::App itself?
>
> eg saying
>
> $self->{my_special_value} = 'SOME_VALUE';
Yes, that's bad. You can technically do it, but you should tread lightly,
and be aware of the possible consequences. CGI::App is currently based on a
blessed hash, but that might not always be the case (though it's likely to
stay that way). It could move to an inside-out object, or array based, etc.
Also, it uses that to store stuff itself. When you call param, it sets those
in $self->{__PARAMS} hash. If your my_special_value was "__PARAMS", you'd
overwrite the internal __PARAMS hash, and break CGI::App.
As an example, the CGI::App perldoc PLUG-INS section...
Writing Plug-ins
Writing plug-ins is simple. Simply create a new package, and export
the methods that you
want to become part of a CGI::Application project. See
CGI::Application::Plugin::Vali‐
dateRM for an example.
In order to avoid namespace conflicts within a CGI::Application
object, plugin developers
are recommended to use a unique prefix, such as the name of plugin
package, when storing
information. For instance:
$app->{__PARAM} = 'foo'; # BAD! Could conflict.
$app->{'MyPlugin::Module::__PARAM'} = 'foo'; # Good.
$app->{'MyPlugin::Module'}{__PARAM} = 'foo'; # Good.
So if you're going to do it, be careful.
>
>
> instead of
>
> $self->param(my_special_value, 'SOME_VALUE');
?
>
> I guess it is bad policy otherwise the params method would not exist but
> it
> would be useful to understand exactly why this is?
>
> Cheers
> Mark
>
>
> ##### CGI::Application community mailing list ################
> ## ##
> ## To unsubscribe, or change your message delivery options, ##
> ## visit: http://lists.openlib.org/mailman/listinfo/cgiapp ##
> ## ##
> ## Web archive: http://lists.openlib.org/pipermail/cgiapp/ ##
> ## Wiki: http://cgiapp.erlbaum.net/ ##
> ## ##
> ################################################################
>
>
More information about the cgiapp
mailing list