File Coverage

lib/Data/Pokemon/Go/Skill.pm
Criterion Covered Total %
statement 54 62 87.1
branch 13 24 54.1
condition 5 6 83.3
subroutine 15 16 93.7
pod 0 9 0.0
total 87 117 74.3


line stmt bran cond sub pod time code
1             package Data::Pokemon::Go::Skill;
2 7     7   58905 use 5.008001;
  7         30  
3 7     7   35 use utf8;
  7         12  
  7         46  
4              
5 7     7   603 use Moose;
  7         380566  
  7         45  
6 7     7   45790 use Moose::Util::TypeConstraints;
  7         13  
  7         59  
7 7     7   15174 use YAML::XS;
  7         2309  
  7         413  
8 7     7   361 use File::Share 'dist_dir';
  7         17471  
  7         2470  
9             my $dir = dist_dir('Data-Pokemon-Go');
10              
11             with 'Data::Pokemon::Go::Role::Types';
12              
13             my $data = YAML::XS::LoadFile("$dir/Skill.yaml");
14             map{ $data->{$_}{name} = $_ } keys %$data;
15             our @All = map{ $_->{name} } sort{ $a->{type} cmp $b->{type} } values %$data;
16              
17             enum 'SkillName' => \@All;
18             has name => ( is => 'rw', isa => 'SkillName' );
19              
20             has own_type => ( is => 'rw', isa => 'ArrayRef[Type]' );
21              
22             around 'types' => sub {
23             my $orig = shift;
24             my $self = shift;
25             my $name = $self->name();
26             my $type = $data->{$name}{type};
27             die "Type may be invalid: $type" unless $type;
28             die "Type may be invalid: $type" unless $name eq 'めざめるパワー' or grep{ $type eq $_ } @Data::Pokemon::Go::Role::Types::All;
29             return $self->$orig($type) unless $name eq 'めざめるパワー';
30             return 'ランダム';
31             };
32              
33             __PACKAGE__->meta->make_immutable;
34 7     7   78 no Moose;
  7         14  
  7         57  
35              
36             sub exists {
37 166     166 0 89612 my $self = shift;
38 166         203 my $name = shift;
39 166         377 return CORE::exists $data->{$name};
40             }
41              
42             sub strength {
43 830     830 0 889 my $self = shift;
44 830         13621 my $name = $self->name();
45 830         1594 my $num = $data->{$name}{power};
46 830 50       1803 die "'power' may be invalid: $num" unless $num =~ /^\d{1,3}$/;
47 830 50       827 $num *= 1.2 if grep{ $_ eq $self->types() } @{ $self->own_type() || [] };
  0 50       0  
  830         13095  
48 830         2121 return $num;
49             }
50              
51             sub motion {
52 1442     1442 0 1514 my $self = shift;
53 1442         21980 my $name = $self->name();
54 1442         1813 my $num = $data->{$name}{motion};
55 1442 50       2811 die "'motion' may be invalid: $num" unless $num =~ /^\d{3,4}$/;
56 1442   50     3784 return $num || 0.00;
57             }
58              
59             sub gauges {
60 1104     1104 0 1237 my $self = shift;
61 1104         20605 my $name = $self->name();
62 1104   100     2590 my $num = $data->{$name}{gauges} || 0;
63 1104 50       2897 die "'gauges' may be invalid: $num" unless $num =~ /^(:?0|1|2|3)$/;
64 1104         2544 return $num;
65             }
66              
67             sub energy {
68 569     569 0 644 my $self = shift;
69 569         9495 my $name = $self->name();
70 569   100     1908 return $data->{$name}{'energy'} || 0;
71             }
72              
73             sub EPS {
74 223     223 0 357 my $self = shift;
75 223 100       288 return 0.00 unless $self->energy;
76 114         185 my $eps = int( $self->energy / $self->motion * 100000 + 0.5 ) / 100;
77 114         453 return sprintf('%2d.%02d', int $eps, $eps % 1 );
78             }
79              
80             sub DPS {
81 166     166 0 211 my $self = shift;
82 166 100       240 my $dps = $self->gauges()?
83             int( $self->strength() / ( $self->motion() / 1000 + 1 ) * 100 + 0.5 ):
84             int( $self->strength() / ( $self->motion() / 1000 ) * 100 + 0.5 );
85 166         1021 return sprintf('%2d.%02d', int $dps / 100 , $dps % 100 );
86             }
87              
88             sub point {
89 498     498 0 772 my $self = shift;
90 498 100       647 my $point = $self->gauges()?
91             ( $self->strength * 1000 - $self->motion ) / ( $self->motion + 1000 ) * 100:
92             ( ( $self->strength + $self->energy ) / 2 * 1000 - $self->motion )/ $self->motion * 100;
93 498 100       3111 return sprintf('%2d.%02d', int $point / 100, $point % 100 ) if $point > 0;
94 3         11 return '0.00';
95             }
96              
97             sub as_string {
98 0     0 0   my $self = shift;
99 0           my $better = '';
100 0 0         $better = '(タイプ一致)' if grep{ $_ eq $self->type() } @{ $self->own_type() || [] };
  0 0          
  0            
101 0 0         my $str = $self->gauges()?
102             sprintf("%s(%s) 攻撃力:%.2f DPS:%.2f ゲージ数:%d 評価:%.2f%s\n",
103             $self->name,
104             $self->types,
105             $self->strength,
106             $self->DPS(),
107             $self->gauges(),
108             $self->point(),
109             $better,
110             ):
111             sprintf("%s(%s) 攻撃力:%.2f DPS:%.2f EPS:%.2f 評価:%.2f%s\n",
112             $self->name,
113             $self->types,
114             $self->strength,
115             $self->DPS(),
116             $self->EPS(),
117             $self->point(),
118             $better,
119             );
120              
121 0           return $str;
122             }
123              
124              
125             1;
126             __END__
127              
128             =encoding utf-8
129              
130             =head1 NAME
131              
132             Data::Pokemon::Go::Relaition - It's new $module
133              
134             =head1 SYNOPSIS
135              
136             use Data::Pokemon::Go::Relaition;
137              
138             =head1 DESCRIPTION
139              
140             Data::Pokemon::Go::Relaition is ...
141              
142             =head1 LICENSE
143              
144             Copyright (C) Yuki Yoshida.
145              
146             This library is free software; you can redistribute it and/or modify
147             it under the same terms as Perl itself.
148              
149             =head1 AUTHOR
150              
151             Yuki Yoshida E<lt>worthmine@gmail.comE<gt>
152              
153             =cut
154