lib/BalanceOfPower/Role/Recorder.pm

filter: Statementstmt 12.7% 18 / 141 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 6 totaltotal 11.4% 23 / 201 CC 27 SCAR 49.9
CC
27
Cov
10%
load_world
306.0
load_nations
20.0
load_players
20.0
CRAP 147.6
« blib/lib/BalanceOfPower/Commands/NagTreaty.pm ↑ Summary blib/lib/BalanceOfPower/Role/Recorder.pm »
1 package BalanceOfPower::Role::Recorder;
2 11 $BalanceOfPower::Role::Recorder::VERSION = '0.200000';
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use BalanceOfPower::Nation;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use BalanceOfPower::Executive;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 requires 'dump_events';
11 11 requires 'load_events';
12  
13  
14 sub dump
15 {
16 0 ▶ my $self = shift;
Subroutine dump: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my $io = shift;
18 0 ▶ my $indent = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
19 0 print {$io} $indent . join(";", $self->name, $self->first_year, $self->current_year) . "\n";
20 0 $self->dump_events($io, " " . $indent);
21 }
22 sub load
23 {
24 0 ▶ my $self = shift;
Subroutine load: not called CC=1 SCAR=6.9
Pod undocumented
25 0 my $data = shift;
26 0 my $world_line = ( split /\n/, $data )[0];
27 0 $world_line =~ s/^\s+//;
28 0 chomp $world_line;
29 0 my ($name, $first_year, $current_year) =
30 split ";", $world_line;
31 0 $data =~ s/^.*?\n//;
32 0 my $events = $self->load_events($data);
33 0 return BalanceOfPower::World->new(name => $name,
34 first_year => $first_year, current_year => $current_year,
35 events => $events);
36 }
37  
38 sub load_nations
39 {
40 0 ▶ my $self = shift;
Subroutine load_nations: not called CC=4 SCAR=30.0
Pod undocumented
41 0 my $data = shift;
42 0 $data .= "EOF\n";
43 0 my $nation_data = "";
44 0 foreach my $l (split "\n", $data)
45 {
46  
47 0 ▶ if($l !~ /^\s/)
Branch: 1 branch
BranchTrueFalseTotal
if (not $l =~ /^\s/) { } 0 0 0
48 {
49 0 ▶ if($nation_data)
Branch: 1 branch
BranchTrueFalseTotal
if ($nation_data) 0 0 0
50 {
51 0 my $nation = BalanceOfPower::Nation->load($nation_data);
52 0 my $executive = BalanceOfPower::Executive->new( actor => $nation->name );
53 0 $executive->init($self);
54 0 $nation->executive($executive);
55 0 push @{$self->nations}, $nation;
56 0 push @{$self->nation_names}, $nation->name;
57 0 $self->nation_codes->{$nation->code} = $nation->name;
58 }
59 0 $nation_data = $l . "\n";
60 }
61 else
62 {
63 0 $nation_data .= $l . "\n";
64 }
65 }
66 }
67 sub load_players
68 {
69 0 ▶ my $self = shift;
Subroutine load_players: not called CC=4 SCAR=30.0
Pod undocumented
70 0 my $data = shift;
71 0 $data .= "EOF\n";
72 0 my $player_data = "";
73 0 foreach my $l (split "\n", $data)
74 {
75  
76 0 ▶ if($l !~ /^\s/)
Branch: 1 branch
BranchTrueFalseTotal
if (not $l =~ /^\s/) { } 0 0 0
77 {
78 0 ▶ if($player_data)
Branch: 1 branch
BranchTrueFalseTotal
if ($player_data) 0 0 0
79 {
80 0 my $player = BalanceOfPower::Player->load($player_data);
81 0 push @{$self->players}, $player;
82 }
83 0 $player_data = $l . "\n";
84 }
85 else
86 {
87 0 $player_data .= $l . "\n";
88 }
89 }
90 }
91  
92  
93 sub dump_all
94 {
95 0 ▶ my $self = shift;
Subroutine dump_all: not called CC=4 SCAR=30.0
Pod undocumented
96 0 my $file = shift;
97 0 ▶ return "No file provided" if ! $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
98 0 open(my $io, "> $file");
99 0 $self->dump($io);
100 0 print {$io} "### NATIONS\n";
101 0 for(@{$self->nations})
102 {
103 0 $_->dump($io);
104 }
105 0 print {$io} "### PLAYERS\n";
106 0 for(@{$self->players})
107 {
108 0 $_->dump($io);
109 }
110 0 print {$io} "### DIPLOMATIC RELATIONS\n";
111 0 $self->diplomatic_relations->dump($io);
112 0 print {$io} "### TREATIES\n";
113 0 $self->treaties->dump($io);
114 0 print {$io} "### BORDERS\n";
115 0 $self->borders->dump($io);
116 0 print {$io} "### TRADEROUTES\n";
117 0 $self->trade_routes->dump($io);
118 0 print {$io} "### INFLUENCES\n";
119 0 $self->influences->dump($io);
120 0 print {$io} "### SUPPORTS\n";
121 0 $self->military_supports->dump($io);
122 0 print {$io} "### REBEL SUPPORTS\n";
123 0 $self->rebel_military_supports->dump($io);
124 0 print {$io} "### WARS\n";
125 0 $self->wars->dump($io);
126 0 print {$io} "### MEMORIAL\n";
127 0 $self->dump_memorial($io);
128 0 print {$io} "### STATISTICS\n";
129 0 $self->dump_statistics($io);
130 0 print {$io} "### EOF\n";
131 0 close($io);
132 0 return "World saved to $file";
133 }
134  
135 sub load_world
136 {
137 0 ▶ my $self = shift;
Subroutine load_world: not called CC=17 SCAR=57.2
Pod undocumented
138 0 my $file = shift;
139 0 ▶ open(my $dump, "<", $file) or die "Problems opening $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $dump, "<", $file or die "Problems opening ${file}: $!" 0 0 0
140 0 my $world;
141 0 my $target = "WORLD";
142 0 my $data = "";
143 0 for(<$dump>)
144 {
145 0 my $line = $_;
146 0 ▶ if($line =~ /^### (.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^### (.*)$/) { } 0 0 0
147 {
148 0 my $next = $1;
149 0 ▶ if($target eq 'WORLD')
Branch: 13 branches
BranchTrueFalseTotal
if ($target eq 'WORLD') { } 0 0 0
elsif ($target eq 'NATIONS') { } 0 0 0
elsif ($target eq 'PLAYERS') { } 0 0 0
elsif ($target eq 'DIPLOMATIC RELATIONS') { } 0 0 0
elsif ($target eq 'TREATIES') { } 0 0 0
elsif ($target eq 'BORDERS') { } 0 0 0
elsif ($target eq 'TRADEROUTES') { } 0 0 0
elsif ($target eq 'INFLUENCES') { } 0 0 0
elsif ($target eq 'SUPPORTS') { } 0 0 0
elsif ($target eq 'REBEL SUPPORTS') { } 0 0 0
elsif ($target eq 'WARS') { } 0 0 0
elsif ($target eq 'MEMORIAL') { } 0 0 0
elsif ($target eq 'STATISTICS') { } 0 0 0
150 {
151 0 $world = $self->load($data);
152 }
153 elsif($target eq 'NATIONS')
154 {
155 0 $world->load_nations($data);
156 }
157 elsif($target eq 'PLAYERS')
158 {
159 0 $world->load_players($data);
160 }
161 elsif($target eq 'DIPLOMATIC RELATIONS')
162 {
163 0 $world->diplomatic_relations->load_pack("BalanceOfPower::Relations::Friendship", $data);
164 }
165 elsif($target eq 'TREATIES')
166 {
167 0 $world->treaties->load_pack("BalanceOfPower::Relations::Treaty", $data);
168 }
169 elsif($target eq 'BORDERS')
170 {
171 0 $world->borders->load_pack("BalanceOfPower::Relations::Border", $data);
172 }
173 elsif($target eq 'TRADEROUTES')
174 {
175 0 $world->trade_routes->load_pack("BalanceOfPower::Relations::TradeRoute", $data);
176 }
177 elsif($target eq 'INFLUENCES')
178 {
179 0 $world->influences->load_pack("BalanceOfPower::Relations::Influence", $data);
180 }
181 elsif($target eq 'SUPPORTS')
182 {
183 0 $world->military_supports->load_pack("BalanceOfPower::Relations::MilitarySupport", $data);
184 }
185 elsif($target eq 'REBEL SUPPORTS')
186 {
187 0 $world->rebel_military_supports->load_pack("BalanceOfPower::Relations::MilitarySupport", $data);
188 }
189 elsif($target eq 'WARS')
190 {
191 0 $world->wars->load_pack("BalanceOfPower::Relations::War", $data);
192 }
193 elsif($target eq 'MEMORIAL')
194 {
195 0 $world->memorial($world->load_memorial($data));
196 }
197 elsif($target eq 'STATISTICS')
198 {
199 0 $world->load_statistics($data);
200 }
201 0 $data = "";
202 0 $target = $next;
203 }
204 else
205 {
206 0 $data .= $line;
207 }
208 }
209 0 close($dump);
210 0 return $world;
211 }
212  
213 11 1;
« blib/lib/BalanceOfPower/Commands/NagTreaty.pm ↑ Summary blib/lib/BalanceOfPower/Role/Recorder.pm »