Handler/Range.pm

filter: Statementstmt 75.0% 54 / 72 Branchbran 47.2% 17 / 36 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 92.3% 12 / 13 Podpod 0.0% 0 / 7 totaltotal 58.7% 87 / 148 CC 23 SCAR 22.0
CC
23
Cov
62%
Overlaps
20.0
new
17.5
Direction
8.6
CRAP 9.0
« Handler.pm ↑ Summary Handler/Test.pm »
1 #!/usr/bin/perl
2 package Date::Handler::Range;
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Date::Handler;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Date::Handler::Delta;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 $VERSION = '1.0';
13  
14 sub new
15 1 ▶{
Subroutine new: called CC=8 SCAR=28.6
Pod undocumented
16 1 my ($classname, $args) = @_;
17  
18 1 ▶ croak "No arguments to new()" if not defined $args;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args 0 1 1
19 1 ▶ croak "No date argument passed to new()" if not defined $args->{date};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args->{"date"} 0 1 1
20  
21 1 my $self = {};
22 1 bless $self, $classname;
23  
24 1 ▶ if(ref($args) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args eq 'HASH') { } 1 0 1
25 {
26 #Get the date from the arguments.
27 1 ▶ if(UNIVERSAL::isa($args->{date}, 'Date::Handler'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($args->{'date'}, 'Date::Handler')) { } 1 0 1
28 {
29 1 $self->{date} = $args->{date};
30 }
31 else
32 {
33 0 my $date = new Date::Handler({ date => $args->{date} });
34 0 ▶ if(defined $date)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $date) { } 0 0 0
35 {
36 0 $self->{date} = $date;
37 }
38 else
39 {
40 0 croak "Invalid format for date in new()";
41 }
42 }
43
44 1 ▶ if(UNIVERSAL::isa($args->{delta}, 'Date::Handler::Delta'))
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($args->{'delta'}, 'Date::Handler::Delta')) { } 1 0 1
45 {
46 1 $self->{delta} = $args->{delta};
47 }
48 else
49 {
50 0 my $delta = Date::Handler::Delta->new($args->{delta});
51 0 ▶ if(defined $delta)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $delta) { } 0 0 0
52 {
53 0 $self->{delta} = $delta;
54 }
55 else
56 {
57 0 croak "Invalid format for delta in new()";
58 }
59 }
60 }
61 else
62 {
63 0 croak "Invalid arguments passed to new() (not HASHREF)";
64 }
65  
66 1 return $self;
67 }
68  
69  
70 sub Direction
71 5 ▶{
Subroutine Direction: called CC=7 SCAR=21.5
Pod undocumented
72 5 my $self = shift;
73 5 my $direction = shift;
74  
75 5 ▶ if(defined $direction)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $direction) 1 4 5
76 {
77 1 ▶ if($direction =~ /FORWARDS/i || $direction eq 1)
Branch: 2 branches
BranchTrueFalseTotal
if ($direction =~ /FORWARDS/i or $direction eq 1) { } 0 1 1
elsif ($direction =~ /BACKWARDS/i or $direction eq 0) { } 1 0 1
Condition33%1/3
$direction =~ /FORWARDS/i or $direction eq 1
l!l&&r!l&&!r
001
MC/DC0%0/2
$direction =~ /FORWARDS/i or $direction eq 1
$direction =~ /FORWARDS/i $direction eq 1
Truth table33%1/3
A or B
A= $direction =~ /FORWARDS/iB= $direction eq 1
ABresult
1X1
011
000
78 {
79 0 $self->{direction} = 1;
80 }
81 ▶ elsif($direction =~ /BACKWARDS/i || $direction eq 0)
Condition33%1/3
$direction =~ /BACKWARDS/i or $direction eq 0
l!l&&r!l&&!r
100
MC/DC0%0/2
$direction =~ /BACKWARDS/i or $direction eq 0
$direction =~ /BACKWARDS/i $direction eq 0
Truth table33%1/3
A or B
A= $direction =~ /BACKWARDS/iB= $direction eq 0
ABresult
1X1
011
000
82 {
83 1 $self->{direction} = 0;
84 }
85 }
86  
87 5 ▶ $self->{direction} = 1 if not defined $self->{direction};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"direction"} 1 4 5
88 5 return $self->{direction};
89 }
90
91  
92 sub Delta
93 2 ▶{
Subroutine Delta: called CC=3 SCAR=12.7
Pod undocumented
94 2 my $self = shift;
95 2 my $delta = shift;
96  
97 2 ▶ if(defined $delta && $delta->isa('Date::Handler::Delta'))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $delta and $delta->isa("Date::Handler::Delta")) 0 2 2
Condition33%1/3
defined $delta and $delta->isa("Date::Handler::Delta")
!ll&&!rl&&r
200
MC/DC0%0/2
defined $delta and $delta->isa("Date::Handler::Delta")
defined $delta $delta->isa("Date::Handler::Delta")
Truth table33%1/3
A and B
A= defined $deltaB= $delta->isa("Date::Handler::Delta")
ABresult
0X0
100
111
98 {
99 0 $self->{delta} = $delta;
100 }
101 2 return $self->{delta};
102 }
103  
104 sub Date
105 4 ▶{
Subroutine Date: called CC=3 SCAR=12.7
Pod undocumented
106 4 my $self = shift;
107 4 my $date = shift;
108  
109 4 ▶ if(defined $date && $date->isa('Date::Handler'))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $date and $date->isa("Date::Handler")) 0 4 4
Condition33%1/3
defined $date and $date->isa("Date::Handler")
!ll&&!rl&&r
400
MC/DC0%0/2
defined $date and $date->isa("Date::Handler")
defined $date $date->isa("Date::Handler")
Truth table33%1/3
A and B
A= defined $dateB= $date->isa("Date::Handler")
ABresult
0X0
100
111
110 {
111 0 $self->{date} = $date;
112 }
113 4 return $self->{date};
114 }
115  
116 sub StartDate
117 2 ▶{
Subroutine StartDate: called CC=2 SCAR=6.9
Pod undocumented
118 2 my $self = shift;
119  
120 2 ▶ if($self->Direction())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Direction) { } 1 1 2
121 {
122 1 return $self->Date();
123 }
124 else
125 {
126 1 return $self->Date() - $self->Delta();
127 }
128 }
129  
130 sub EndDate
131 2 ▶{
Subroutine EndDate: called CC=2 SCAR=6.9
Pod undocumented
132 2 my $self = shift;
133
134 2 ▶ if($self->Direction())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Direction) { } 1 1 2
135 {
136 1 return $self->Date() + $self->Delta();
137 }
138 else
139 {
140 1 return $self->Date();
141 }
142 }
143  
144 sub Overlaps
145 0 ▶{
Subroutine Overlaps: not called CC=4 SCAR=30.0
Pod undocumented
146 0 my $self = shift;
147 0 my $range = shift;
148  
149 0 ▶ croak "Arguments to Overlaps() is not a Date::Handler::Range" if !$range->isa('Date::Handler::Range');
Branch: 1 branch
BranchTrueFalseTotal
unless $range->isa("Date::Handler::Range") 0 0 0
150  
151 0 ▶ return 0 if($self->EndDate() <= $range->StartDate());
Branch: 1 branch
BranchTrueFalseTotal
if $self->EndDate <= $range->StartDate 0 0 0
152 0 ▶ return 0 if($range->EndDate() <= $self->StartDate());
Branch: 1 branch
BranchTrueFalseTotal
if $range->EndDate <= $self->StartDate 0 0 0
153 0 return 1;
154  
155 }
156  
157
158  
159 8 666;
160 __END__
« Handler.pm ↑ Summary Handler/Test.pm »