Natural/Compat.pm

filter: Statementstmt 98.7% 76 / 77 Branchbran 95.0% 19 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 98.1% 108 / 110 CC 11 SCAR 6.7
CC
11
Cov
98%
_Nth_Weekday_of_Month_Year
3.0
BEGIN
2.1
_Add_Delta_Days
2.0
CRAP 2.0
« Natural/Lang/Base.pm ↑ Summary Natural/Helpers.pm »
1 package DateTime::Format::Natural::Compat;
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 27 ▶use boolean qw(true false);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 27 ▶use DateTime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 27 our ($VERSION, $Pure);
10  
11 27 $VERSION = '0.08';
12  
13 BEGIN
14 27 ▶{
Subroutine BEGIN: called CC=2 SCAR=7.2
15 27 ▶ if (eval {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Date::Calc; 'Date::Calc'->import('Add_Delta_Days', 'Day_of_Week', 'Days_in_Month', 'Decode_Day_of_Week', 'Decode_Month', 'Nth_Weekday_of_Month_Year', 'check_date', 'check_time'); 1 } }) { } 27 0 27
16 27 require Date::Calc;
17 27 Date::Calc->import(qw(
18 Add_Delta_Days
19 Day_of_Week
20 Days_in_Month
21 Decode_Day_of_Week
22 Decode_Month
23 Nth_Weekday_of_Month_Year
24 check_date
25 check_time
26 ));
27 27 1;
28 }) {
29 27 $Pure = false;
30 }
31 else {
32 0 $Pure = true;
33 }
34 }
35  
36 sub _Add_Delta_Days
37 132 ▶{
Subroutine _Add_Delta_Days: called CC=2 SCAR=6.9
38 132 my $self = shift;
39  
40 132 ▶ if ($Pure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pure) { } 60 72 132
41 60 my ($year, $day) = @_;
42 60 my $dt = DateTime->from_day_of_year(year => $year, day_of_year => $day);
43 60 return ($dt->year, $dt->month, $dt->mday);
44 }
45 else {
46 72 my ($year, $day) = @_;
47 72 return Add_Delta_Days($year, 1, 1, $day - 1);
48 }
49 }
50  
51 sub _Day_of_Week
52 1530 ▶{
Subroutine _Day_of_Week: called CC=2 SCAR=6.9
53 1530 my $self = shift;
54  
55 1530 ▶ if ($Pure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pure) { } 765 765 1530
56 765 return $self->{datetime}->wday;
57 }
58 else {
59 765 return Day_of_Week(@_);
60 }
61 }
62  
63 sub _Days_in_Month
64 123 ▶{
Subroutine _Days_in_Month: called CC=2 SCAR=6.9
65 123 my $self = shift;
66  
67 123 ▶ if ($Pure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pure) { } 54 69 123
68 54 my ($year, $month) = @_;
69 54 my $dt = DateTime->last_day_of_month(year => $year, month => $month);
70 54 return $dt->day;
71 }
72 else {
73 69 return Days_in_Month(@_);
74 }
75 }
76  
77 sub _Decode_Day_of_Week
78 3645 ▶{
Subroutine _Decode_Day_of_Week: called CC=2 SCAR=6.9
79 3645 my $self = shift;
80  
81 3645 ▶ if ($Pure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pure) { } 1767 1878 3645
82 1767 my ($day) = @_;
83 1767 return $self->{data}->{weekdays}->{$day};
84 }
85 else {
86 1878 return Decode_Day_of_Week(@_);
87 }
88 }
89  
90 sub _Decode_Month
91 3078 ▶{
Subroutine _Decode_Month: called CC=2 SCAR=6.9
92 3078 my $self = shift;
93  
94 3078 ▶ if ($Pure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pure) { } 1476 1602 3078
95 1476 my ($month) = @_;
96 1476 return $self->{data}->{months}->{$month};
97 }
98 else {
99 1602 return Decode_Month(@_);
100 }
101 }
102  
103 sub _Nth_Weekday_of_Month_Year
104 228 ▶{
Subroutine _Nth_Weekday_of_Month_Year: called CC=3 SCAR=11.0
105 228 my $self = shift;
106  
107 228 ▶ if ($Pure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pure) { } 114 114 228
108 114 my ($year, $month, $weekday, $count) = @_;
109 114 my $dt = $self->{datetime}->clone;
110 114 $dt->set_year($year);
111 114 $dt->set_month($month);
112 114 $dt->set_day(1);
113 114 ▶ $dt->set_day($dt->day + 1)
Branch: 1 branch
BranchTrueFalseTotal
$weekday ne $dt->dow and do { $dt->set_day($dt->day + 1) } 426 114 540
114 while ($weekday ne $dt->dow);
115 114 $dt->set_day($dt->day + 7 * ($count - 1));
116 114 return ($dt->year, $dt->month, $dt->day);
117 }
118 else {
119 114 return Nth_Weekday_of_Month_Year(@_);
120 }
121 }
122  
123 sub _check_date
124 4088 ▶{
Subroutine _check_date: called CC=2 SCAR=6.9
125 4088 my $self = shift;
126  
127 4088 ▶ if ($Pure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pure) { } 1962 2126 4088
128 1962 my ($year, $month, $day) = @_;
129 1962 local $@;
130 1962 eval {
131 1962 my $dt = $self->{datetime}->clone;
132 1962 $dt->set(year => $year, month => $month, day => $day);
133 };
134 1962 return !$@;
135 }
136 else {
137 2126 return check_date(@_);
138 }
139 }
140  
141 sub _check_time
142 9252 ▶{
Subroutine _check_time: called CC=2 SCAR=6.9
143 9252 my $self = shift;
144  
145 9252 ▶ if ($Pure) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Pure) { } 4554 4698 9252
146 4554 my ($hour, $minute, $second) = @_;
147 4554 local $@;
148 4554 eval {
149 4554 my $dt = $self->{datetime}->clone;
150 4554 $dt->set(hour => $hour, minute => $minute, second => $second);
151 };
152 4554 return !$@;
153 }
154 else {
155 4698 return check_time(@_);
156 }
157 }
158  
159 27 1;
160 __END__
« Natural/Lang/Base.pm ↑ Summary Natural/Helpers.pm »