Rest/Product.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 64 CC 5 SCAR 16.2
CC
5
Cov
0%
AUTOLOAD
12.0
error
6.0
is_serializable
6.0
CRAP 5.1
1 package Eixo::Rest::Product;
2  
3 use strict;
4 use Eixo::Base::Clase;
5 use Eixo::Rest::Client;
6 use Eixo::Rest::BaseException;
7  
8 has (api => undef);
9  
10 sub AUTOLOAD{
11 my ($self, @args) = @_;
12  
13 #
14 # Searching for meaningful verbs
15 #
16 my ($method) = our $AUTOLOAD =~ /\:\:(\w+)$/;
17  
18 if(my ($original_method) = $method =~ /(\w+)Async$/){
19
20 unless($self->can($original_method)){
21 die(ref($self) . '::UNKONW_METHOD: ' . $original_method + ' async')
22 }
23  
24 $self->api->async(
25  
26 $self,
27  
28 $original_method,
29  
30 @args,
31  
32 );
33 }
34 # else{
35  
36 # $self->api->sync(
37  
38 # $self,
39  
40 # $method,
41  
42 # @args
43 # );
44 # }
45 }
46  
47 sub DESTROY{}
48  
49 sub populate{
50 my ($self, $values) = @_;
51  
52 # debug
53 # use Data::Dumper;
54 # print "POPULANDO ".ref($self)."\n";
55 # print Dumper($values);
56 # print "\n\n";
57  
58 $self->$_($values->{$_}) foreach(keys(%$values));
59  
60 $self;
61 }
62  
63  
64  
65 sub error{
66 my ($self, $method, $reason, @args) = @_;
67  
68 if($self->can("__error")){
69 $self->__error($method, $reason, @args);
70 }
71 else{
72 Eixo::Rest::BaseException->new(
73  
74 method => $method,
75
76 reason => $reason,
77
78 args => \@args,
79  
80 )->raise();
81 }
82 }
83  
84 sub NOT_SERIALIZE{
85 return qw(api);
86 }
87  
88 sub is_serializable{
89 my ($self,$attribute) = @_;
90  
91 return undef if(grep {$attribute eq $_} $self->NOT_SERIALIZE);
92  
93 return 1;
94 }
95  
96 sub TO_JSON {
97 my $self = $_[0];
98  
99 return {map {$_ => $self->$_} grep {$self->is_serializable($_)} keys(%$self)};
100 }
101  
102 1;