| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DateTime::Format::Natural::Utils; |
|
2
|
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
352
|
use strict; |
|
|
26
|
|
|
|
|
114
|
|
|
|
26
|
|
|
|
|
1146
|
|
|
4
|
26
|
|
|
26
|
|
158
|
use warnings; |
|
|
26
|
|
|
|
|
56
|
|
|
|
26
|
|
|
|
|
2153
|
|
|
5
|
26
|
|
|
26
|
|
206
|
use base qw(Exporter); |
|
|
26
|
|
|
|
|
62
|
|
|
|
26
|
|
|
|
|
3741
|
|
|
6
|
26
|
|
|
26
|
|
203
|
use boolean qw(true false); |
|
|
26
|
|
|
|
|
55
|
|
|
|
26
|
|
|
|
|
235
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our ($VERSION, @EXPORT_OK); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.08'; |
|
11
|
|
|
|
|
|
|
@EXPORT_OK = qw(trim); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _valid_date |
|
14
|
|
|
|
|
|
|
{ |
|
15
|
3422
|
|
|
3422
|
|
8579
|
my $self = shift; |
|
16
|
3422
|
|
|
|
|
33315
|
return $self->_valid(@_, |
|
17
|
|
|
|
|
|
|
{ units => [ qw(year month day) ], |
|
18
|
|
|
|
|
|
|
error => '(date is not valid)', |
|
19
|
|
|
|
|
|
|
type => 'date', |
|
20
|
|
|
|
|
|
|
}, |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _valid_time |
|
25
|
|
|
|
|
|
|
{ |
|
26
|
9217
|
|
|
9217
|
|
22193
|
my $self = shift; |
|
27
|
9217
|
|
|
|
|
83653
|
return $self->_valid(@_, |
|
28
|
|
|
|
|
|
|
{ units => [ qw(hour minute second) ], |
|
29
|
|
|
|
|
|
|
error => '(time is not valid)', |
|
30
|
|
|
|
|
|
|
type => 'time', |
|
31
|
|
|
|
|
|
|
}, |
|
32
|
|
|
|
|
|
|
); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _valid |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
12639
|
|
|
12639
|
|
27269
|
my $self = shift; |
|
38
|
12639
|
|
|
|
|
26346
|
my $opts = pop; |
|
39
|
12639
|
|
|
|
|
50627
|
my %values = @_; |
|
40
|
|
|
|
|
|
|
|
|
41
|
12639
|
|
|
|
|
33790
|
delete $values{nanosecond}; # always valid |
|
42
|
|
|
|
|
|
|
|
|
43
|
12639
|
|
|
|
|
26811
|
my %set = map { $_ => $self->{datetime}->$_ } @{$opts->{units}}; |
|
|
37917
|
|
|
|
|
291914
|
|
|
|
12639
|
|
|
|
|
37572
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
12639
|
|
|
|
|
141574
|
while (my ($unit, $value) = each %values) { |
|
46
|
25010
|
|
|
|
|
101248
|
$set{$unit} = $value; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
12639
|
|
|
|
|
37178
|
my $checker = '_check' . "_$opts->{type}"; |
|
50
|
|
|
|
|
|
|
|
|
51
|
12639
|
50
|
|
|
|
28662
|
if ($self->$checker(map $set{$_}, @{$opts->{units}})) { |
|
|
12639
|
|
|
|
|
110361
|
|
|
52
|
12639
|
|
|
|
|
49259
|
return true; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
else { |
|
55
|
0
|
|
|
|
|
0
|
$self->_set_failure; |
|
56
|
0
|
|
|
|
|
0
|
$self->_set_error($opts->{error}); |
|
57
|
0
|
|
|
|
|
0
|
return false; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _trace_string |
|
62
|
|
|
|
|
|
|
{ |
|
63
|
11931
|
|
|
11931
|
|
27431
|
my $self = shift; |
|
64
|
|
|
|
|
|
|
|
|
65
|
11931
|
|
|
|
|
80897
|
my ($trace, $modified, $keyword) = map $self->{$_}, qw(trace modified keyword); |
|
66
|
|
|
|
|
|
|
|
|
67
|
11931
|
|
50
|
|
|
46088
|
$trace ||= []; |
|
68
|
11931
|
|
100
|
|
|
43377
|
$modified ||= {}; |
|
69
|
11931
|
|
100
|
|
|
36624
|
$keyword ||= ''; |
|
70
|
|
|
|
|
|
|
|
|
71
|
11931
|
100
|
100
|
|
|
51877
|
return undef unless (@$trace || %$modified || length $keyword); |
|
|
|
|
66
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
11569
|
|
|
|
|
21392
|
my $i; |
|
74
|
11569
|
|
|
|
|
26169
|
my %order = map { $_ => $i++ } @{$self->{data}->__units('ordered')}; |
|
|
92552
|
|
|
|
|
253243
|
|
|
|
11569
|
|
|
|
|
99465
|
|
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return join "\n", grep length, $keyword, @$trace, |
|
77
|
34231
|
|
|
|
|
62056
|
map { my $unit = $_; "$unit: $modified->{$unit}" } |
|
|
34231
|
|
|
|
|
183700
|
|
|
78
|
11569
|
|
|
|
|
87140
|
sort { $order{$a} <=> $order{$b} } |
|
|
34492
|
|
|
|
|
93662
|
|
|
79
|
|
|
|
|
|
|
keys %$modified; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub trim |
|
83
|
|
|
|
|
|
|
{ |
|
84
|
13613
|
100
|
|
13613
|
0
|
57167
|
local $_ = ref $_[0] eq 'SCALAR' ? ${$_[0]} : $_[0]; |
|
|
13402
|
|
|
|
|
37381
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
13613
|
|
|
|
|
64241
|
s/^\s+//; |
|
87
|
13613
|
|
|
|
|
66001
|
s/\s+$//; |
|
88
|
|
|
|
|
|
|
|
|
89
|
13613
|
100
|
|
|
|
46088
|
return ref $_[0] eq 'SCALAR' ? do { ${$_[0]} = $_; '' } : $_; |
|
|
13402
|
|
|
|
|
26408
|
|
|
|
13402
|
|
|
|
|
40305
|
|
|
|
13402
|
|
|
|
|
52837
|
|
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
|
93
|
|
|
|
|
|
|
__END__ |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
DateTime::Format::Natural::Utils - Handy utility functions/methods |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Please see the DateTime::Format::Natural documentation. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The C<DateTime::Format::Natural::Utils> class consists of utility functions/methods. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L<DateTime::Format::Natural> |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 AUTHOR |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Steven Schubiger <schubiger@cpan.org> |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 LICENSE |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This program is free software; you may redistribute it and/or |
|
118
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
See L<http://dev.perl.org/licenses/> |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |