[sf-perl] Advice on how to expose a class-wide preference

Bern fluxnet at gmail.com
Tue Mar 18 14:37:07 PDT 2008


hi, sorry need to ask when is the next meeting ? or any other meetings and
or events in the sfbay area, thanks

On Tue, Mar 18, 2008 at 1:12 PM, Steve Fink <sphink at gmail.com> wrote:

> On Mon, Mar 17, 2008 at 11:28 PM, Anirvan Chatterjee
> <x.sfpug at chatterjee.net> wrote:
> >  1) Have a class-wide preference indicating the default style:
> >
> >         Class->default_string_style('normalized');
> >
> >  2) Let users set their preference via a magic variable:
> >
> >         local $Class::default_string_style = 'normalized';
> >
> >  The first option seems cleaner, and easier to subclass (were that an
> >  issue); it also allows for better error handling when the user calls
> >  the class method. Unfortunately, setting a class-wide flag also blows
> >  away any prior settings. Two pieces of code using the module will
> >  necessarily overwrite each other's preferences.
> >
> >  Using a variable seems uglier, but allows users to safely intermix
> >  different preference values in different contexts.
>
> Just to add to the set of possibilities, you could make the settings
> only apply to the package that requested them. So the syntax could
> either be your original #1:
>
>  Class->default_string_style('normalized')
>
> or you could make it explicit
>
>  Class->default_string_style(__PACKAGE__, 'normalized')
>
> default_string_style() would then use caller() or the passed-in
> package name to record who wants what, and the stringification would
> use caller() to decide whose setting to use.
>
> I'm not recommending it, just pointing it out.
>
> If you really wanted to be able to use local() but still have
> package-scoping, you could always do
>
>  our $STRINGIFICATION_SETTING;
>  local $STRINGIFICATION_SETTING = ...;
>
> and have stringification use caller() to look up that variable in its
> caller's package.
>
> Whee.
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20080318/48ce9eff/attachment.html 


More information about the SanFrancisco-pm mailing list