[Catalyst] Global 'helper' methods
Bill Moseley
moseley at hank.org
Tue Oct 30 14:58:14 GMT 2012
On Tue, Oct 30, 2012 at 7:03 AM, Craig Chant
<craig at homeloanpartnership.com>wrote:
> So it seems it=92s OK to whack them in the main MyApp.pm , here is an
> example of what is currently in a =91MemberGlobs.pm=92, which is =91requi=
red=92 in
> 90% of all the perl scripts.
>
Be careful with that approach. I'd stick with method that need to get
inserted into the request cycle -- not just a catch-all for something you
don't know where it really belongs.
>
>
> ##########
>
> # Yank Date #
>
> ##########
>
> sub YankDate {
>
>
>
> #_[0] =3D UK Date
>
>
>
> # split to parts
>
> my @dte =3D split(/\//, $_[0]);
>
Where does $_ come from? Now might be a good time to start using
PerlCritic because it's a pain later to try and clean up code.
>
>
> # rebuild to yank date
>
> my $yank =3D "$dte[2]-$dte[1]-$dte[0]";
>
Where's this date coming from? The database? Look at inflating all dates
and times to DateTime objects.
Then the rendering of that object becomes a View issue.
How do you see the timezone? That's also a rendering/View issue.
It's not pretty, but what I tend to do in the View (say, in a Template) is:
Event Time: [% set_user_time_zone( event.start_time ).strftime( loc(
'_time_with_zone' ) ) %]
set_user_time_zone clones the DateTime object and sets the timezone and
locale on the DateTime objet. The _time_with_zone is a string that gets
"translated" -- although mostly to %c, %x, and %X. But, by using
localization it can be anything.
>
> # return result
>
> $yank;
>
Yes, check out PerlCritic.
> }
>
>
>
> I=92m forever having to switch between UK dates and USA dates so have hel=
per
> methods.
>
See above.
>
>
> Where do these go?
>
>
>
> Also where do you put application global constants?
>
Not a clear line, but you have an app config for app-specific config. But,
I also have App::Constants that export constats which is useful for when
you need the constants outside of Catalyst.
-- =
Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20121030/fc916=
103/attachment.htm
More information about the Catalyst
mailing list