line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package REST::Cot::Generators; |
2
|
|
|
|
|
|
|
$REST::Cot::Generators::VERSION = '0.006'; |
3
|
2
|
|
|
2
|
|
15
|
use 5.16.0; |
|
2
|
|
|
|
|
4
|
|
4
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
28
|
|
5
|
2
|
|
|
2
|
|
26
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
69
|
|
6
|
2
|
|
|
2
|
|
695
|
use Email::MIME::ContentType; |
|
2
|
|
|
|
|
1223
|
|
|
2
|
|
|
|
|
74
|
|
7
|
2
|
|
|
2
|
|
8
|
use URI; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
27
|
|
8
|
2
|
|
|
2
|
|
6
|
use JSON; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
10
|
|
9
|
2
|
|
|
2
|
|
175
|
use Carp qw[confess]; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
65
|
|
10
|
2
|
|
|
2
|
|
6
|
use Hash::Merge::Simple 'merge'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
52
|
|
11
|
2
|
|
|
2
|
|
6
|
use namespace::autoclean; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub progenitor { |
14
|
23
|
|
|
23
|
0
|
29
|
my $self = shift; |
15
|
|
|
|
|
|
|
return sub { |
16
|
206
|
100
|
|
206
|
|
326
|
return $self unless $self->{parent}; |
17
|
59
|
|
|
|
|
194
|
return $self->{parent}->{progenitor}->(); |
18
|
23
|
|
|
|
|
55
|
}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub path { |
22
|
23
|
|
|
23
|
0
|
16
|
my $self = shift; |
23
|
|
|
|
|
|
|
return sub { |
24
|
146
|
|
|
146
|
|
69
|
state $path; |
25
|
146
|
50
|
|
|
|
136
|
return undef unless ref($self->{progenitor}->()); |
26
|
146
|
100
|
|
|
|
270
|
return $path if $path; |
27
|
|
|
|
|
|
|
|
28
|
22
|
|
|
|
|
51
|
$path = @{ $self->{args} }? |
29
|
7
|
|
|
|
|
16
|
join ( '/', $self->{parent}->{path}->(), $self->{name}, @{ $self->{args} } ) : |
30
|
22
|
100
|
|
|
|
15
|
join ( '/', $self->{parent}->{path}->(), $self->{name} ); |
31
|
|
|
|
|
|
|
|
32
|
22
|
|
|
|
|
40
|
return $path; |
33
|
23
|
|
|
|
|
59
|
}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub merged_query { |
37
|
23
|
|
|
23
|
0
|
17
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return sub { |
40
|
184
|
100
|
|
184
|
|
198
|
if ($self->{parent}->{merged_query}) { |
41
|
51
|
|
|
|
|
57
|
return merge($self->{query}, $self->{parent}->{merged_query}->()); |
42
|
|
|
|
|
|
|
} else { |
43
|
133
|
|
|
|
|
152
|
return $self->{query}; |
44
|
|
|
|
|
|
|
} |
45
|
23
|
|
|
|
|
53
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub uri { |
49
|
23
|
|
|
23
|
0
|
16
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return sub { |
52
|
133
|
|
|
133
|
|
133
|
my $path = $self->{path}->(); |
53
|
133
|
|
|
|
|
135
|
my $q = $self->{merged_query}->(); |
54
|
133
|
|
|
|
|
503
|
my $uri = URI->new($path); |
55
|
|
|
|
|
|
|
|
56
|
133
|
|
|
|
|
9302
|
$uri->query_form($q); |
57
|
|
|
|
|
|
|
|
58
|
133
|
|
|
|
|
2872
|
return $uri |
59
|
23
|
|
|
|
|
52
|
}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub method { |
63
|
23
|
|
|
23
|
0
|
19
|
my $self = shift; |
64
|
|
|
|
|
|
|
return sub { |
65
|
0
|
|
|
0
|
|
|
my $method = shift; |
66
|
0
|
|
|
|
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $response = $self->{client}->$method( "$self", @_ ); |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if (my $content_type = $response->responseHeader('Content-Type')) { |
71
|
0
|
|
|
|
|
|
$content_type = parse_content_type($content_type); |
72
|
0
|
|
|
|
|
|
my $body = $response->responseContent; |
73
|
0
|
|
|
|
|
|
my $code = $response->responseCode; |
74
|
0
|
|
|
|
|
|
my $type = $content_type->{type}; |
75
|
0
|
|
|
|
|
|
my $subtype = $content_type->{subtype}; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if ($type eq 'application') { |
78
|
0
|
|
|
|
|
|
my $decoded = $body; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
$decoded = from_json($body) |
81
|
|
|
|
|
|
|
if ($subtype eq 'json'); |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
$decoded = $response->responseXpath |
84
|
|
|
|
|
|
|
if ($subtype eq 'xml'); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
return !wantarray? $decoded : ($decoded, $code, $response); |
87
|
|
|
|
|
|
|
} else { |
88
|
0
|
|
|
|
|
|
return $response; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} else { |
91
|
0
|
|
|
|
|
|
return $response; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
23
|
|
|
|
|
61
|
} |
95
|
|
|
|
|
|
|
|
96
|
2
|
|
|
2
|
|
820
|
no namespace::clean; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |