PrettyCure/Girl.pm

filter: Statementstmt 92.7% 90 / 97 Branchbran 86.6% 26 / 30 Conditioncond 100% 16 / 16 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 40 / 40 Podpod 29.6% 8 / 27 totaltotal 86.2% 188 / 218 CC 30 SCAR 14.1
CC
30
Cov
92%
image
19.4
to_boolean
6.0
data_name
4.2
CRAP 4.1
« PrettyCure/Team.pm ↑ Summary PrettyCure/Girl/CurePeace.pm »
1 27 ▶use v5.44;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 27 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 27 ▶use experimental qw(class builtin keyword_any signature_named_parameters);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # A girl. Each girl is a class of her own, Acme::PrettyCure::Girl::<name>, with this class as its base;
6 # what she is (her names, what she says, her color) is the data of Acme::PrettyCure::Data for that
7 # name. How she transforms with her buddies is Acme::PrettyCure::Team.
8 class Acme::PrettyCure::Girl;
9  
10 26 ▶use mro;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 25 ▶use Encode qw(encode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 25 ▶use Time::Piece ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 25 ▶use Acme::PrettyCure::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 25 ▶use Acme::PrettyCure::Team;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 25 ▶use Acme::PrettyCure::Fairy;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # The data of the girl of this class: the girl of the nearest class under Acme::PrettyCure::Girl:: that
18 # is in the data. __CLASS__ is the class of the object being made, so this is also right for a subclass
19 # of a girl: CureBright of CureBloom, or a class of a user's own outside this namespace.
20 25 field $data = data_of(__CLASS__);
21  
22 field $is_precure :param = false;
23  
24 791 ▶ADJUST {
Subroutine __ANON__: called CC=1 SCAR=0.0
25 791 $is_precure = to_boolean($is_precure);
26 }
27  
28 791 ▶sub data_of ($class) { Acme::PrettyCure::Data->girl(data_name($class)) }
Subroutine data_of: called CC=1 SCAR=0.0
Pod undocumented
29  
30 # The name of the girl in the data for a class: the nearest class under Acme::PrettyCure::Girl:: that is
31 # in the data.
32 817 ▶sub data_name ($class) {
Subroutine data_name: called CC=4 SCAR=14.3
Pod undocumented
33 817 for my $c (mro::get_linear_isa($class)->@*) {
34 818 my $name = $c =~ s/\AAcme::PrettyCure::Girl:://r;
35 818 ▶ next if $name eq $c;
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $c 1 817 818
36 817 ▶ return $name if Acme::PrettyCure::Data->girl($name);
Branch: 1 branch
BranchTrueFalseTotal
if "Acme::PrettyCure::Data"->girl($name) 817 0 817
37 }
38 0 die "$class is not a girl of Acme::PrettyCure::Data\n";
39 }
40  
41 # A boolean of `true`/`false`, or 0 or 1, as `true` or `false`; anything else dies.
42 847 ▶sub to_boolean ($v) {
Subroutine to_boolean: called CC=6 SCAR=17.9
Pod undocumented
43 847 ▶ die(($v // 'undef') . " is not a boolean\n")
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::is_bool($v) or defined $v and $v =~ /\A[01]\z/u 5 842 847
Condition100%8/8
builtin::is_bool($v) or defined $v and $v =~ /\A[01]\z/u
l!l&&r!l&&!r
83575
defined $v and $v =~ /\A[01]\z/u
!ll&&!rl&&r
147
$v // "undef"
l!l
41
MC/DC100%3/3
builtin::is_bool($v) or defined $v and $v =~ /\A[01]\z/u
builtin::is_bool($v) defined $v $v =~ /\A[01]\z/u
MC/DC100%1/1
$v // "undef"
$v
Truth table100%4/4
A or B and C
A= builtin::is_bool($v)B= defined $vC= $v =~ /\A[01]\z/u
ABCresult
1XX1
0111
00X0
0100
Truth table100%2/2
A
A= $v
Aresult
11
00
44 unless builtin::is_bool($v) || (defined $v && $v =~ /\A[01]\z/);
45 842 ▶ return $v ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$v ? : 32 810 842
46 }
47  
48 171 ▶method human_name { $data->{human_name} }
Subroutine human_name: called CC=1 SCAR=0.0
Pod undocumented
49 227 ▶method precure_name { $data->{precure_name} }
Subroutine precure_name: called CC=1 SCAR=0.0
Pod undocumented
50 39 ▶method age { $data->{age} }
Subroutine age: called CC=1 SCAR=0.0
Pod undocumented
51 39 ▶method blood_type { $data->{blood_type} }
Subroutine blood_type: called CC=1 SCAR=0.0
Pod undocumented
52 541 ▶method color { $data->{color} }
Subroutine color: called CC=1 SCAR=0.0
Pod undocumented
53 43 ▶method fairy_name { $data->{fairy_name} }
Subroutine fairy_name: called CC=1 SCAR=0.0
Pod undocumented
54 59 ▶method message { $data->{message} }
Subroutine message: called CC=1 SCAR=0.0
Pod undocumented
55 40 ▶method image_url { $data->{image_url} // '' }
Subroutine image_url: called CC=2 SCAR=6.9
Pod undocumented
Condition100%2/2
$data->{"image_url"} // ""
l!l
364
MC/DC100%1/1
$data->{"image_url"} // ""
$data->{"image_url"}
Truth table100%2/2
A
A= $data->{"image_url"}
Aresult
11
00
56  
57 46 ▶method birthday {
Subroutine birthday: called CC=2 SCAR=6.9
Pod undocumented
58 46 ▶ my $day = $data->{birthday} // return;
Condition100%2/2
$data->{"birthday"} // (return)
l!l
1630
MC/DC100%1/1
$data->{"birthday"} // (return)
$data->{"birthday"}
Truth table100%2/2
A
A= $data->{"birthday"}
Aresult
11
00
59 16 return Time::Piece->strptime($day, '%Y-%m-%d');
60 }
61  
62 # What she says when she transforms, a line each. In scalar context, the last line (as the subs that
63 # returned a list of strings did).
64 431 ▶method challenge {
Subroutine challenge: called CC=2 SCAR=6.9
Pod undocumented
65 431 my @lines = $data->{challenge}->@*;
66 431 ▶ return wantarray ? @lines : $lines[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 276 155 431
67 }
68  
69 # Who she transforms with, and how.
70 # The girl she is another form of, at the root of `isa` (or herself): CureBloom for CureBright.
71 26 ▶my method base_form {
Subroutine base_form: called CC=2 SCAR=6.9
72 26 my $name = data_name(ref $self);
73 26 ▶ while (my $isa = Acme::PrettyCure::Data->girl($name)->{isa}) { $name = $isa }
Branch: 1 branch
BranchTrueFalseTotal
if (my $isa = "Acme::PrettyCure::Data"->girl($name)->{"isa"}) 5 26 31
74 26 return $name;
75 }
76  
77 # Her partner fairy (Acme::PrettyCure::Fairy), or none.
78 4 ▶method fairy {
Subroutine fairy: called CC=2 SCAR=6.9
Pod documented
79 4 ▶ my $name = $data->{fairy} // return;
Condition100%2/2
$data->{"fairy"} // (return)
l!l
31
MC/DC100%1/1
$data->{"fairy"} // (return)
$data->{"fairy"}
Truth table100%2/2
A
A= $data->{"fairy"}
Aresult
11
00
80 3 return Acme::PrettyCure::Fairy->new(name => $name, partner => $self->&base_form);
81 }
82  
83 # Her forms: herself as first made, then her other forms (`forms`), by the names of their classes
84 # (Acme::PrettyCure::Girl::<name>).
85 23 ▶method forms { $self->&base_form, ($data->{forms} // [])->@* }
Subroutine forms: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$data->{"forms"} // []
l!l
212
MC/DC100%1/1
$data->{"forms"} // []
$data->{"forms"}
Truth table100%2/2
A
A= $data->{"forms"}
Aresult
11
00
86  
87 # She in another of her forms (a name of `forms`), transformed if she is.
88 12 ▶method form ($name) {
Subroutine form: called CC=2 SCAR=6.9
Pod documented
89 die "$name is not a form of " . $self->human_name . "\n"
90 12 ▶ unless any { $_ eq $name } $self->forms;
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::any {$_ eq $name;} $self->forms 1 11 12
91 11 my $class = "Acme::PrettyCure::Girl::$name";
92 11 ▶ builtin::load_module($class);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
93 11 return $class->new(is_precure => $is_precure);
94 }
95  
96 # Her stronger form: the first of her other forms.
97 8 ▶method powerup {
Subroutine powerup: called CC=2 SCAR=6.9
Pod documented
98 8 my (undef, $form) = $self->forms;
99 8 ▶ die $self->human_name . " has no other form\n" unless defined $form;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form 1 7 8
100 7 return $self->form($form);
101 }
102  
103 256 ▶method series_name { $data->{series} }
Subroutine series_name: called CC=1 SCAR=0.0
Pod undocumented
104 270 ▶method transform_style { $data->{transform} }
Subroutine transform_style: called CC=1 SCAR=0.0
Pod undocumented
105 270 ▶method needs { $data->{needs} }
Subroutine needs: called CC=1 SCAR=0.0
Pod undocumented
106 60 ▶method call { $data->{call} }
Subroutine call: called CC=1 SCAR=0.0
Pod undocumented
107  
108 # Whether she is transformed. Given a value, sets it: a boolean, or 0 or 1.
109 411 ▶method is_precure (@value) {
Subroutine is_precure: called CC=2 SCAR=6.9
Pod documented
110 411 ▶ $is_precure = to_boolean($value[0]) if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 29 382 411
111 409 return $is_precure;
112 }
113  
114 256 ▶method name { $is_precure ? $self->precure_name : $self->human_name }
Subroutine name: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$is_precure ? : 160 96 256
115  
116 # Prints a line in her color.
117 502 ▶method say ($text) {
Subroutine say: called CC=3 SCAR=11.0
Pod undocumented
118 502 my $color = $self->color;
119 502 ▶ print "\e[38;5;${color}m" if defined $color;
Branch: 1 branch
BranchTrueFalseTotal
if defined $color 404 98 502
120 502 print encode_utf8("$text\n");
121 502 ▶ print "\e[0m" if defined $color;
Branch: 1 branch
BranchTrueFalseTotal
if defined $color 404 98 502
122 }
123  
124 # Transforms with the buddies, as her series does (Acme::PrettyCure::Team).
125 270 ▶method transform (@buddies) {
Subroutine transform: called CC=1 SCAR=0.0
Pod documented
126 270 return Acme::PrettyCure::Team->for_girl($self)->transform($self, @buddies);
127 }
128  
129 # Transforms her alone, without her team: what each girl says when she transforms. Called by
130 # Acme::PrettyCure::Team.
131 238 ▶method transform_alone {
Subroutine transform_alone: called CC=3 SCAR=11.0
Pod undocumented
132 238 ▶ die "already transformed\n" if $is_precure;
Branch: 1 branch
BranchTrueFalseTotal
if $is_precure 1 237 238
133 237 $is_precure = true;
134 237 $self->say($_) for $self->challenge;
135 237 return $self;
136 }
137  
138 # Shows her image in the terminal (Acme::PrettyCure::Image::Terminal), fetched from the official site
139 # the first time and kept in the cache after that (Acme::PrettyCure::Image).
140 #
141 # $girl->image; # the best way the terminal has, 40 cells wide
142 # $girl->image(protocol => 'halfblock', width => 20);
143 1 ▶method image (
Subroutine image: called CC=8 SCAR=29.6
Pod documented
144 1 :$protocol = 'auto',
145 1 :$width = 40,
146 1 :$fh = \*STDOUT,
147 1 :$http = undef,
148 :$cache_dir = undef
149 )
150 1 {
151 1 ▶ my $url = $self->image_url or die $self->human_name . " has no image\n";
Branch: 1 branch
BranchTrueFalseTotal
my $url = $self->image_url or die $self->human_name . " has no image\n" 0 1 1
152 0 require Acme::PrettyCure::Image;
153 0 require Acme::PrettyCure::Image::Terminal;
154 my $image = Acme::PrettyCure::Image->new(
155 url => $url,
156 http => $http,
157 crop => $data->{image_crop},
158 0 ▶ defined $cache_dir ? (cache_dir => $cache_dir) : (),
Branch: 1 branch
BranchTrueFalseTotal
defined $cache_dir ? : 0 0 0
159 );
160 0 print {$fh} encode_utf8(
161 Acme::PrettyCure::Image::Terminal->render(
162 $image->imager,
163 protocol => $protocol,
164 width => $width
165 )
166 );
167 0 return $self;
168 }
169  
170  
171 __END__
« PrettyCure/Team.pm ↑ Summary PrettyCure/Girl/CurePeace.pm »