| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Asana::Role::NewFromResponse; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
1
|
|
|
1
|
|
951
|
$WWW::Asana::Role::NewFromResponse::AUTHORITY = 'cpan:GETTY'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$WWW::Asana::Role::NewFromResponse::VERSION = '0.003'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
# ABSTRACT: Role which implements new_from_response for Asana classes |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
7
|
use MooX::Role; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
11
|
1
|
|
|
1
|
|
1805
|
use DateTime::Format::ISO8601; |
|
|
1
|
|
|
|
|
484785
|
|
|
|
1
|
|
|
|
|
148
|
|
|
12
|
1
|
|
|
1
|
|
16
|
use Class::Load ':all'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1095
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new_from_response { |
|
16
|
0
|
|
|
0
|
1
|
|
my ( $class, $data ) = @_; |
|
17
|
0
|
0
|
|
|
|
|
die "First parameter to new_From_response need to be a HashRef" unless ref $data eq 'HASH'; |
|
18
|
0
|
|
|
|
|
|
my %data = %{$data}; |
|
|
0
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my %multi_mapping = ( |
|
20
|
|
|
|
|
|
|
followers => 'WWW::Asana::User', |
|
21
|
|
|
|
|
|
|
workspaces => 'WWW::Asana::Workspace', |
|
22
|
|
|
|
|
|
|
projects => 'WWW::Asana::Project', |
|
23
|
|
|
|
|
|
|
tags => 'WWW::Asana::Tag', |
|
24
|
|
|
|
|
|
|
); |
|
25
|
0
|
|
|
|
|
|
my @needs_workspace = qw( projects tags ); |
|
26
|
0
|
|
|
|
|
|
my %single_mapping = ( |
|
27
|
|
|
|
|
|
|
assignee => 'WWW::Asana::User', |
|
28
|
|
|
|
|
|
|
workspace => 'WWW::Asana::Workspace', |
|
29
|
|
|
|
|
|
|
created_by => 'WWW::Asana::User', |
|
30
|
|
|
|
|
|
|
); |
|
31
|
0
|
|
|
|
|
|
my %new = %data; |
|
32
|
|
|
|
|
|
|
# single mapping before multi mapping so that workspace is already there |
|
33
|
0
|
|
|
|
|
|
for my $key (keys %single_mapping) { |
|
34
|
0
|
0
|
|
|
|
|
if (exists $data{$key}) { |
|
35
|
0
|
0
|
|
|
|
|
if ($data{$key}) { |
|
36
|
0
|
|
|
|
|
|
my $target_class = $single_mapping{$key}; |
|
37
|
0
|
0
|
|
|
|
|
load_class($target_class) unless is_class_loaded($target_class); |
|
38
|
0
|
|
|
|
|
|
$new{$key} = $target_class->new_from_response({ |
|
39
|
0
|
0
|
|
|
|
|
%{$data{$key}}, |
|
40
|
|
|
|
|
|
|
defined $data{client} ? ( client => $data{client} ) : (), |
|
41
|
|
|
|
|
|
|
response => $data{response}, |
|
42
|
|
|
|
|
|
|
}); |
|
43
|
|
|
|
|
|
|
} else { |
|
44
|
0
|
|
|
|
|
|
delete $new{$key}; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
0
|
|
|
|
|
|
for my $key (keys %multi_mapping) { |
|
49
|
0
|
0
|
|
|
|
|
if (exists $data{$key}) { |
|
50
|
0
|
|
|
|
|
|
$new{$key} = []; |
|
51
|
0
|
|
|
|
|
|
my $target_class = $multi_mapping{$key}; |
|
52
|
0
|
|
|
|
|
|
for (@{$data{$key}}) { |
|
|
0
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
load_class($target_class) unless is_class_loaded($target_class); |
|
54
|
0
|
|
|
|
|
|
push @{$new{$key}}, $target_class->new_from_response({ |
|
|
0
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
%{$_}, |
|
56
|
|
|
|
|
|
|
defined $data{client} ? ( client => $data{client} ) : (), |
|
57
|
0
|
0
|
|
|
|
|
(grep { $_ eq $key } @needs_workspace) ? ( workspace => $new{workspace} ) : (), |
|
|
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
response => $data{response}, |
|
59
|
|
|
|
|
|
|
}); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
0
|
|
|
|
|
|
for my $key (qw( completed_at modified_at created_at due_on )) { |
|
64
|
0
|
0
|
|
|
|
|
if (exists $data{$key}) { |
|
65
|
0
|
0
|
|
|
|
|
if ($data{$key}) { |
|
66
|
0
|
|
|
|
|
|
$new{$key} = DateTime::Format::ISO8601->parse_datetime($data{$key}); |
|
67
|
|
|
|
|
|
|
} else { |
|
68
|
0
|
|
|
|
|
|
delete $new{$key}; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
0
|
|
|
|
|
|
return $class->new(%new); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
|
76
|
|
|
|
|
|
|
__END__ |