| 1 | package DateTime::Format::Natural::Rewrite; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 27 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 27 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 27 | our $VERSION = '0.10'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub _rewrite | ||||||||||||||||||||||||||||
| 9 | 12216 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_rewrite: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 10 | 12216 | my $self = shift; | |||||||||||||||||||||||||||
| 11 | 12216 | my ($date_string) = @_; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 12216 | foreach my $type (qw(regular aliases conditional)) { | |||||||||||||||||||||||||||
| 14 | 36648 | my $method = "_rewrite_$type"; | |||||||||||||||||||||||||||
| 15 | 36648 | $self->$method($date_string); | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub _rewrite_regular | ||||||||||||||||||||||||||||
| 20 | 12216 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_rewrite_regular: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 12216 | my $self = shift; | |||||||||||||||||||||||||||
| 22 | 12216 | my ($date_string) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 12216 | $$date_string =~ s/,(?!\d)//g; | |||||||||||||||||||||||||||
| 25 | 12216 | $$date_string =~ s/\s+?(a\.?m\.?|p\.?m\.?)\b/$1/gi; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | sub _rewrite_conditional | ||||||||||||||||||||||||||||
| 29 | 12216 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_rewrite_conditional: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 30 | 12216 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | 12216 | my ($date_string) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 12216 | my $rewrite = $self->{data}->{rewrite}; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | REWRITE: { | ||||||||||||||||||||||||||||
| 36 | 12216 | ▶ | if ($$date_string =~ /$rewrite->{at}{match}/g) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 2529 | my $last_token = $1; | |||||||||||||||||||||||||||
| 38 | my @regexes = ( | ||||||||||||||||||||||||||||
| 39 | (map $self->{data}->__RE($_), qw(time time_am time_pm)), | ||||||||||||||||||||||||||||
| 40 | $rewrite->{at}{daytime}, | ||||||||||||||||||||||||||||
| 41 | 2529 | ); | |||||||||||||||||||||||||||
| 42 | 2529 | foreach my $regex (@regexes) { | |||||||||||||||||||||||||||
| 43 | 5505 | ▶ | if ($last_token =~ $regex) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 2523 | ▶ | $$date_string =~ s/\G/:00/ if $last_token =~ /^\d{1,2}$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 2523 | $$date_string =~ s/$rewrite->{at}{subst}//; | |||||||||||||||||||||||||||
| 46 | 2523 | redo REWRITE; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub _rewrite_aliases | ||||||||||||||||||||||||||||
| 54 | 12216 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_rewrite_aliases: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 55 | 12216 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 12216 | my ($date_string) = @_; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 12216 | my $aliases = $self->{data}->{aliases}; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 12216 | ▶ | if ($$date_string =~ /\s+/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 10432 | foreach my $type (qw(words tokens)) { | |||||||||||||||||||||||||||
| 62 | 20864 | foreach my $alias (keys %{$aliases->{$type}}) { | |||||||||||||||||||||||||||
| 63 | 146048 | ▶ | if ($alias =~ /^\w+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 135616 | $$date_string =~ s/\b $alias \b/$aliases->{$type}{$alias}/gix; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||
| 67 | 10432 | $$date_string =~ s/(?:^|(?<=\s)) $alias (?:(?=\s)|$)/$aliases->{$type}{$alias}/gix; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 1784 | foreach my $alias (keys %{$aliases->{words}}) { | |||||||||||||||||||||||||||
| 74 | 5352 | $$date_string =~ s/^ $alias $/$aliases->{words}{$alias}/ix; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 1784 | foreach my $alias (keys %{$aliases->{short}}) { | |||||||||||||||||||||||||||
| 77 | 3568 | $$date_string =~ s/(?<=\d) $alias $/$aliases->{short}{$alias}/ix; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | sub _rewrite_duration | ||||||||||||||||||||||||||||
| 83 | 1258 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_rewrite_duration: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 84 | 1258 | my $self = shift; | |||||||||||||||||||||||||||
| 85 | 1258 | my ($date_strings) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1258 | my ($formatted) = $date_strings->[0] =~ $self->{data}->__regexes('format'); | |||||||||||||||||||||||||||
| 88 | 1258 | my %count = $self->_count_separators($formatted); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1258 | ▶ | return unless ($self->_check_formatted('ymd', \%count) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->_check_formatted("ymd", \%count) or $self->_check_formatted("md", \%count)
MC/DC100%2/2
$self->_check_formatted("ymd", \%count) or $self->_check_formatted("md", \%count)
$self->_check_formatted("ymd", \%count)
$self->_check_formatted("md", \%count)
Truth table100%3/3
A or B
A= $self->_check_formatted("ymd", \%count)B= $self->_check_formatted("md", \%count)
| |||||||||||||||||||||||||||||
| 91 | || $self->_check_formatted('md', \%count)); | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 137 | ▶ | if ($date_strings->[0] =~ /^ \Q$formatted\E \s+ \d{1,2} $/x) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 12 | $date_strings->[0] .= ':00'; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 137 | ▶ | if (@$date_strings == 2 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$date_strings == 2 and $date_strings->[1] =~ /^ \d{1,2} $/x
MC/DC100%2/2
@$date_strings == 2 and $date_strings->[1] =~ /^ \d{1,2} $/x
@$date_strings == 2
$date_strings->[1] =~ /^ \d{1,2} $/x
Truth table100%3/3
A and B
A= @$date_strings == 2B= $date_strings->[1] =~ /^ \d{1,2} $/x
| |||||||||||||||||||||||||||||
| 97 | && $date_strings->[1] =~ /^ \d{1,2} $/x) | ||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 12 | $date_strings->[1] .= ':00'; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 27 | 1; | |||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||