SFX.pm

filter: Statementstmt 96.3% 78 / 81 Branchbran 75.0% 33 / 44 Conditioncond 56.6% 17 / 30 MC/DCmcdc 22.2% 4 / 18 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 75.8% 141 / 186 CC 35 SCAR 24.7
CC
35
Cov
83%
parse_sfx_threshold
20.9
parse_year_ranges
10.3
parse_sfx_year_range
8.1
CRAP 11.9
↑ Summary Fix/sfx_threshold.pm »
1 package Catmandu::SFX;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 our $VERSION = '0.02';
5  
6 3 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Catmandu::Util qw(:is);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶sub parse_sfx_threshold {
Subroutine parse_sfx_threshold: called CC=15 SCAR=30.4
Pod undocumented
12 6 my ($self,$str) = @_;
13
14 6 my $res = { raw => $str , start => {} , end => {} , limit => {} , years => [] };
15  
16 # Parse the Available from part...
17 6 ▶ if ($str =~ m{^Available\s+(.*)\.}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^Available\s+(.*)\./) 4 2 6
18 4 my $from = $1;
19  
20 4 ▶ if (defined $from && $from =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if (defined $from and $from =~ / (in|from) \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? (.*) /x) 4 0 4
Condition33%1/3
defined $from and $from =~ / (in|from) \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? (.*) /x
!ll&&!rl&&r
004
MC/DC0%0/2
defined $from and $from =~ / (in|from) \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? (.*) /x
defined $from $from =~ / (in|from) \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? (.*) /x
Truth table33%1/3
A and B
A= defined $fromB= $from =~ / (in|from) \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? (.*) /x
ABresult
0X0
100
111
21 (in|from)
22 \s+
23 (\d+)
24 (\s+volume:\s+(\S+))?
25 (\s+issue:\s+(\S+))?
26 (.*)
27 }x) {
28 4 $res->{start}->{year} = $2;
29 4 ▶ $res->{start}->{volume} = $4 if $3;
Branch: 1 branch
BranchTrueFalseTotal
if $3 2 2 4
30 4 ▶ $res->{start}->{issue} = $6 if $5;
Branch: 1 branch
BranchTrueFalseTotal
if $5 1 3 4
31 }
32  
33 4 my $until = $7;
34  
35 4 ▶ if (defined $until && $until =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if (defined $until and $until =~ / until \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? /x) 0 4 4
Condition33%1/3
defined $until and $until =~ / until \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? /x
!ll&&!rl&&r
040
MC/DC0%0/2
defined $until and $until =~ / until \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? /x
defined $until $until =~ / until \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? /x
Truth table33%1/3
A and B
A= defined $untilB= $until =~ / until \s+ (\d+) (\s+volume:\s+(\S+))? (\s+issue:\s+(\S+))? /x
ABresult
0X0
100
111
36 until
37 \s+
38 (\d+)
39 (\s+volume:\s+(\S+))?
40 (\s+issue:\s+(\S+))?
41 }x) {
42 0 ▶ $res->{end}->{year} = $1 if $1;
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 0 0
43 0 ▶ $res->{end}->{volume} = $3 if $3;
Branch: 1 branch
BranchTrueFalseTotal
if $3 0 0 0
44 0 ▶ $res->{end}->{issue} = $5 if $5;
Branch: 1 branch
BranchTrueFalseTotal
if $5 0 0 0
45 }
46 }
47
48 # Parse the Most recent part...
49 6 ▶ if ($str =~ m{
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ / Most \s+ recent \s+ (\d+) \s+ (year|month) \(s\) \s+ (not\s+)? available \. /x) 4 2 6
50 Most
51 \s+
52 recent
53 \s+
54 (\d+)
55 \s+
56 (year|month)
57 \(s\)
58 \s+
59 (not\s+)?
60 available
61 \.
62
63 }x) {
64 4 $res->{limit}->{num} = $1;
65 4 $res->{limit}->{type} = $2;
66 4 ▶ $res->{limit}->{available} = $3 ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$3 ? : 3 1 4
67 }
68  
69 6 ▶ if (exists $res->{end}->{year} || exists $res->{limit}->{num}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $res->{'end'}{'year'} or exists $res->{'limit'}{'num'}) { } 4 2 6
Condition66%2/3
exists $res->{"end"}{"year"} or exists $res->{"limit"}{"num"}
l!l&&r!l&&!r
042
MC/DC50%1/2
exists $res->{"end"}{"year"} or exists $res->{"limit"}{"num"}
exists $res->{"end"}{"year"} exists $res->{"limit"}{"num"}
Truth table66%2/3
A or B
A= exists $res->{"end"}{"year"}B= exists $res->{"limit"}{"num"}
ABresult
1X1
011
000
70 4 $res->{is_running} = 0;
71 }
72 else {
73 2 $res->{is_running} = 1;
74 }
75  
76 6 $res->{years} = $self->parse_year_ranges($res);
77  
78 6 $res->{human} = $self->parse_human_ranges($res);
79  
80 6 $res;
81 }
82  
83 6 ▶sub parse_human_ranges {
Subroutine parse_human_ranges: called CC=5 SCAR=16.3
Pod undocumented
84 6 my ($self,$parsed) = @_;
85 6 my $years = $parsed->{years};
86  
87 6 my @human = ();
88  
89 6 ▶ if (is_array_ref($years) && @$years > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array_ref($years) and @$years > 0) 6 0 6
Condition33%1/3
is_array_ref($years) and @$years > 0
!ll&&!rl&&r
006
MC/DC0%0/2
is_array_ref($years) and @$years > 0
is_array_ref($years) @$years > 0
Truth table33%1/3
A and B
A= is_array_ref($years)B= @$years > 0
ABresult
0X0
100
111
90 6 push @human , $years->[0];
91 6 ▶ push @human , $years->[-1] if @$years > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @$years > 1 4 2 6
92 }
93  
94 6 ▶ if ($parsed->{is_running} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parsed->{'is_running'} == 0) { } 4 2 6
95 4 return join(' - ', @human);
96 }
97 else {
98 2 return shift(@human) . " - ";
99 }
100 }
101  
102 6 ▶sub parse_year_ranges {
Subroutine parse_year_ranges: called CC=10 SCAR=23.3
Pod undocumented
103 6 my ($self,$parsed) = @_;
104  
105 # Calculate which years are available for users...
106 6 my $this_year = strftime("%Y", localtime);
107  
108 6 my ($start_year,$end_year);
109
110 6 ▶ $start_year = $parsed->{start}->{year} if exists $parsed->{start}->{year};
Branch: 1 branch
BranchTrueFalseTotal
if exists $parsed->{"start"}{"year"} 4 2 6
111 6 ▶ $start_year //= $this_year;
Condition66%2/3
$start_year //= $this_year
l!l&&r!l&&!r
420
MC/DC0%0/2
$start_year //= $this_year
$start_year $this_year
Truth table66%2/3
A //= B
A= $start_yearB= $this_year
ABresult
1X1
011
000
112  
113 6 ▶ $end_year = $parsed->{end}->{year} if exists $parsed->{end}->{year};
Branch: 1 branch
BranchTrueFalseTotal
if exists $parsed->{"end"}{"year"} 0 6 6
114 6 ▶ $end_year //= $this_year;
Condition33%1/3
$end_year //= $this_year
l!l&&r!l&&!r
060
MC/DC0%0/2
$end_year //= $this_year
$end_year $this_year
Truth table33%1/3
A //= B
A= $end_yearB= $this_year
ABresult
1X1
011
000
115  
116 # If most recent X years(s) are not available
117 6 ▶ if (exists $parsed->{limit} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $parsed->{"limit"} and $parsed->{"limit"}{"num"} and $parsed->{"limit"}{"type"} eq "year" and $parsed->{"limit"}{"available"} == 0) 2 4 6
Condition88%8/9
exists $parsed->{"limit"} and $parsed->{"limit"}{"num"} and $parsed->{"limit"}{"type"} eq "year" and $parsed->{"limit"}{"available"} == 0
!ll&&!rl&&r
312
exists $parsed->{"limit"} and $parsed->{"limit"}{"num"} and $parsed->{"limit"}{"type"} eq "year"
!ll&&!rl&&r
213
exists $parsed->{"limit"} and $parsed->{"limit"}{"num"}
!ll&&!rl&&r
024
MC/DC75%3/4
exists $parsed->{"limit"} and $parsed->{"limit"}{"num"} and $parsed->{"limit"}{"type"} eq "year" and $parsed->{"limit"}{"available"} == 0
exists $parsed->{"limit"} $parsed->{"limit"}{"num"} $parsed->{"limit"}{"type"} eq "year" $parsed->{"limit"}{"available"} == 0
Truth table80%4/5
A and B and C and D
A= exists $parsed->{"limit"}B= $parsed->{"limit"}{"num"}C= $parsed->{"limit"}{"type"} eq "year"D= $parsed->{"limit"}{"available"} == 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
118 $parsed->{limit}->{num} &&
119 $parsed->{limit}->{type} eq 'year' &&
120 $parsed->{limit}->{available} == 0) {
121 2 $end_year -= $parsed->{limit}->{num} + 1;
122 }
123  
124 6 ▶ if ($start_year < $end_year) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_year < $end_year) { } 4 2 6
125 4 return [ ($start_year .. $end_year) ];
126 }
127 else {
128 2 return [ ($end_year .. $start_year) ];
129 }
130 }
131  
132 1 ▶sub parse_sfx_year_range {
Subroutine parse_sfx_year_range: called CC=8 SCAR=20.9
Pod undocumented
133 1 my ($self, $years) = @_;
134  
135 1 ▶ return "" unless is_array_ref($years) && @$years > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless is_array_ref($years) and @$years > 0 0 1 1
Condition33%1/3
is_array_ref($years) and @$years > 0
!ll&&!rl&&r
001
MC/DC0%0/2
is_array_ref($years) and @$years > 0
is_array_ref($years) @$years > 0
Truth table33%1/3
A and B
A= is_array_ref($years)B= @$years > 0
ABresult
0X0
100
111
136  
137 1 my $curryear = [localtime time]->[5] + 1900;
138 1 my %h;
139  
140 1 foreach (@$years) {
141 6 $h{$_} = 1;
142 }
143  
144 1 my $start = undef;
145 1 my $prev = undef;
146 1 my $human = '';
147  
148 1 foreach (sort { $a <=> $b } keys %h) {
149 6 ▶ if (! defined $start) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $start) { } 1 5 6
elsif ($_ == $prev + 1) { } 3 2 5
elsif ($start == $prev) { } 1 1 2
150 1 $start = $_;
151 }
152 elsif ($_ == $prev + 1) { }
153 elsif ($start == $prev) {
154 1 $human .= "$start ; ";
155 1 $start = $_;
156 }
157 else {
158 1 $human .= "$start - $prev ; ";
159 1 $start = $_;
160 }
161 6 $prev = $_;
162 }
163  
164 1 $human .= "$start - $prev";
165  
166 1 return $human;
167 }
168  
169 3 1;
170  
171 __END__
↑ Summary Fix/sfx_threshold.pm »