Pak.pm

filter: Statementstmt 83.1% 128 / 154 Branchbran 63.9% 55 / 86 Conditioncond 38.7% 24 / 62 MC/DCmcdc 11.4% 4 / 35 Subroutinesub 88.2% 15 / 17 Podpod 50.0% 6 / 12 totaltotal 63.3% 232 / 366 CC 82 SCAR 37.9
CC
82
Cov
69%
from_string
93.4
payload_text
20.0
deep_print
15.1
CRAP 44.0
« Image.pm ↑ Summary Livery.pm »
1 package Games::Simutrans::Pak;
2  
3 #
4 # Represents an individual Simutrans object (although multiple objects
5 # may reside in an actual *.pak file).
6 #
7  
8 1 ▶use v5.32;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.02';
11  
12 1 ▶use Mojo::Base -base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Mojo::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Data::DeepAccess qw(deep_exists deep_get deep_set);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 has '_intro';
17 1 has '_retire';
18 1 has 'name';
19  
20 ################
21 #
22 # Create an object from, e.g., a dat file section.
23 # This requires both the text, and the pathname from which it was loaded,
24 # in order to be able to locate the attached images.
25 #
26 ################
27  
28 3 ▶sub from_string ($self, $params) {
Subroutine from_string: called CC=41 SCAR=45.4
Pod documented
29  
30 3 my $filename;
31 my $dat_text;
32  
33 3 ▶ if (ref $params) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params) { } 3 0 3
34 3 $filename = $params->{file};
35 3 $dat_text = $params->{text};
36 } else {
37 0 return undef;
38 }
39  
40 3 my %this_object;
41 3 $this_object{_filename} = $filename;
42  
43 3 foreach my $line (split("\n", $dat_text)) {
44 # Remove (but save) comments
45 63 ▶ if ($line =~ s/\#(?<comment>.*)\Z//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ s/\#(?<comment>.*)\Z//u) { } 3 60 63
elsif ($line =~ /^\s*-{2,}/u) { } 1 59 60
46 3 push @{$this_object{_comments}}, $+{comment};
47 } elsif ($line =~ /^\s*-{2,}/) {
48 1 last; # Only load the first object. Caller is responsible for splitting *.dat files.
49 }
50  
51 62 ▶ if ($line =~ /^\s*(?<object>\w+)\s*(?:\[(?<subscr>(?:\[|\]|\-|\w|\s)+)\])?\s*=(?<nozoom>>?)\s*(?<value>.*?)\s*\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*(?<object>\w+)\s*(?:\[(?<subscr>(?:\[|\]|\-|\w|\s)+)\])?\s*=(?<nozoom>>?)\s*(?<value>.*?)\s*\Z/u) 54 8 62
52 # /^\s*(?<object>\w+)\s*(?:\[(?<sub1>\w+)\](?:\[(?<sub2>\w+)\])?)?\s*=\s*(?<value>.*?)\s*\Z/) {
53 54 my ($object, $value, $nozoom) = @+{qw(object value)};
54 54 $object = lc($object);
55 54 ▶ $this_object{_nozoom}{$object} = 1 if $+{nozoom}; # icon=>foo means foo.png without change as map is zoomed
Branch: 1 branch
BranchTrueFalseTotal
if $+{"nozoom"} 0 54 54
56 54 my @subscripts;
57 54 ▶ @subscripts = split /[\[\]]+/, $+{subscr} if defined $+{subscr};
Branch: 1 branch
BranchTrueFalseTotal
if defined $+{"subscr"} 24 30 54
58 54 ▶ if (scalar @subscripts || $object =~ /^(?:cursor|icon)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @subscripts or $object =~ /^(?:cursor|icon)\z/u) { } 24 30 54
Condition66%2/3
scalar @subscripts or $object =~ /^(?:cursor|icon)\z/u
l!l&&r!l&&!r
24030
MC/DC50%1/2
scalar @subscripts or $object =~ /^(?:cursor|icon)\z/u
scalar @subscripts $object =~ /^(?:cursor|icon)\z/u
Truth table66%2/3
A or B
A= scalar @subscriptsB= $object =~ /^(?:cursor|icon)\z/u
ABresult
1X1
011
000
59 # NOTE: Values with subscripts, as "value[0]=50", will clobber a previous "value=50".
60 24 ▶ if (ref(\$this_object{$object}) eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref \$this_object{$object} eq "SCALAR") 3 21 24
61 3 undef $this_object{$object};
62 }
63 24 my $is_image = 0;
64 24 my $dimensions;
65 24 ▶ if ($object =~ /^(front|back)?(image|diagonal|start|ramp|pillar)(up)?2?\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($object =~ /^(front|back)?(image|diagonal|start|ramp|pillar)(up)?2?\z/u) { } 24 0 24
elsif ($object =~ /^((empty|freight)image|cursor|icon)\z/u) { } 0 0 0
66 # NOTE: certain keys (FrontImage, BackImage) have multiple assumed axes,
67 # but not all values will give values for each; thus you may find two
68 # entries as:
69 # FrontImage[1][0] = value1
70 # FrontImage[1][0][1] = value2
71 # where value1 is actually for FrontImage[1][0][0][0][0][0], with all the
72 # unstated axes defaulting to zero.
73 24 ▶ $dimensions = (defined $1 && $2 eq 'image') ? 6 : 2; # frontimage, backimage are 6-dim;
Branch: 1 branch
BranchTrueFalseTotal
defined $1 && $2 eq 'image' ? : 24 0 24
Condition33%1/3
defined $1 and $2 eq "image"
!ll&&!rl&&r
0024
MC/DC0%0/2
defined $1 and $2 eq "image"
defined $1 $2 eq "image"
Truth table33%1/3
A and B
A= defined $1B= $2 eq "image"
ABresult
0X0
100
111
74 # all other images are two-dimensional (one axis plus season).
75 24 $is_image++;
76 } elsif ($object =~ /^((empty|freight)image|cursor|icon)\z/) {
77 0 $dimensions = 3;
78 0 $is_image++;
79 }
80 24 ▶ if (defined $dimensions) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dimensions) 24 0 24
81 24 ▶ if (scalar @subscripts > $dimensions) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @subscripts > $dimensions) 0 24 24
82 0 ▶ print STDERR "Object " . ($this_object{name} // '??') . " has " .
Condition0%0/2
$this_object{"name"} // "??"
l!l
00
MC/DC0%0/1
$this_object{"name"} // "??"
$this_object{"name"}
Truth table0%0/2
A
A= $this_object{"name"}
Aresult
11
00
83 scalar @subscripts . " ($dimensions expected)\n";
84 }
85 # Convert to correction number of dimensions, with '0' defaults:
86 24 ▶ @subscripts = map { $_ // 0 } @subscripts[0..($dimensions-1)];
Condition50%1/2
$_ // 0
l!l
1440
MC/DC0%0/1
$_ // 0
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
87 }
88 24 ▶ if ($is_image) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_image) 24 0 24
89 # Can begin as './something' but otherwise file cannot have dots within
90 24 ▶ if ($value =~ /^(?<image>\.?[^.]+)
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(?<image>\.?[^.]+) (?:\.(?<y>\d+) (?:\.(?<x>\d+))? (?:,(?<xoff>\d+) (?:,(?<yoff>\d+))? )? )?/ax) 24 0 24
91 (?:\.(?<y>\d+)
92 (?:\.(?<x>\d+))?
93 (?:,(?<xoff>\d+)
94 (?:,(?<yoff>\d+))?
95 )?
96 )?/xa) {
97 72 ▶ $value = { ( map { defined $+{$_} ? ($_ => $+{$_}) : () } qw(image xoff yoff) ), # skip each if undef
Branch: 1 branch
BranchTrueFalseTotal
defined $+{$_} ? : 24 48 72
98 24 ▶ ( map { $_ => $+{$_} // 0 } qw( x y ) ) }; # these default to zero
Condition50%1/2
$+{$_} // 0
l!l
480
MC/DC0%0/1
$+{$_} // 0
$+{$_}
Truth table50%1/2
A
A= $+{$_}
Aresult
11
00
99 # Override above in case of older "imagefile.3" form, which assumes column (x) only
100 24 ▶ if (!defined $+{x} && $object =~ /^(front|back|empty|freight)/) { #
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $+{"x"} and $object =~ /^(front|back|empty|freight)/u) 0 24 24
Condition33%1/3
not defined $+{"x"} and $object =~ /^(front|back|empty|freight)/u
!ll&&!rl&&r
2400
MC/DC0%0/2
not defined $+{"x"} and $object =~ /^(front|back|empty|freight)/u
not defined $+{"x"} $object =~ /^(front|back|empty|freight)/u
Truth table33%1/3
not(A) and B
A= not defined $+{"x"}B= $object =~ /^(front|back|empty|freight)/u
ABresult
0X0
100
111
101 0 ▶ $value->{x} = $+{y} // 0; $value->{y} = 0;
Condition0%0/2
$+{"y"} // 0
l!l
00
MC/DC0%0/1
$+{"y"} // 0
$+{"y"}
Truth table0%0/2
A
A= $+{"y"}
Aresult
11
00
102 }
103 24 ▶ $value->{imagefile} = Mojo::File->new($filename)->sibling($value->{image}.'.png') unless $value->{image} eq '-';
Branch: 1 branch
BranchTrueFalseTotal
unless $value->{"image"} eq "-" 24 0 24
104 24 $this_object{_hasimages}{$object}++;
105 }
106 }
107 # for Data::DeepAccess … Thanks mst and Grinnz on irc.perl.org #perl 2020-06-18
108 24 deep_set(\%this_object, $object, (map { lc } (@subscripts)), $value);
109 } else {
110 30 $this_object{lc($object)} = $value;
111 }
112 }
113 }
114  
115 ################
116 # Finalization
117 ################
118  
119 3 ▶ if (! $this_object{intro_year} && ! $this_object{retire_year}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $this_object{'intro_year'} || $this_object{'retire_year'}) { } 0 3 3
Condition33%1/3
$this_object{'intro_year'} || $this_object{'retire_year'}
l!l&&r!l&&!r
300
MC/DC0%0/2
$this_object{'intro_year'} || $this_object{'retire_year'}
$this_object{'intro_year'} $this_object{'retire_year'}
Truth table33%1/3
A || B
A= $this_object{'intro_year'}B= $this_object{'retire_year'}
ABresult
1X1
011
000
120 0 $this_object{_is_permanent} = 1;
121 0 $this_object{_sort_key} = '0000';
122 } else {
123 3 ▶ $this_object{intro_year} ||= 1000;
Condition50%1/2
$this_object{"intro_year"} ||= 1000
l!l
30
MC/DC0%0/1
$this_object{"intro_year"} ||= 1000
$this_object{"intro_year"}
Truth table50%1/2
A
A= $this_object{"intro_year"}
Aresult
11
00
124 3 ▶ $this_object{intro_month} ||= 1;
Condition50%1/2
$this_object{"intro_month"} ||= 1
l!l
03
MC/DC0%0/1
$this_object{"intro_month"} ||= 1
$this_object{"intro_month"}
Truth table50%1/2
A
A= $this_object{"intro_month"}
Aresult
11
00
125 3 ▶ $this_object{retire_year} ||= 2999;
Condition50%1/2
$this_object{"retire_year"} ||= 2999
l!l
30
MC/DC0%0/1
$this_object{"retire_year"} ||= 2999
$this_object{"retire_year"}
Truth table50%1/2
A
A= $this_object{"retire_year"}
Aresult
11
00
126 3 ▶ $this_object{retire_month} ||= 12;
Condition50%1/2
$this_object{"retire_month"} ||= 12
l!l
03
MC/DC0%0/1
$this_object{"retire_month"} ||= 12
$this_object{"retire_month"}
Truth table50%1/2
A
A= $this_object{"retire_month"}
Aresult
11
00
127 3 $this_object{_is_internal} = $this_object{intro_year} < 100; # Internal object
128  
129 # Permit second-level sorting for objects with equal introductory times
130 3 my $power = $this_object{'engine_type'};
131 3 ▶ $power = '~~~' if (!length($power)); # sort last
Branch: 1 branch
BranchTrueFalseTotal
unless length $power 3 0 3
132  
133 $this_object{_sort_key} = sprintf("%4d.%02d %s %4d.%02d",
134 $this_object{'intro_year'}, $this_object{'intro_month'},
135 $power,
136 3 $this_object{'retire_year'}, $this_object{'retire_month'});
137 }
138  
139 ###### OBSOLETE
140 # # Abbreviate loquacious names
141 # $this_object{_short_name} = $this_object{'name'} // '(none)';
142 # if (length($this_object{_short_name}) > 30) {
143 # $this_object{_short_name} =~ s/-([^-]{3})[^-]+/-$1/g;
144 # }
145  
146 # en-passant spelling correction
147 3 ▶ $this_object{max_length} //= delete $this_object{max_lenght} if defined $this_object{max_lenght};
Branch: 1 branch
BranchTrueFalseTotal
if defined $this_object{"max_lenght"} 0 3 3
Condition0%0/3
$this_object{"max_length"} //= delete $this_object{"max_lenght"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$this_object{"max_length"} //= delete $this_object{"max_lenght"}
$this_object{"max_length"} delete $this_object{"max_lenght"}
Truth table0%0/3
A //= B
A= $this_object{"max_length"}B= delete $this_object{"max_lenght"}
ABresult
1X1
011
000
148  
149 3 ▶ if (exists $this_object{intro_year}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this_object{"intro_year"}) 3 0 3
150 3 foreach my $event (qw[intro retire]) {
151 6 foreach my $period (qw[month year]) {
152 12 my $setit = $event . '_' . $period;
153 12 $self->$setit (delete $this_object{$setit});
154 }
155 }
156 }
157  
158 ################
159 # TODO: Suppress trailing zero dimensions in image hashes/arrays.
160 ################
161  
162 ################
163 # Copy values into returned (self) object
164 ################
165  
166 3 foreach my $k (keys %this_object) {
167 42 $self->{$k} = $this_object{$k};
168 }
169  
170 3 ▶ return defined $this_object{obj} ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $this_object{'obj'} ? : 3 0 3
171 }
172  
173 ################
174  
175 23 ▶sub intro ($self) { return $self->_intro; }
Subroutine intro: called CC=1 SCAR=0.0
Pod documented
176 22 ▶sub retire ($self) { return $self->_retire; }
Subroutine retire: called CC=1 SCAR=0.0
Pod documented
177  
178 7 ▶sub intro_year ($self, $value = undef) {
Subroutine intro_year: called CC=5 SCAR=16.2
Pod undocumented
179 7 ▶ $self->_intro( $value * 12 + (($self->intro() // 0) % 12) ) if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 3 4 7
Condition50%1/2
$self->intro // 0
l!l
30
MC/DC0%0/1
$self->intro // 0
$self->intro
Truth table50%1/2
A
A= $self->intro
Aresult
11
00
180 7 ▶ return defined $self->intro() ? int($self->intro() / 12) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->intro ? : 4 3 7
181 }
182  
183 4 ▶sub intro_month ($self, $value = undef) {
Subroutine intro_month: called CC=5 SCAR=16.6
Pod undocumented
184 4 ▶ $self->_intro( (($self->intro_year() // 0) * 12) + $value - 1) if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 3 1 4
Condition50%1/2
$self->intro_year // 0
l!l
03
MC/DC0%0/1
$self->intro_year // 0
$self->intro_year
Truth table50%1/2
A
A= $self->intro_year
Aresult
11
00
185 4 ▶ return defined $self->intro() ? ($self->intro() % 12) + 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->intro ? : 4 0 4
186 }
187  
188 7 ▶sub retire_year ($self, $value = undef) {
Subroutine retire_year: called CC=5 SCAR=16.2
Pod undocumented
189 7 ▶ $self->_retire( $value * 12 + (($self->retire() // 0) % 12) ) if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 3 4 7
Condition50%1/2
$self->retire // 0
l!l
30
MC/DC0%0/1
$self->retire // 0
$self->retire
Truth table50%1/2
A
A= $self->retire
Aresult
11
00
190 7 ▶ return defined $self->retire() ? int($self->retire() / 12) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->retire ? : 4 3 7
191 }
192  
193 4 ▶sub retire_month ($self, $value = undef) {
Subroutine retire_month: called CC=5 SCAR=16.6
Pod undocumented
194 4 ▶ $self->_retire( (($self->retire_year() // 0) * 12) + $value - 1) if defined $value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 3 1 4
Condition50%1/2
$self->retire_year // 0
l!l
03
MC/DC0%0/1
$self->retire_year // 0
$self->retire_year
Truth table50%1/2
A
A= $self->retire_year
Aresult
11
00
195 4 ▶ return defined $self->retire() ? ($self->retire() % 12) + 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->retire ? : 4 0 4
196 }
197  
198 ################
199  
200 0 ▶sub waytype_text ($self) {
Subroutine waytype_text: not called CC=3 SCAR=24.8
Pod documented
201 # Return a standardized, shorter version of the waytype
202 0 my $waytype = $self->{'waytype'};
203 0 ▶ if (defined $waytype) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $waytype) 0 0 0
204 0 $waytype =~ s/_track//;
205 0 $waytype =~ s/track/train/;
206 0 $waytype =~ s/water/ship/;
207 0 $waytype =~ s/narrowgauge/narrow/;
208 }
209 0 ▶ return $waytype // '';
Condition0%0/2
$waytype // ""
l!l
00
MC/DC0%0/1
$waytype // ""
$waytype
Truth table0%0/2
A
A= $waytype
Aresult
11
00
210 }
211  
212 0 ▶sub payload_text ($self) {
Subroutine payload_text: not called CC=4 SCAR=30.0
Pod documented
213 # Return a standardized, shorter version of the capacities (from the payload)
214 0 my $capacity;
215 0 ▶ if ( defined $self->{payload} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"payload"}) 0 0 0
216 0 ▶ if ( ref $self->{payload} eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'payload'} eq 'HASH') { } 0 0 0
217 0 $capacity = join(',', $self->{payload}->@{ sort keys %{$self->{payload}} } );
218 } else {
219 0 $capacity = sprintf("%3du", $self->{payload});
220 }
221 }
222 0 ▶ return $capacity // '--';
Condition0%0/2
$capacity // "--"
l!l
00
MC/DC0%0/1
$capacity // "--"
$capacity
Truth table0%0/2
A
A= $capacity
Aresult
11
00
223 }
224  
225 ################
226  
227 2 ▶sub comments ($self) {
Subroutine comments: called CC=1 SCAR=0.0
Pod undocumented
228 2 return $self->{_comments};
229 }
230  
231 37 ▶sub deep_print ($self, $attribute, @keys) {
Subroutine deep_print: called CC=13 SCAR=27.2
Pod undocumented
232 37 my $value = deep_get($self->{$attribute}, @keys);
233 37 ▶ if (ref $value eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 29 8 37
234 29 my $text;
235 29 my $has_values = [];
236 29 ▶ my $is_image = exists $value->{image} && exists $value->{x};
Condition66%2/3
exists $value->{'image'} && exists $value->{'x'}
!ll&&!rl&&r
2108
MC/DC50%1/2
exists $value->{'image'} && exists $value->{'x'}
exists $value->{'image'} exists $value->{'x'}
Truth table66%2/3
A && B
A= exists $value->{'image'}B= exists $value->{'x'}
ABresult
0X0
100
111
237 29 foreach my $k (sort keys %{$value}) {
238 60 ▶ if ($is_image && !ref deep_get($self->{$attribute}, @keys, $k)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_image and not ref deep_get($self->{$attribute}, @keys, $k)) { } 24 36 60
Condition100%3/3
$is_image and not ref deep_get($self->{$attribute}, @keys, $k)
!ll&&!rl&&r
28824
MC/DC100%2/2
$is_image and not ref deep_get($self->{$attribute}, @keys, $k)
$is_image not ref deep_get($self->{$attribute}, @keys, $k)
Truth table100%3/3
A and not(B)
A= $is_imageB= not ref deep_get($self->{$attribute}, @keys, $k)
ABresult
0X0
100
111
239 24 push @{$has_values}, $k;
240 } else {
241 36 $text .= $self->deep_print($attribute, @keys, $k);
242 }
243 }
244 29 ▶ if (scalar @{$has_values}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$has_values;}) 8 21 29
245 # TODO: Only if this is an image!
246 my $image_spec = $value->{image} .
247 '.' . ($value->{y}//0) .
248 8 ▶ '.' . ($value->{x}//0);
Condition50%2/4
$value->{"y"} // 0
l!l
80
$value->{"x"} // 0
l!l
80
MC/DC0%0/1
$value->{"y"} // 0
$value->{"y"}
MC/DC0%0/1
$value->{"x"} // 0
$value->{"x"}
Truth table50%1/2
A
A= $value->{"y"}
Aresult
11
00
Truth table50%1/2
A
A= $value->{"x"}
Aresult
11
00
249 $image_spec .= ',' . ($value->{xoff}//0) . ',' . ($value->{yoff}//0)
250 8 ▶ if defined $value->{xoff} || $value->{yoff};
Branch: 1 branch
BranchTrueFalseTotal
if defined $value->{"xoff"} or $value->{"yoff"} 0 8 8
Condition14%1/7
defined $value->{"xoff"} or $value->{"yoff"}
l!l&&r!l&&!r
008
$value->{"xoff"} // 0
l!l
00
$value->{"yoff"} // 0
l!l
00
MC/DC0%0/2
defined $value->{"xoff"} or $value->{"yoff"}
defined $value->{"xoff"} $value->{"yoff"}
MC/DC0%0/1
$value->{"xoff"} // 0
$value->{"xoff"}
MC/DC0%0/1
$value->{"yoff"} // 0
$value->{"yoff"}
Truth table33%1/3
A or B
A= defined $value->{"xoff"}B= $value->{"yoff"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $value->{"xoff"}
Aresult
11
00
Truth table0%0/2
A
A= $value->{"yoff"}
Aresult
11
00
251 8 return $attribute . '[' . join('][', @keys) . ']=' . $image_spec . "\n";
252 }
253 21 return $text;
254 } else {
255 8 return $attribute . '[' . join('][', @keys) . ']=' . $value . "\n";
256 }
257 }
258  
259 1 ▶sub to_string ($self) {
Subroutine to_string: called CC=7 SCAR=20.8
Pod documented
260 # Preferred order to emit attributes. Any others will be emitted
261 # in random order after these.
262 1 my $emit_order = Mojo::Collection->new(qw( obj type name copyright
263 intro_year intro_month retire_year retire_month
264 waytype own_waytype engine_type chance DistributionWeight
265 needs_ground seasons climates
266 noinfo noconstruction
267 build_time level offset_left
268 enables_pax enables_post enables_ware
269 catg metric weight_per_unit value speed_bonus
270 freight payload speed topspeed cost maintenance runningcost
271 power gear height weight length sound smoke
272 loading_time
273 max_length max_height pillar_distance pillar_asymmetric system_type
274 MapColor
275 dims
276 icon cursor
277 FrontImage BackImage BackImage2
278 FreightImageType FreightImage EmptyImage
279 openimage front_openimage closedimage front_closedimage
280 ));
281 1 my %to_emit = map { ($_, $self->{$_}) } grep { $_ !~ /^_/ } keys %{$self};
282  
283 # Replace synthetic dates with external representations
284 1 ▶ if (defined $self->intro()) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->intro) 1 0 1
285 1 @to_emit{qw(intro_year intro_month retire_year retire_month)} =
286 ($self->intro_year(), $self->intro_month(), $self->retire_year(), $self->retire_month());
287 };
288  
289 1 my $text = '';
290  
291 1 ▶ foreach my $c (@{$self->comments // []}) {
Condition50%1/2
$self->comments // []
l!l
10
MC/DC0%0/1
$self->comments // []
$self->comments
Truth table50%1/2
A
A= $self->comments
Aresult
11
00
292 1 $text .= "#$c\n";
293 }
294 # Emit common attributes in a desirable order
295 63 ▶ $emit_order->each(sub { my $emit_key = lc($_); # %to_emit has keys from object, not as capitalized above
Subroutine __ANON__: called CC=3 SCAR=11.0
296 63 ▶ if (defined $to_emit{$emit_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to_emit{$emit_key}) 13 50 63
297 13 ▶ if (ref $self->{$emit_key} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$emit_key} ne 'HASH') { } 12 1 13
298 12 $text .= "$_=" . $to_emit{$emit_key} . "\n"; # simple value
299 } else {
300 1 $text .= $self->deep_print($emit_key);
301 }
302 13 delete $to_emit{$emit_key};
303 }
304 1 });
305 1 $text .= "\n";
306  
307 # Emit remaining attributes
308 1 foreach my $k (sort keys %to_emit) {
309 0 ▶ if (defined $self->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$k}) 0 0 0
310 0 ▶ if (ref $self->{$k} ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$k} ne 'HASH') { } 0 0 0
311 0 $text .= "$k=" . $self->{$k} . "\n"; # simple value
312 } else {
313 0 $text .= $self->deep_print($k);
314 }
315 }
316 }
317 1 return $text . "------\n\n";
318 }
319  
320 1 1;
321  
322 __END__
« Image.pm ↑ Summary Livery.pm »