| 1 | package AsposePdfCloud::Object::BaseObject; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | require 5.6.0; | |||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use JSON qw(decode_json); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Module::Runtime qw(use_module); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use Log::Any qw($log); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use Date::Parse; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use DateTime; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 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 | 0 | ▶ | return decode_json(JSON->new->convert_blessed->encode( shift )); | ||||||||||||
|
Subroutine
to_hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | # used by JSON for serialization | ||||||||||||||
| 28 | sub TO_JSON { | ||||||||||||||
| 29 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
TO_JSON: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 30 | 0 | my $_data = {}; | |||||||||||||
| 31 | 0 | foreach my $_key (%{$self->get_attribute_map}) { | |||||||||||||
| 32 | 0 | ▶ | if (defined $self->{$_key}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 0 | $_data->{$self->get_attribute_map->{$_key}} = $self->{$_key}; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | } | ||||||||||||||
| 36 | 0 | return $_data; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | # from json string | ||||||||||||||
| 40 | sub from_hash { | ||||||||||||||
| 41 | 0 | ▶ | my ($self, $hash) = @_; | ||||||||||||
|
Subroutine
from_hash: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 42 | # loop through attributes and use swagger_types to deserialize the data | ||||||||||||||
| 43 | 0 | ▶ | while ( my ($_key, $_type) = each %{$self->get_swagger_types }) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 0 | ▶ | if ($_type =~ /^array\[/i) { # array | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 45 | 0 | my $_subclass = substr($_type, 6, -1); | |||||||||||||
| 46 | 0 | my @_array = (); | |||||||||||||
| 47 | 0 | foreach my $_element (@{$hash->{$self->get_attribute_map->{$_key}}}) { | |||||||||||||
| 48 | 0 | push @_array, $self->_deserialize($_subclass, $_element); | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | 0 | $self->{$_key} = \@_array; | |||||||||||||
| 51 | } elsif (defined $hash->{$_key}) { #hash(model), primitive, datetime | ||||||||||||||
| 52 | 0 | $self->{$_key} = $self->_deserialize($_type, $hash->{$_key}); | |||||||||||||
| 53 | } else { | ||||||||||||||
| 54 | 0 | $log->debugf("warning: %s not defined\n", $_key); | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | return $self; | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | # deserialize non-array data | ||||||||||||||
| 62 | sub _deserialize { | ||||||||||||||
| 63 | 0 | ▶ | my ($self, $type, $data) = @_; | ||||||||||||
|
Subroutine
_deserialize: not called CC=3 SCAR=24.8
| |||||||||||||||
| 64 | 0 | $log->debugf("deserializing %s with %s",Dumper($data), $type); | |||||||||||||
| 65 | |||||||||||||||
| 66 | 0 | ▶ | if ($type eq 'DateTime') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 67 | 0 | return DateTime->from_epoch(epoch => str2time($data)); | |||||||||||||
| 68 | } elsif ( grep( /^$type$/, ('int', 'double', 'string', 'boolean'))) { | ||||||||||||||
| 69 | 0 | return $data; | |||||||||||||
| 70 | } else { # hash(model) | ||||||||||||||
| 71 | 0 | my $_instance = use_module("AsposePdfCloud::Object::$type")->new; | |||||||||||||
| 72 | 0 | return $_instance->from_hash($data); | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 1 | 1; | |||||||||||||