File Coverage

blib/lib/DateTime/Functions.pm
Criterion Covered Total %
statement 18 20 90.0
branch n/a
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 26 29 89.6


line stmt bran cond sub pod time code
1             package DateTime::Functions;
2             $DateTime::Functions::VERSION = '0.13';
3 1     1   76802 use 5.006;
  1         2  
4 1     1   3 use strict;
  1         1  
  1         14  
5 1     1   3 use warnings;
  1         4  
  1         20  
6 1     1   3 use parent 'Exporter';
  1         1  
  1         5  
7              
8 1     1   43 use DateTime ();
  1         1  
  1         47  
9              
10             our @EXPORT = qw(
11             datetime from_epoch now today from_object
12             last_day_of_month from_day_of_year default_locale
13             compare compare_ignore_floating duration
14             );
15              
16             =encoding utf8
17              
18             =head1 NAME
19              
20             DateTime::Functions - Procedural interface to DateTime functions
21              
22             =head1 SYNOPSIS
23              
24             use DateTime::Functions;
25             print today->year;
26             print now->strftime("%Y-%m-%d %H:%M:%S");
27              
28             =head1 DESCRIPTION
29              
30             This module simply exports all class methods of L into the
31             caller's namespace.
32              
33             =head1 METHODS
34              
35             Unless otherwise noted, all methods correspond to the same-named class
36             method in L. Please see L for which parameters are
37             supported.
38              
39             =head2 Constructors
40              
41             All constructors can die when invalid parameters are given. They all
42             return C objects, except for C which returns
43             a C object.
44              
45             =over 4
46              
47             =item * datetime( ... )
48              
49             Equivalent to C<< DateTime->new( ... ) >>.
50              
51             =item * duration( ... )
52              
53             Equivalent to C<< DateTime::Duration->new( ... ) >>.
54              
55             =item * from_epoch( epoch => $epoch, ... )
56              
57             =item * now( ... )
58              
59             =item * today( ... )
60              
61             =item * from_object( object => $object, ... )
62              
63             =item * last_day_of_month( ... )
64              
65             =item * from_day_of_year( ... )
66              
67             =back
68              
69             =head2 Utility Functions
70              
71             =over 4
72              
73             =item * default_locale( $locale )
74              
75             Equivalent to C<< DateTime->DefaultLocale( $locale ) >>.
76              
77             =item * compare
78              
79             =item * compare_ignore_floating
80              
81             =back
82              
83             =cut
84              
85             foreach my $func (@EXPORT) {
86 1     1   3 no strict 'refs';
  1         1  
  1         105  
87             my $method = $func;
88             next if $func eq 'duration';
89             $method = 'new' if $func eq 'datetime';
90             $method = 'DefaultLocale' if $func eq 'default_locale';
91 2     2   895 *$func = sub { DateTime->can($method)->('DateTime', @_) };
92             }
93              
94             sub duration {
95 0     0 1   require DateTime::Duration;
96 0           return DateTime::Duration->new(@_);
97             }
98              
99             1;
100              
101             =head1 SEE ALSO
102              
103             L
104              
105             =head1 AUTHOR
106              
107             唐鳳 Ecpan@audreyt.orgE
108              
109             =head1 COPYRIGHT AND LICENSE
110              
111             唐鳳 has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law.
112              
113             Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author.
114              
115             This work is published from Taiwan.
116              
117             L
118              
119             =cut
120