line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DateTime::Format::Natural::Utils; |
2
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
231
|
use strict; |
|
26
|
|
|
|
|
69
|
|
|
26
|
|
|
|
|
829
|
|
4
|
26
|
|
|
26
|
|
176
|
use warnings; |
|
26
|
|
|
|
|
71
|
|
|
26
|
|
|
|
|
974
|
|
5
|
26
|
|
|
26
|
|
200
|
use base qw(Exporter); |
|
26
|
|
|
|
|
65
|
|
|
26
|
|
|
|
|
4087
|
|
6
|
26
|
|
|
26
|
|
230
|
use boolean qw(true false); |
|
26
|
|
|
|
|
76
|
|
|
26
|
|
|
|
|
330
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our ($VERSION, @EXPORT_OK); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.08'; |
11
|
|
|
|
|
|
|
@EXPORT_OK = qw(trim); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _valid_date |
14
|
|
|
|
|
|
|
{ |
15
|
3383
|
|
|
3383
|
|
6196
|
my $self = shift; |
16
|
3383
|
|
|
|
|
18462
|
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
|
9043
|
|
|
9043
|
|
16951
|
my $self = shift; |
27
|
9043
|
|
|
|
|
46594
|
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
|
12426
|
|
|
12426
|
|
22440
|
my $self = shift; |
38
|
12426
|
|
|
|
|
19396
|
my $opts = pop; |
39
|
12426
|
|
|
|
|
34527
|
my %values = @_; |
40
|
|
|
|
|
|
|
|
41
|
12426
|
|
|
|
|
23911
|
delete $values{nanosecond}; # always valid |
42
|
|
|
|
|
|
|
|
43
|
12426
|
|
|
|
|
19566
|
my %set = map { $_ => $self->{datetime}->$_ } @{$opts->{units}}; |
|
37278
|
|
|
|
|
206929
|
|
|
12426
|
|
|
|
|
27293
|
|
44
|
|
|
|
|
|
|
|
45
|
12426
|
|
|
|
|
109231
|
while (my ($unit, $value) = each %values) { |
46
|
24458
|
|
|
|
|
81291
|
$set{$unit} = $value; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
12426
|
|
|
|
|
34046
|
my $checker = '_check' . "_$opts->{type}"; |
50
|
|
|
|
|
|
|
|
51
|
12426
|
50
|
|
|
|
20451
|
if ($self->$checker(map $set{$_}, @{$opts->{units}})) { |
|
12426
|
|
|
|
|
70364
|
|
52
|
12426
|
|
|
|
|
35571
|
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
|
11699
|
|
|
11699
|
|
22508
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
11699
|
|
|
|
|
57887
|
my ($trace, $modified, $keyword) = map $self->{$_}, qw(trace modified keyword); |
66
|
|
|
|
|
|
|
|
67
|
11699
|
|
50
|
|
|
41217
|
$trace ||= []; |
68
|
11699
|
|
100
|
|
|
26609
|
$modified ||= {}; |
69
|
11699
|
|
100
|
|
|
27110
|
$keyword ||= ''; |
70
|
|
|
|
|
|
|
|
71
|
11699
|
100
|
100
|
|
|
33532
|
return undef unless (@$trace || %$modified || length $keyword); |
|
|
|
66
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
11339
|
|
|
|
|
18239
|
my $i; |
74
|
11339
|
|
|
|
|
17488
|
my %order = map { $_ => $i++ } @{$self->{data}->__units('ordered')}; |
|
90712
|
|
|
|
|
184635
|
|
|
11339
|
|
|
|
|
67565
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return join "\n", grep length, $keyword, @$trace, |
77
|
33492
|
|
|
|
|
52151
|
map { my $unit = $_; "$unit: $modified->{$unit}" } |
|
33492
|
|
|
|
|
134688
|
|
78
|
11339
|
|
|
|
|
59393
|
sort { $order{$a} <=> $order{$b} } |
|
35061
|
|
|
|
|
69949
|
|
79
|
|
|
|
|
|
|
keys %$modified; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub trim |
83
|
|
|
|
|
|
|
{ |
84
|
13381
|
100
|
|
13381
|
0
|
40619
|
local $_ = ref $_[0] eq 'SCALAR' ? ${$_[0]} : $_[0]; |
|
13170
|
|
|
|
|
28785
|
|
85
|
|
|
|
|
|
|
|
86
|
13381
|
|
|
|
|
44602
|
s/^\s+//; |
87
|
13381
|
|
|
|
|
40782
|
s/\s+$//; |
88
|
|
|
|
|
|
|
|
89
|
13381
|
100
|
|
|
|
34256
|
return ref $_[0] eq 'SCALAR' ? do { ${$_[0]} = $_; '' } : $_; |
|
13170
|
|
|
|
|
22382
|
|
|
13170
|
|
|
|
|
29479
|
|
|
13170
|
|
|
|
|
36525
|
|
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 |