Go/Pokemon.pm

filter: Statementstmt 85.5% 124 / 145 Branchbran 66.6% 20 / 30 Conditioncond 84.6% 11 / 13 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 90.6% 29 / 32 Podpod 0.0% 0 / 20 totaltotal 76.5% 189 / 247 CC 22 SCAR 10.4
CC
22
Cov
82%
exists
7.0
skill
6.0
special
6.0
CRAP 2.8
« Go/Skill.pm ↑ Summary Go/Relation.pm »
1 package Data::Pokemon::Go::Pokemon;
2 6 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 our @EXPORT_OK = qw( $All @List @Types );
7  
8 6 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 enum 'Countries' => [qw( en ja ca fr )];
12 6 has lang => ( is => 'ro', isa => 'Countries', required => 1, default => 'ja' );
13  
14 6 ▶use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use File::Share 'dist_dir';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶my $dir = $ENV{'USER'} eq 'yuki.yoshida'? 'share': dist_dir('Data-Pokemon-Go');
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'USER'} eq 'yuki.yoshida' ? : 0 6 6
17  
18 6 ▶use Data::Pokemon::Go::Relation;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 our @Types = @Data::Pokemon::Go::Role::Types::All;
20 6 ▶use Data::Pokemon::Go::Skill;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 6 my $skill = Data::Pokemon::Go::Skill->new();
23  
24 6 our $All = {};
25 6 our @List = ();
26 6 foreach my $region (qw|Kanto Johto Hoenn Sinnoh Unova Alola Galar|){
27 42 my $data = YAML::XS::LoadFile("$dir/$region.yaml");
28 map{
29 42 my $fullname = get_fullname( bless( { lang => 'ja' }, __PACKAGE__ ), $_ );
30 4128 push @List, $fullname;
31 4128 $All->{ $fullname } = $_;
32 } @$data;
33 }
34  
35 6 enum 'PokemonName' => \@List;
36 6 has name => ( is => 'rw', isa => 'PokemonName' );
37 21701 ▶before 'name' => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
38 21701 my $self = shift;
39 21701 my $name = shift;
40 21701 ▶ my $form = shift || '';
Condition50%1/2
shift() || ''
l!l
021701
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
41 21701 ▶ if ( defined $name and $name =~ /^(\w+)\((\w+)\)$/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and $name =~ /^(\w+)\((\w+)\)$/) 240 21461 21701
Condition100%3/3
defined $name and $name =~ /^(\w+)\((\w+)\)$/
!ll&&!rl&&r
188812580240
MC/DC100%2/2
defined $name and $name =~ /^(\w+)\((\w+)\)$/
defined $name $name =~ /^(\w+)\((\w+)\)$/
Truth table100%3/3
A and B
A= defined $nameB= $name =~ /^(\w+)\((\w+)\)$/
ABresult
0X0
100
111
42 240 $name = $1;
43 240 $form = $2;
44 }
45
46 # croak "unvalid name: $name($form)"
47 # if defined $name and defined $form and not $self->exists($name) and not $self->exists( $name, $form );
48 6 };
49  
50 6 __PACKAGE__->meta->make_immutable;
51 6 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 2136 ▶sub exists {
Subroutine exists: called CC=7 SCAR=19.5
Pod undocumented
54 2136 my $self = shift;
55 2136 my $name = shift;
56 2136 ▶ my $form = shift || undef;
Condition100%2/2
shift() || undef
l!l
22134
MC/DC100%1/1
shift() || undef
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
57  
58 2136 ▶ if ( not defined $form and defined $name and $name =~ /^(\w+)\((\w+)\)$/ ){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $form and defined $name and $name =~ /^(\w+)\((\w+)\)$/) 193 1943 2136
Condition83%5/6
not defined $form and defined $name and $name =~ /^(\w+)\((\w+)\)$/
!ll&&!rl&&r
21941193
not defined $form and defined $name
!ll&&!rl&&r
202134
MC/DC66%2/3
not defined $form and defined $name and $name =~ /^(\w+)\((\w+)\)$/
not defined $form defined $name $name =~ /^(\w+)\((\w+)\)$/
Truth table75%3/4
not(A) and B and C
A= not defined $formB= defined $nameC= $name =~ /^(\w+)\((\w+)\)$/
ABCresult
0XX0
10X0
1100
1111
59 193 return CORE::exists $All->{"$1($2)"};
60 }
61 1943 my $fullname = $All->{$name}{'Name'}{$self->lang()};
62 1943 ▶ return 0 unless defined $fullname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fullname 0 1943 1943
63 1943 ▶ return 1 unless $form;
Branch: 1 branch
BranchTrueFalseTotal
unless $form 1941 2 1943
64 2 $fullname .= "($form)";
65 2 return CORE::exists $All->{$fullname};
66 }
67  
68 2131 ▶sub id {
Subroutine id: called CC=2 SCAR=7.0
Pod undocumented
69 2131 my $self = shift;
70 2131 my $name = $self->name();
71 2131 my $id = $All->{$name}{ID};
72 2131 ▶ carp "'ID' may be invalid: $id" unless $id =~ /^\d{3}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $id =~ /^\d{3}$/ 0 2131 2131
73 2131 return $id;
74 }
75  
76 6259 ▶sub types {
Subroutine types: called CC=2 SCAR=7.0
Pod undocumented
77 6259 my $self = shift;
78 6259 my $name = $self->name();
79 6259 my $typesref = $All->{$name}{Types};
80 6259 ▶ carp "'Types' may be invalid: $typesref" unless ref $typesref eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $typesref eq "ARRAY" 0 6259 6259
81 6259 return $typesref;
82 }
83  
84 0 ▶sub skill {
Subroutine skill: not called CC=2 SCAR=17.9
Pod undocumented
85 0 my $self = shift;
86 0 my $name = $self->name();
87 0 my $ref = $All->{$name}{Skill};
88 0 my @skill;
89 0 foreach my $name (@$ref) {
90 0 $skill->name($name);
91 0 $skill->own_type( $self->types() );
92 0 push @skill, $skill->as_string();
93 }
94 0 return @skill;
95 }
96  
97 0 ▶sub special {
Subroutine special: not called CC=2 SCAR=17.9
Pod undocumented
98 0 my $self = shift;
99 0 my $name = $self->name();
100 0 my $ref = $All->{$name}{Special};
101 0 my @skill;
102 0 foreach my $name (@$ref) {
103 0 $skill->name($name);
104 0 $skill->own_type( $self->types() );
105 0 push @skill, $skill->as_string();
106 }
107 0 return @skill;
108 }
109  
110 688 ▶sub effective {
Subroutine effective: called CC=1 SCAR=0.0
Pod undocumented
111 688 my $self = shift;
112 688 return Data::Pokemon::Go::Relation->new( types => $self->types() )->effective();
113 };
114  
115 688 ▶sub invalid {
Subroutine invalid: called CC=1 SCAR=0.0
Pod undocumented
116 688 my $self = shift;
117 688 return Data::Pokemon::Go::Relation->new( types => $self->types() )->invalid();
118 };
119  
120 688 ▶sub advantage {
Subroutine advantage: called CC=1 SCAR=0.0
Pod undocumented
121 688 my $self = shift;
122 688 return Data::Pokemon::Go::Relation->new( types => $self->types() )->advantage();
123 };
124  
125 688 ▶sub disadvantage {
Subroutine disadvantage: called CC=1 SCAR=0.0
Pod undocumented
126 688 my $self = shift;
127 688 return Data::Pokemon::Go::Relation->new( types => $self->types() )->disadvantage();
128 };
129  
130 1376 ▶sub recommended {
Subroutine recommended: called CC=1 SCAR=0.0
Pod undocumented
131 1376 my $self = shift;
132 1376 return Data::Pokemon::Go::Relation->new( types => $self->types() )->recommended();
133 };
134  
135 1930 ▶sub stamina {
Subroutine stamina: called CC=2 SCAR=7.0
Pod undocumented
136 1930 my $self = shift;
137 1930 my $name = $self->name();
138 1930 ▶ croak "'Stamina' is undefined for $name" unless exists $All->{$name}{'Stamina'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Data::Pokemon::Go::Pokemon::All->{$name}{"Stamina"} 0 1930 1930
139 1930 return $All->{$name}{Stamina};
140 }
141  
142 1930 ▶sub attack {
Subroutine attack: called CC=2 SCAR=7.0
Pod undocumented
143 1930 my $self = shift;
144 1930 my $name = $self->name();
145 1930 ▶ croak "'Attack' is undefined for $name" unless exists $All->{$name}{'Attack'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Data::Pokemon::Go::Pokemon::All->{$name}{"Attack"} 0 1930 1930
146 1930 return $All->{$name}{Attack};
147 }
148  
149 1930 ▶sub defense {
Subroutine defense: called CC=2 SCAR=7.0
Pod undocumented
150 1930 my $self = shift;
151 1930 my $name = $self->name();
152 1930 ▶ croak "'Defense' is undefined for $name" unless exists $All->{$name}{'Defense'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Data::Pokemon::Go::Pokemon::All->{$name}{"Defense"} 0 1930 1930
153 1930 return $All->{$name}{Defense};
154 }
155  
156 1242 ▶sub max {
Subroutine max: called CC=3 SCAR=11.2
Pod undocumented
157 1242 my $self = shift;
158 1242 my $when = shift;
159 1242 ▶ croak "Unvalid param $when into sub max()"
Branch: 1 branch
BranchTrueFalseTotal
unless $when =~ /(:?Boosted|Hatched|Grown)/ 0 1242 1242
160 unless $when =~ /(:?Boosted|Hatched|Grown)/;
161  
162 1242 my $name = $self->name();
163 1242 ▶ croak "'$when' is undefined for $name" unless exists $All->{$name}{'MAXCP'}{$when};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Data::Pokemon::Go::Pokemon::All->{$name}{"MAXCP"}{$when} 0 1242 1242
164 1242 return $All->{$name}{'MAXCP'}{$when};
165 }
166  
167 0 ▶sub isNotWild {
Subroutine isNotWild: not called CC=1 SCAR=6.9
Pod undocumented
168 0 my $self = shift;
169 0 my $name = $self->name();
170 0 return $All->{$name}{'isNotWild'};
171 }
172  
173 688 ▶sub isNotAvailable {
Subroutine isNotAvailable: called CC=1 SCAR=0.0
Pod undocumented
174 688 my $self = shift;
175 688 my $name = $self->name();
176 688 return $All->{$name}{'isNotAvailable'};
177 }
178  
179 640 ▶sub hasOtherForm {
Subroutine hasOtherForm: called CC=1 SCAR=0.0
Pod undocumented
180 640 my $self = shift;
181 640 my $name = $self->name();
182 640 return $All->{$name}{'hasOtherForm'};
183 }
184  
185 755 ▶sub hasForms {
Subroutine hasForms: called CC=2 SCAR=6.9
Pod undocumented
186 755 my $self = shift;
187 755 my $name = $self->name();
188 755 ▶ return exists $All->{$name}{'Form'}? $All->{$name}{'Form'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $Data::Pokemon::Go::Pokemon::All->{$name}{'Form'} ? : 96 659 755
189 }
190  
191 4816 ▶sub get_fullname {
Subroutine get_fullname: called CC=2 SCAR=6.9
Pod undocumented
192 4816 my $self = shift;
193 4816 my $ref = shift;
194 4816 my $fullname = $self->get_Pokemon_name($ref);
195 4816 ▶ $fullname .= '(' . $ref->{'Form'} . ')' if exists $ref->{'Form'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ref->{"Form"} 336 4480 4816
196 4816 return $fullname;
197 }
198  
199 4883 ▶sub get_Pokemon_name {
Subroutine get_Pokemon_name: called CC=2 SCAR=7.0
Pod undocumented
200 4883 my $self = shift;
201 4883 my $ref = shift;
202 4883 my $lang = $self->lang();
203 4883 ▶ croak "No name for $lang" unless exists $ref->{'Name'}{$lang};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ref->{"Name"}{$lang} 0 4883 4883
204 4883 return $ref->{'Name'}{$lang};
205 }
206  
207 6 1;
208 __END__
« Go/Skill.pm ↑ Summary Go/Relation.pm »