File Coverage

blib/lib/WebService/Pokemon/Role/APIResource.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 32 35 91.4


line stmt bran cond sub pod time code
1             package WebService::Pokemon::Role::APIResource;
2              
3 3     3   1079 use utf8;
  3         6  
  3         12  
4 3     3   69 use strictures 2;
  3         13  
  3         70  
5 3     3   319 use namespace::clean;
  3         4  
  3         12  
6              
7 3     3   333 use Moo::Role;
  3         6  
  3         16  
8 3     3   791 use Types::Standard qw(HashRef InstanceOf);
  3         6  
  3         12  
9              
10             our $VERSION = '0.09';
11              
12              
13             has api => (
14                 isa => InstanceOf['WebService::Pokemon'],
15                 is => 'rw',
16             );
17              
18             has response => (
19                 isa => HashRef,
20                 is => 'rw',
21             );
22              
23             sub BUILD {
24 2     2 0 3170     my ($self, $args) = @_;
25              
26 2         8     foreach my $arg (keys %$args) {
27 4 50       113         $self->$arg($args->{$arg}) if (defined $args->{$arg});
28                 }
29              
30 2         54     foreach my $arg (keys %{$self->response}) {
  2         27  
31 16 50       260         if (!$self->can($arg)) {
32 16         45             $self->meta->add_attribute($arg => ( is => 'rw'));
33 16         391394             $self->$arg($self->response->{$arg});
34                     }
35                 }
36              
37 2         50     return $self;
38             }
39              
40              
41             1;
42             __END__
43