line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::Natural::Helpers; |
2
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
202
|
use strict; |
|
26
|
|
|
|
|
69
|
|
|
26
|
|
|
|
|
845
|
|
4
|
26
|
|
|
26
|
|
159
|
use warnings; |
|
26
|
|
|
|
|
74
|
|
|
26
|
|
|
|
|
816
|
|
5
|
26
|
|
|
26
|
|
170
|
use base qw(Exporter); |
|
26
|
|
|
|
|
79
|
|
|
26
|
|
|
|
|
2847
|
|
6
|
26
|
|
|
26
|
|
200
|
use boolean qw(true false); |
|
26
|
|
|
|
|
67
|
|
|
26
|
|
|
|
|
193
|
|
7
|
|
|
|
|
|
|
|
8
|
26
|
|
|
26
|
|
1976
|
use constant REAL_FLAG => true; |
|
26
|
|
|
|
|
72
|
|
|
26
|
|
|
|
|
195
|
|
9
|
26
|
|
|
26
|
|
1930
|
use constant VIRT_FLAG => false; |
|
26
|
|
|
|
|
91
|
|
|
26
|
|
|
|
|
184
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our ($VERSION, @EXPORT_OK, %flag); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.06'; |
14
|
|
|
|
|
|
|
@EXPORT_OK = qw(%flag); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my @flags = ( |
17
|
|
|
|
|
|
|
{ weekday_name => REAL_FLAG }, |
18
|
|
|
|
|
|
|
{ weekday_num => REAL_FLAG }, |
19
|
|
|
|
|
|
|
{ month_name => REAL_FLAG }, |
20
|
|
|
|
|
|
|
{ month_num => REAL_FLAG }, |
21
|
|
|
|
|
|
|
{ time_am => REAL_FLAG }, |
22
|
|
|
|
|
|
|
{ time_pm => REAL_FLAG }, |
23
|
|
|
|
|
|
|
{ last_this_next => VIRT_FLAG }, |
24
|
|
|
|
|
|
|
{ yes_today_tom => VIRT_FLAG }, |
25
|
|
|
|
|
|
|
{ noon_midnight => VIRT_FLAG }, |
26
|
|
|
|
|
|
|
{ morn_aftern_even => VIRT_FLAG }, |
27
|
|
|
|
|
|
|
{ before_after_from => VIRT_FLAG }, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
my $i; |
32
|
|
|
|
|
|
|
%flag = map { (keys %$_)[0] => $i++ } @flags; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _helper |
36
|
|
|
|
|
|
|
{ |
37
|
17937
|
|
|
17937
|
|
32448
|
my $self = shift; |
38
|
17937
|
|
|
|
|
39010
|
my ($flags, $string) = @_; |
39
|
|
|
|
|
|
|
|
40
|
17937
|
|
|
|
|
35776
|
foreach my $flag (@$flags) { |
41
|
24612
|
|
|
|
|
41235
|
my $name = (keys %{$flags[$flag]})[0]; |
|
24612
|
|
|
|
|
61550
|
|
42
|
24612
|
100
|
|
|
|
75253
|
if ($flags[$flag]->{$name}) { |
43
|
19681
|
|
|
|
|
152889
|
my $helper = "_$name"; |
44
|
19681
|
|
|
|
|
64450
|
$self->$helper(\$string); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
4931
|
|
|
|
|
49918
|
$string = $self->{data}->{conversion}->{$name}->{lc $string}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
17937
|
|
|
|
|
71547
|
return $string; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _weekday_name |
55
|
|
|
|
|
|
|
{ |
56
|
3645
|
|
|
3645
|
|
7120
|
my $self = shift; |
57
|
3645
|
|
|
|
|
7581
|
my ($arg) = @_; |
58
|
|
|
|
|
|
|
|
59
|
3645
|
|
|
|
|
8505
|
my $helper = $self->{data}->{helpers}; |
60
|
|
|
|
|
|
|
|
61
|
3645
|
100
|
|
|
|
23514
|
if ($$arg =~ $helper->{suffix}) { |
62
|
42
|
|
|
|
|
216
|
$$arg =~ s/$helper->{suffix}//; |
63
|
|
|
|
|
|
|
} |
64
|
3645
|
|
|
|
|
14459
|
$helper->{normalize}->($arg); |
65
|
3645
|
100
|
|
|
|
11012
|
if ($helper->{abbreviated}->($arg)) { |
66
|
660
|
|
|
|
|
2864
|
$$arg = $self->{data}->{weekdays_abbrev}->{$$arg}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _weekday_num |
71
|
|
|
|
|
|
|
{ |
72
|
3645
|
|
|
3645
|
|
6902
|
my $self = shift; |
73
|
3645
|
|
|
|
|
7249
|
my ($arg) = @_; |
74
|
|
|
|
|
|
|
|
75
|
3645
|
|
|
|
|
13376
|
$$arg = $self->_Decode_Day_of_Week($$arg); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _month_name |
79
|
|
|
|
|
|
|
{ |
80
|
3030
|
|
|
3030
|
|
6098
|
my $self = shift; |
81
|
3030
|
|
|
|
|
6701
|
my ($arg) = @_; |
82
|
|
|
|
|
|
|
|
83
|
3030
|
|
|
|
|
7431
|
my $helper = $self->{data}->{helpers}; |
84
|
|
|
|
|
|
|
|
85
|
3030
|
|
|
|
|
11451
|
$helper->{normalize}->($arg); |
86
|
3030
|
100
|
|
|
|
9279
|
if ($helper->{abbreviated}->($arg)) { |
87
|
2503
|
|
|
|
|
11342
|
$$arg = $self->{data}->{months_abbrev}->{$$arg}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _month_num |
92
|
|
|
|
|
|
|
{ |
93
|
3030
|
|
|
3030
|
|
5618
|
my $self = shift; |
94
|
3030
|
|
|
|
|
6631
|
my ($arg) = @_; |
95
|
|
|
|
|
|
|
|
96
|
3030
|
|
|
|
|
11618
|
$$arg = $self->_Decode_Month($$arg); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _time_am |
100
|
|
|
|
|
|
|
{ |
101
|
3599
|
|
|
3599
|
|
6945
|
my $self = shift; |
102
|
3599
|
|
|
|
|
7906
|
my ($arg) = @_; |
103
|
|
|
|
|
|
|
|
104
|
3599
|
|
|
|
|
10346
|
$self->_time_meridiem($arg, 'am'); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _time_pm |
108
|
|
|
|
|
|
|
{ |
109
|
2732
|
|
|
2732
|
|
5816
|
my $self = shift; |
110
|
2732
|
|
|
|
|
5617
|
my ($arg) = @_; |
111
|
|
|
|
|
|
|
|
112
|
2732
|
|
|
|
|
8026
|
$self->_time_meridiem($arg, 'pm'); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _time_meridiem |
116
|
|
|
|
|
|
|
{ |
117
|
6331
|
|
|
6331
|
|
11020
|
my $self = shift; |
118
|
6331
|
|
|
|
|
13307
|
my ($time, $period) = @_; |
119
|
|
|
|
|
|
|
|
120
|
6331
|
|
|
|
|
21228
|
my ($hour) = split /:/, $$time; |
121
|
|
|
|
|
|
|
|
122
|
6331
|
100
|
|
|
|
33578
|
my %hours = ( |
|
|
100
|
|
|
|
|
|
123
|
|
|
|
|
|
|
am => $hour - (($hour == 12) ? 12 : 0), |
124
|
|
|
|
|
|
|
pm => $hour + (($hour == 12) ? 0 : 12), |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
6331
|
|
|
|
|
63871
|
$$time =~ s/^ \d+? (?:(?=\:)|$)/$hours{$period}/x; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
__END__ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 NAME |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
DateTime::Format::Natural::Helpers - Various helper methods |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SYNOPSIS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Please see the DateTime::Format::Natural documentation. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 DESCRIPTION |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
The C<DateTime::Format::Natural::Helpers> class defines helper methods. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 SEE ALSO |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L<DateTime::Format::Natural> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHOR |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Steven Schubiger <schubiger@cpan.org> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 LICENSE |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This program is free software; you may redistribute it and/or |
156
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
See L<http://dev.perl.org/licenses/> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |