| 1 | package Catalyst::Plugin::DateTime; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 1 | ▶ | use Catalyst::Exception; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use DateTime; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | our $VERSION = "0.03"; | |||||||||||
| 10 | |||||||||||||
| 11 | =pod | ||||||||||||
| 12 | =head1 NAME | ||||||||||||
| 13 | |||||||||||||
| 14 | Catalyst::Plugin::DateTime - DateTime plugin for Catalyst. | ||||||||||||
| 15 | |||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||
| 17 | |||||||||||||
| 18 | # In your application class | ||||||||||||
| 19 | use Catalyst qw/DateTime/; | ||||||||||||
| 20 | |||||||||||||
| 21 | |||||||||||||
| 22 | # Use DateTime objects within your Catalyst app: | ||||||||||||
| 23 | my $dt = $c->datetime(); # will return a DateTime object with local date and time | ||||||||||||
| 24 | my $dt = $c->datetime(year => '2005', month => '01'); | ||||||||||||
| 25 | |||||||||||||
| 26 | $c->datetime->mdy(); # returns current date in mdy format (i.e. 01/01/2006) | ||||||||||||
| 27 | |||||||||||||
| 28 | $c->dt(time_zone => 'Asia/Taipei'); # returns current date & time for argued time zone | ||||||||||||
| 29 | |||||||||||||
| 30 | =head1 METHODS | ||||||||||||
| 31 | |||||||||||||
| 32 | =over 4 | ||||||||||||
| 33 | |||||||||||||
| 34 | =item datetime | ||||||||||||
| 35 | |||||||||||||
| 36 | Returns a L<DateTime> object. If params are argued they will be passed to the | ||||||||||||
| 37 | C<< DateTime->new() >> method. Exceptions thrown by L<DateTime> will be caught by | ||||||||||||
| 38 | L<Catalyst::Exception>. | ||||||||||||
| 39 | |||||||||||||
| 40 | If the argument list is empty, a L<DateTime> object with the local date and time | ||||||||||||
| 41 | obtained via C<< DateTime->now() >> will be returned. | ||||||||||||
| 42 | |||||||||||||
| 43 | Uses C<< time_zone => local >> as a default. | ||||||||||||
| 44 | |||||||||||||
| 45 | =item dt | ||||||||||||
| 46 | |||||||||||||
| 47 | Alias to datetime. | ||||||||||||
| 48 | |||||||||||||
| 49 | =back | ||||||||||||
| 50 | |||||||||||||
| 51 | =cut | ||||||||||||
| 52 | |||||||||||||
| 53 | 1 | ▶ | sub datetime { | ||||||||||
|
Subroutine
datetime: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||
| 54 | 1 | my $c = shift; | |||||||||||
| 55 | 1 | my %params = @_; | |||||||||||
| 56 | 1 | ▶ | my $tz = delete $params{time_zone} || 'local'; | ||||||||||
|
Condition50%1/2
delete $params{'time_zone'} || 'local'
MC/DC0%0/1
delete $params{'time_zone'} || 'local'
delete $params{'time_zone'}
Truth table50%1/2
A
A= delete $params{'time_zone'}
| |||||||||||||
| 57 | |||||||||||||
| 58 | # use params if argued | ||||||||||||
| 59 | 1 | ▶ | if (%params) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 1 | return DateTime->new(\%params)->set_time_zone($tz); | |||||||||||
| 61 | } | ||||||||||||
| 62 | else { # otherwise use now | ||||||||||||
| 63 | 0 | return DateTime->now(time_zone => $tz); | |||||||||||
| 64 | } | ||||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | # alias $c->dt | ||||||||||||
| 68 | 1 | *dt = \&datetime; | |||||||||||
| 69 | |||||||||||||
| 70 | |||||||||||||
| 71 | 1 | 1; | |||||||||||
| 72 | |||||||||||||
| 73 | =pod | ||||||||||||
| 74 | |||||||||||||
| 75 | =head1 DESCRIPTION | ||||||||||||
| 76 | |||||||||||||
| 77 | This module's intention is to make the wonders of L<DateTime> easily accesible within | ||||||||||||
| 78 | a L<Catalyst> application via the L<Catalyst::Plugin> interface. | ||||||||||||
| 79 | |||||||||||||
| 80 | It adds the methods C<datetime> and C<dt> to the C<Catalyst> namespace. | ||||||||||||
| 81 | |||||||||||||
| 82 | =head1 AUTHOR | ||||||||||||
| 83 | |||||||||||||
| 84 | James Kiser L<james.kiser@gmail.com> | ||||||||||||
| 85 | |||||||||||||
| 86 | =head1 SEE ALSO | ||||||||||||
| 87 | |||||||||||||
| 88 | L<Catalyst>, L<DateTime> | ||||||||||||
| 89 | |||||||||||||
| 90 | =head1 COPYRIGHT & LICENSE | ||||||||||||
| 91 | |||||||||||||
| 92 | Copyright (c) 2006 the aforementioned author(s). All rights | ||||||||||||
| 93 | reserved. This program is free software; you can redistribute | ||||||||||||
| 94 | it and/or modify it under the same terms as Perl itself. | ||||||||||||
| 95 | |||||||||||||
| 96 | =cut | ||||||||||||
| 97 | |||||||||||||
| 98 | |||||||||||||