lib/BalanceOfPower/Utils.pm

filter: Statementstmt 81.4% 70 / 86 Branchbran 70.5% 24 / 34 Conditioncond 19.2% 5 / 26 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 75.0% 12 / 16 Podpod 0.0% 0 / 11 totaltotal 59.6% 111 / 186 CC 27 SCAR 31.0
CC
27
Cov
68%
compare_turns
63.1
from_to_turns
8.2
split_turn
3.1
CRAP 22.2
« blib/lib/BalanceOfPower/Utils.pm ↑ Summary lib/BalanceOfPower/Role/Analyst.pm »
1 package BalanceOfPower::Utils;
2 11 $BalanceOfPower::Utils::VERSION = '0.200000';
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 1822 ▶ my $year = shift;
Subroutine prev_turn: called CC=3 SCAR=11.0
Pod undocumented
14 1822 my ($y, $i) = split '/', $year;
15 1822 ▶ $i ||= 1;
Condition50%1/2
$i ||= 1
l!l
18220
MC/DC0%0/1
$i ||= 1
$i
Truth table50%1/2
A
A= $i
Aresult
11
00
16 1822 ▶ if($i == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 1) { } 612 1210 1822
17 {
18 612 return ($y -1) . '/' . TURNS_FOR_YEAR;
19 }
20 else
21 {
22 1210 return $y . '/' . ($i - 1);
23 }
24 }
25 sub next_turn
26 {
27 5 ▶ my $year = shift;
Subroutine next_turn: called CC=2 SCAR=6.9
Pod undocumented
28 5 my ($y, $i) = split '/', $year;
29 5 ▶ if($i == TURNS_FOR_YEAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 4) { } 2 3 5
30 {
31 2 return ($y +1) . '/' . '1';
32 }
33 else
34 {
35 3 return $y . '/' . ($i + 1);
36 }
37 }
38 sub get_year_turns
39 {
40 19 ▶ my $year = shift;
Subroutine get_year_turns: called CC=3 SCAR=11.0
Pod undocumented
41 19 ▶ return ($year) if($year =~ /\d+\/\d+/);
Branch: 1 branch
BranchTrueFalseTotal
if $year =~ m[\d+/\d+] 18 1 19
42 1 my @turns = ();
43 1 ▶ for(my $i = 1; $i<= TURNS_FOR_YEAR; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 4) 4 1 5
44 {
45 4 push @turns, $year . '/' . $i;
46 }
47 1 return @turns;
48 }
49 sub split_turn
50 {
51 14 ▶ my $turn = shift;
Subroutine split_turn: called CC=3 SCAR=11.2
Pod undocumented
52 14 ▶ if($turn =~ /(\d+)(\/(\d+))?/)
Branch: 1 branch
BranchTrueFalseTotal
if ($turn =~ m[(\d+)(/(\d+))?]) { } 14 0 14
53 {
54 14 my $turn_y = $1;
55 14 ▶ my $turn_t = $3 ? $3 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$3 ? : 8 6 14
56 14 return ($turn_y, $turn_t);
57 }
58 else
59 {
60 0 (undef, undef);
61 }
62 }
63 sub from_to_turns
64 {
65 5 ▶ my $from = shift;
Subroutine from_to_turns: called CC=8 SCAR=21.0
Pod undocumented
66 5 my $to = shift;
67 5 my ($from_y, $from_t) = split_turn($from);
68 5 ▶ return () if(! $from_y);
Branch: 1 branch
BranchTrueFalseTotal
unless $from_y 0 5 5
69 5 my ($to_y, $to_t) = split_turn($to);
70 5 ▶ return () if(! $from_y);
Branch: 1 branch
BranchTrueFalseTotal
unless $from_y 0 5 5
71 return ()
72 5 ▶ 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 4 1 5
Condition50%3/6
$to_y < $from_y or $to_y == $from_y and $to_t < $from_t
l!l&&r!l&&!r
401
$to_y == $from_y and $to_t < $from_t
!ll&&!rl&&r
100
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 table25%1/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 1 my $goon = 1;
74 1 my $to_add_y = $from_y;
75 1 my $to_add_t = $from_t;
76 1 my @turns = ();
77 1 while(1)
78 {
79 14 my $to_add = $to_add_y . '/' . $to_add_t;
80 14 push @turns, $to_add;
81 14 ▶ last if($to_add eq $to);
Branch: 1 branch
BranchTrueFalseTotal
if $to_add eq $to 1 13 14
82 13 ▶ if($to_add_t < TURNS_FOR_YEAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($to_add_t < 4) { } 10 3 13
83 {
84 10 $to_add_t++;
85 }
86 else
87 {
88 3 $to_add_y++;
89 3 $to_add_t = 1;
90 }
91 }
92 1 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 4 ▶ my $first = shift;
Subroutine compare_turns: called CC=13 SCAR=41.4
Pod undocumented
105 4 my $second = shift;
106 4 ▶ return 0 if ($first eq $second);
Branch: 1 branch
BranchTrueFalseTotal
if $first eq $second 2 2 4
107 2 my ($first_y, $first_t) = split_turn($first);
108 2 ▶ return undef if(! $first_y);
Branch: 1 branch
BranchTrueFalseTotal
unless $first_y 0 2 2
109 2 my ($second_y, $second_t) = split_turn($second);
110 2 ▶ return undef if(! $second_y);
Branch: 1 branch
BranchTrueFalseTotal
unless $second_y 0 2 2
111 2 ▶ 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 2 0 2
Condition33%1/3
$first_y == $second_y and $first_t == $second_t
!ll&&!rl&&r
002
MC/DC0%0/2
$first_y == $second_y and $first_t == $second_t
$first_y == $second_y $first_t == $second_t
Truth table33%1/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_title
136 {
137 24 ▶ my $text = shift;
Subroutine as_title: called CC=1 SCAR=0.0
Pod undocumented
138 24 return color("yellow bold") . $text . color("reset");
139 }
140 sub as_subtitle
141 {
142 0 ▶ my $text = shift;
Subroutine as_subtitle: not called CC=1 SCAR=6.9
Pod undocumented
143 0 return color("yellow") . $text . color("reset");
144 }
145 sub as_evidenced
146 {
147 0 ▶ my $text = shift;
Subroutine as_evidenced: not called CC=1 SCAR=6.9
Pod undocumented
148 0 return color("bold green") . $text . color("reset");
149 }
150 sub as_active
151 {
152 0 ▶ my $text = shift;
Subroutine as_active: not called CC=1 SCAR=6.9
Pod undocumented
153 0 return color("bold white") . $text . color("reset");
154 }
155  
156 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');
157  
158 11 1;
« blib/lib/BalanceOfPower/Utils.pm ↑ Summary lib/BalanceOfPower/Role/Analyst.pm »