Object/BaseObject.pm

filter: Statementstmt 50.8% 29 / 57 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 0.0% 0 / 3 totaltotal 44.7% 38 / 85 CC 9 SCAR 24.1
CC
9
Cov
42%
from_hash
30.0
TO_JSON
12.0
_deserialize
12.0
CRAP 11.1
« ApiClient.pm ↑ Summary Object/HttpResponseMessage.pm »
1 package AsposeEmailCloud::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 0 ▶sub to_hash {
Subroutine to_hash: not called CC=1 SCAR=6.9
Pod undocumented
24 0 return decode_json(JSON->new->convert_blessed->encode( shift ));
25 }
26
27 # used by JSON for serialization
28 0 ▶sub TO_JSON {
Subroutine TO_JSON: not called CC=3 SCAR=24.8
Pod undocumented
29 0 my $self = shift;
30 0 my $_data = {};
31 0 foreach my $_key (%{$self->get_attribute_map}) {
32 0 ▶ if (defined $self->{$_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{$_key}) 0 0 0
33 0 $_data->{$self->get_attribute_map->{$_key}} = $self->{$_key};
34 }
35 }
36 0 return $_data;
37 }
38
39 # from json string
40 0 ▶sub from_hash {
Subroutine from_hash: not called CC=5 SCAR=34.0
Pod undocumented
41 0 my ($self, $hash) = @_;
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
BranchTrueFalseTotal
if (() = each %{$self->get_swagger_types;}) 0 0 0
44 0 ▶ if ($_type =~ /^array\[/i) { # array
Branch: 2 branches
BranchTrueFalseTotal
if ($_type =~ /^array\[/i) { } 0 0 0
elsif (defined $hash->{$_key}) { } 0 0 0
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 0 ▶sub _deserialize {
Subroutine _deserialize: not called CC=3 SCAR=24.8
63 0 my ($self, $type, $data) = @_;
64 0 $log->debugf("deserializing %s with %s",Dumper($data), $type);
65
66 0 ▶ if ($type eq 'DateTime') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'DateTime') { } 0 0 0
elsif (grep /^$type$/, ('int', 'double', 'string', 'boolean')) { } 0 0 0
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("AsposeEmailCloud::Object::$type")->new;
72 0 return $_instance->from_hash($data);
73 }
74 }
75
76 1 1;
« ApiClient.pm ↑ Summary Object/HttpResponseMessage.pm »