Object/BaseObject.pm untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 87 CC 6 SCAR 17.2
CC
6
Cov
0%
from_hash
12.0
_deserialize
12.0
TO_JSON
6.0
CRAP 5.6
1 package AsposeImagingCloud::Object::BaseObject;
2
3 require 5.6.0;
4 use strict;
5 use warnings;
6 use utf8;
7 use JSON qw(decode_json);
8 use Data::Dumper;
9 use Module::Runtime qw(use_module);
10 use Log::Any qw($log);
11 use Date::Parse;
12 use DateTime;
13
14
15 #
16 #
17 #
18 #NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
19 #
20
21
22 # return json string
23 sub to_hash {
24 return decode_json(JSON->new->convert_blessed->encode( shift ));
25 }
26
27 # used by JSON for serialization
28 sub TO_JSON {
29 my $self = shift;
30 my $_data = {};
31 foreach my $_key (%{$self->get_attribute_map}) {
32 if (defined $self->{$_key}) {
33 $_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
34 }
35 }
36 return $_data;
37 }
38
39 # from json string
40 sub from_hash {
41 my ($self, $hash) = @_;
42 # loop through attributes and use swagger_types to deserialize the data
43 while ( my ($_key, $_type) = each %{$self->get_swagger_types }) {
44 if ($_type =~ /^array\[/i) { # array
45 my $_subclass = substr($_type, 6, -1);
46 my @_array = ();
47 foreach my $_element (@{$hash->{$self->get_attribute_map->{$_key}}}) {
48 push @_array, $self->_deserialize($_subclass, $_element);
49 }
50 $self->{$_key} = \@_array;
51 } elsif (defined $hash->{$_key}) { #hash(model), primitive, datetime
52 $self->{$_key} = $self->_deserialize($_type, $hash->{$_key});
53 } else {
54 $log->debugf("warning: %s not defined\n", $_key);
55 }
56 }
57
58 return $self;
59 }
60
61 # deserialize non-array data
62 sub _deserialize {
63 my ($self, $type, $data) = @_;
64 $log->debugf("deserializing %s with %s",Dumper($data), $type);
65
66 if ($type eq 'DateTime') {
67 return DateTime->from_epoch(epoch => str2time($data));
68 } elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) {
69 return $data;
70 } else { # hash(model)
71 my $_instance = use_module("AsposeImagingCloud::Object::$type")->new;
72 return $_instance->from_hash($data);
73 }
74 }
75
76 1;