On Tue, Oct 30, 2012 at 7:03 AM, Craig Chant
<[email protected]>wrote:
> So it seems it’s OK to whack them in the main MyApp.pm , here is an
> example of what is currently in a ‘MemberGlobs.pm’, which is ‘required’ 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] = UK Date
>
>
>
> # split to parts
>
> my @dte = 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 = "$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’m forever having to switch between UK dates and USA dates so have helper
> 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
[email protected]
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/