lib/BalanceOfPower/Utils.pm

filter: Statementstmt 16.6% 18 / 108 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 21.7% 5 / 23 Podpod 0.0% 0 / 18 totaltotal 9.8% 23 / 234 CC 33 SCAR 40.6
CC
33
Cov
10%
compare_turns
182.0
from_to_turns
72.0
prev_turn
12.0
CRAP 58.1
« lib/BalanceOfPower/Role/Broker.pm ↑ Summary blib/lib/BalanceOfPower/Role/Broker.pm »
1 package BalanceOfPower::Utils;
2 11 $BalanceOfPower::Utils::VERSION = '0.300010';
3 11 ▶use BalanceOfPower::Constants ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub prev_turn
12 {
13 0 ▶ my $year = shift;
Subroutine prev_turn: not called CC=3 SCAR=24.8
Pod undocumented
14 0 my ($y, $i) = split '/', $year;
15 0 ▶ $i ||= 1;
Condition0%0/2
$i ||= 1
l!l
00
MC/DC0%0/1
$i ||= 1
$i
Truth table0%0/2
A
A= $i
Aresult
11
00
16 0 ▶ if($i == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 1) { } 0 0 0
17 {
18 0 return ($y -1) . '/' . TURNS_FOR_YEAR;
19 }
20 else
21 {
22 0 return $y . '/' . ($i - 1);
23 }
24 }
25 sub next_turn
26 {
27 0 ▶ my $year = shift;
Subroutine next_turn: not called CC=2 SCAR=17.9
Pod undocumented
28 0 my ($y, $i) = split '/', $year;
29 0 ▶ if($i == TURNS_FOR_YEAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 4) { } 0 0 0
30 {
31 0 return ($y +1) . '/' . '1';
32 }
33 else
34 {
35 0 return $y . '/' . ($i + 1);
36 }
37 }
38 sub get_year_turns
39 {
40 0 ▶ my $year = shift;
Subroutine get_year_turns: not called CC=3 SCAR=24.8
Pod undocumented
41 0 ▶ return ($year) if($year =~ /\d+\/\d+/);
Branch: 1 branch
BranchTrueFalseTotal
if $year =~ m[\d+/\d+] 0 0 0
42 0 my @turns = ();
43 0 ▶ for(my $i = 1; $i<= TURNS_FOR_YEAR; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 4) 0 0 0
44 {
45 0 push @turns, $year . '/' . $i;
46 }
47 0 return @turns;
48 }
49 sub split_turn
50 {
51 0 ▶ my $turn = shift;
Subroutine split_turn: not called CC=3 SCAR=24.8
Pod undocumented
52 0 ▶ if($turn =~ /(\d+)(\/(\d+))?/)
Branch: 1 branch
BranchTrueFalseTotal
if ($turn =~ m[(\d+)(/(\d+))?]) { } 0 0 0
53 {
54 0 my $turn_y = $1;
55 0 ▶ my $turn_t = $3 ? $3 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$3 ? : 0 0 0
56 0 return ($turn_y, $turn_t);
57 }
58 else
59 {
60 0 (undef, undef);
61 }
62 }
63 sub from_to_turns
64 {
65 0 ▶ my $from = shift;
Subroutine from_to_turns: not called CC=8 SCAR=42.8
Pod undocumented
66 0 my $to = shift;
67 0 my ($from_y, $from_t) = split_turn($from);
68 0 ▶ return () if(! $from_y);
Branch: 1 branch
BranchTrueFalseTotal
unless $from_y 0 0 0
69 0 my ($to_y, $to_t) = split_turn($to);
70 0 ▶ return () if(! $from_y);
Branch: 1 branch
BranchTrueFalseTotal
unless $from_y 0 0 0
71 return ()
72 0 ▶ if($to_y < $from_y || ($to_y == $from_y && $to_t < $from_t));
Branch: 1 branch
BranchTrueFalseTotal
if $to_y < $from_y or $to_y == $from_y and $to_t < $from_t 0 0 0
Condition0%0/6
$to_y < $from_y or $to_y == $from_y and $to_t < $from_t
l!l&&r!l&&!r
000
$to_y == $from_y and $to_t < $from_t
!ll&&!rl&&r
000
MC/DC0%0/3
$to_y < $from_y or $to_y == $from_y and $to_t < $from_t
$to_y < $from_y $to_y == $from_y $to_t < $from_t
Truth table0%0/4
A or B and C
A= $to_y < $from_yB= $to_y == $from_yC= $to_t < $from_t
ABCresult
1XX1
0111
00X0
0100
73 0 my $goon = 1;
74 0 my $to_add_y = $from_y;
75 0 my $to_add_t = $from_t;
76 0 my @turns = ();
77 0 while(1)
78 {
79 0 my $to_add = $to_add_y . '/' . $to_add_t;
80 0 push @turns, $to_add;
81 0 ▶ last if($to_add eq $to);
Branch: 1 branch
BranchTrueFalseTotal
if $to_add eq $to 0 0 0
82 0 ▶ if($to_add_t < TURNS_FOR_YEAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($to_add_t < 4) { } 0 0 0
83 {
84 0 $to_add_t++;
85 }
86 else
87 {
88 0 $to_add_y++;
89 0 $to_add_t = 1;
90 }
91 }
92 0 return @turns;
93 }
94  
95  
96  
97  
98 # first < second -> -1
99 # first = second -> 0
100 # first > second -> 1
101 #
102 sub compare_turns
103 {
104 0 ▶ my $first = shift;
Subroutine compare_turns: not called CC=13 SCAR=52.0
Pod undocumented
105 0 my $second = shift;
106 0 ▶ return 0 if ($first eq $second);
Branch: 1 branch
BranchTrueFalseTotal
if $first eq $second 0 0 0
107 0 my ($first_y, $first_t) = split_turn($first);
108 0 ▶ return undef if(! $first_y);
Branch: 1 branch
BranchTrueFalseTotal
unless $first_y 0 0 0
109 0 my ($second_y, $second_t) = split_turn($second);
110 0 ▶ return undef if(! $second_y);
Branch: 1 branch
BranchTrueFalseTotal
unless $second_y 0 0 0
111 0 ▶ return 0 if($first_y == $second_y && $first_t == $second_t);
Branch: 1 branch
BranchTrueFalseTotal
if $first_y == $second_y and $first_t == $second_t 0 0 0
Condition0%0/3
$first_y == $second_y and $first_t == $second_t
!ll&&!rl&&r
000
MC/DC0%0/2
$first_y == $second_y and $first_t == $second_t
$first_y == $second_y $first_t == $second_t
Truth table0%0/3
A and B
A= $first_y == $second_yB= $first_t == $second_t
ABresult
0X0
100
111
112 return undef
113 0 ▶ if($first_t < 0 ||
Branch: 1 branch
BranchTrueFalseTotal
if $first_t < 0 or $second_t < 0 or $first_t > 4 or $second_t > 4 0 0 0
Condition0%0/9
$first_t < 0 or $second_t < 0 or $first_t > 4 or $second_t > 4
l!l&&r!l&&!r
000
$first_t < 0 or $second_t < 0 or $first_t > 4
l!l&&r!l&&!r
000
$first_t < 0 or $second_t < 0
l!l&&r!l&&!r
000
MC/DC0%0/4
$first_t < 0 or $second_t < 0 or $first_t > 4 or $second_t > 4
$first_t < 0 $second_t < 0 $first_t > 4 $second_t > 4
Truth table0%0/5
A or B or C or D
A= $first_t < 0B= $second_t < 0C= $first_t > 4D= $second_t > 4
ABCDresult
1XXX1
01XX1
001X1
00011
00000
114 $second_t < 0 ||
115 $first_t > TURNS_FOR_YEAR ||
116 $second_t > TURNS_FOR_YEAR);
117 0 ▶ if($first_y > $second_y ||
Branch: 1 branch
BranchTrueFalseTotal
if ($first_y > $second_y or $first_y == $second_y and $first_t > $second_t) { } 0 0 0
Condition0%0/6
$first_y > $second_y or $first_y == $second_y and $first_t > $second_t
l!l&&r!l&&!r
000
$first_y == $second_y and $first_t > $second_t
!ll&&!rl&&r
000
MC/DC0%0/3
$first_y > $second_y or $first_y == $second_y and $first_t > $second_t
$first_y > $second_y $first_y == $second_y $first_t > $second_t
Truth table0%0/4
A or B and C
A= $first_y > $second_yB= $first_y == $second_yC= $first_t > $second_t
ABCresult
1XX1
0111
00X0
0100
118 (($first_y == $second_y && $first_t > $second_t)))
119 {
120 0 return 1;
121 }
122 else
123 {
124 0 return -1;
125 }
126 }
127 sub evidence_text
128 {
129 0 ▶ my $text = shift;
Subroutine evidence_text: not called CC=1 SCAR=6.9
Pod undocumented
130 0 my $key = shift;
131 0 $text =~ s/($key)/as_evidenced($1)/eg;
132 0 return $text;
133 }
134  
135 sub as_main_title
136 {
137 0 ▶ my $text = shift;
Subroutine as_main_title: not called CC=3 SCAR=24.8
Pod undocumented
138 0 my $mode = shift;
139 0 ▶ if($mode eq 'print')
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'print') { } 0 0 0
elsif ($mode eq 'html') { } 0 0 0
140 {
141 0 return as_title("$text\n===\n");
142 }
143 elsif($mode eq 'html')
144 {
145 0 return as_html_title($text);
146 }
147 }
148 sub as_main_subtitle
149 {
150 0 ▶ my $text = shift;
Subroutine as_main_subtitle: not called CC=3 SCAR=24.8
Pod undocumented
151 0 my $mode = shift;
152 0 ▶ if($mode eq 'print')
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'print') { } 0 0 0
elsif ($mode eq 'html') { } 0 0 0
153 {
154 0 return "### $text\n";
155 }
156 elsif($mode eq 'html')
157 {
158 0 return "<h4>$text</h4>";
159 }
160 }
161  
162 sub as_title
163 {
164 0 ▶ my $text = shift;
Subroutine as_title: not called CC=1 SCAR=6.9
Pod undocumented
165 0 return color("yellow bold") . $text . color("reset");
166 }
167 sub as_html_title
168 {
169 0 ▶ my $text = shift;
Subroutine as_html_title: not called CC=1 SCAR=6.9
Pod undocumented
170 0 return "<h3>$text</h3>";
171 }
172 sub as_html_dangerous
173 {
174 0 ▶ my $text = shift;
Subroutine as_html_dangerous: not called CC=1 SCAR=6.9
Pod undocumented
175 0 return '<span class="dangerous">' . $text . '</span>';
176 }
177 sub as_html_evidenced
178 {
179 0 ▶ my $text = shift;
Subroutine as_html_evidenced: not called CC=1 SCAR=6.9
Pod undocumented
180 0 return '<span class="evidenced">' . $text . '</span>';
181 }
182 sub as_html_box
183 {
184 0 ▶ my $text = shift;
Subroutine as_html_box: not called CC=1 SCAR=6.9
Pod undocumented
185 0 return "<p>$text</p>";
186 }
187 sub as_subtitle
188 {
189 0 ▶ my $text = shift;
Subroutine as_subtitle: not called CC=1 SCAR=6.9
Pod undocumented
190 0 return color("yellow") . $text . color("reset");
191 }
192 sub as_evidenced
193 {
194 0 ▶ my $text = shift;
Subroutine as_evidenced: not called CC=1 SCAR=6.9
Pod undocumented
195 0 return color("bold green") . $text . color("reset");
196 }
197 sub as_active
198 {
199 0 ▶ my $text = shift;
Subroutine as_active: not called CC=1 SCAR=6.9
Pod undocumented
200 0 return color("bold white") . $text . color("reset");
201 }
202 sub br
203 {
204 0 ▶ my $mode = shift;
Subroutine br: not called CC=3 SCAR=24.8
Pod undocumented
205 0 ▶ if($mode eq 'print')
Branch: 2 branches
BranchTrueFalseTotal
if ($mode eq 'print') { } 0 0 0
elsif ($mode eq 'html') { } 0 0 0
206 {
207 0 return "\n";
208 }
209 elsif($mode eq 'html')
210 {
211 0 return "<br />";
212 }
213 }
214  
215 11 our @EXPORT_OK = ('prev_turn', 'next_turn', 'random', 'random10', 'get_year_turns', 'as_title', 'from_to_turns', 'compare_turns', 'as_subtitle', 'evidence_text', 'as_evidenced', 'as_active', 'as_html_title', 'as_html_box', 'as_html_dangerous', 'as_html_evidenced', 'as_main_title', 'as_main_subtitle', 'br');
216  
217 11 1;
« lib/BalanceOfPower/Role/Broker.pm ↑ Summary blib/lib/BalanceOfPower/Role/Broker.pm »