| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 2 |  |  | 2 |  | 19 | use 5.16.0; | 
|  | 2 |  |  |  |  | 6 |  | 
| 2 | 2 |  |  | 2 |  | 10 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 38 |  | 
| 3 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 102 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package REST::Cot::Generators; | 
| 6 | 2 |  |  | 2 |  | 1436 | use Email::MIME::ContentType; | 
|  | 2 |  |  |  |  | 1783 |  | 
|  | 2 |  |  |  |  | 104 |  | 
| 7 | 2 |  |  | 2 |  | 11 | use JSON; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 14 |  | 
| 8 | 2 |  |  | 2 |  | 232 | use Carp qw[confess]; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 78 |  | 
| 9 | 2 |  |  | 2 |  | 1553 | use namespace::clean; | 
|  | 2 |  |  |  |  | 34547 |  | 
|  | 2 |  |  |  |  | 10 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub progenitor { | 
| 12 | 17 |  |  | 17 | 0 | 21 | my $self = shift; | 
| 13 |  |  |  |  |  |  | return sub { | 
| 14 | 197 | 100 |  | 197 |  | 555 | return $self unless $self->{parent}; | 
| 15 | 58 |  |  |  |  | 133 | return $self->{parent}->{progenitor}->(); | 
| 16 | 17 |  |  |  |  | 77 | }; | 
| 17 |  |  |  |  |  |  | } | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | sub path { | 
| 20 | 17 |  |  | 17 | 0 | 29 | my $self = shift; | 
| 21 |  |  |  |  |  |  | return sub { | 
| 22 | 138 |  |  | 138 |  | 148 | state $path; | 
| 23 | 138 | 50 |  |  |  | 237 | return undef unless ref($self->{progenitor}->()); | 
| 24 | 138 | 100 |  |  |  | 505 | return $path if $path; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 16 |  |  |  |  | 83 | $path = @{ $self->{args} }? | 
| 27 | 5 |  |  |  |  | 17 | join ( '/', $self->{parent}->{path}->(), $self->{name}, @{ $self->{args} } ) : | 
| 28 | 16 | 100 |  |  |  | 21 | join ( '/', $self->{parent}->{path}->(), $self->{name} ); | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 16 |  |  |  |  | 66 | return $path; | 
| 31 | 17 |  |  |  |  | 88 | }; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub method { | 
| 35 | 17 |  |  | 17 | 0 | 23 | my $self = shift; | 
| 36 |  |  |  |  |  |  | return sub { | 
| 37 | 0 |  |  | 0 |  |  | my $method = shift; | 
| 38 | 0 |  |  |  |  |  | my $self = shift; | 
| 39 | 0 |  |  |  |  |  | my $response = $self->{client}->$method( "$self", @_ ); | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 0 | 0 |  |  |  |  | if (my $content_type = $response->responseHeader('Content-Type')) { | 
| 42 | 0 |  |  |  |  |  | $content_type = parse_content_type($content_type); | 
| 43 | 0 |  |  |  |  |  | my $body = $response->responseContent; | 
| 44 | 0 |  |  |  |  |  | my $code = $response->responseCode; | 
| 45 | 0 |  |  |  |  |  | my $type = $content_type->{type}; | 
| 46 | 0 |  |  |  |  |  | my $subtype = $content_type->{subtype}; | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 0 | 0 |  |  |  |  | if ($type eq 'application') { | 
| 49 | 0 |  |  |  |  |  | my $decoded = $body; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 | 0 |  |  |  |  | $decoded = from_json($body) | 
| 52 |  |  |  |  |  |  | if ($subtype eq 'json'); | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 0 | 0 |  |  |  |  | $decoded = $response->responseXpath | 
| 55 |  |  |  |  |  |  | if ($subtype eq 'xml'); | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 0 | 0 |  |  |  |  | return !wantarray? $decoded : ($decoded, $code, $response); | 
| 58 |  |  |  |  |  |  | } else { | 
| 59 | 0 |  |  |  |  |  | return $response; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | } else { | 
| 62 | 0 |  |  |  |  |  | return $response; | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  | } | 
| 65 | 17 |  |  |  |  | 94 | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 2 |  |  | 2 |  | 1231 | no namespace::clean; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 8 |  | 
| 68 |  |  |  |  |  |  | 1; | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | __END__ |