| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::Tumblr::API; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 16 |  |  | 16 |  | 68 | use strict; | 
|  | 16 |  |  |  |  | 25 |  | 
|  | 16 |  |  |  |  | 394 |  | 
| 4 | 16 |  |  | 16 |  | 56 | use warnings; | 
|  | 16 |  |  |  |  | 20 |  | 
|  | 16 |  |  |  |  | 320 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 16 |  |  | 16 |  | 53 | use Moose; | 
|  | 16 |  |  |  |  | 18 |  | 
|  | 16 |  |  |  |  | 119 |  | 
| 7 | 16 |  |  | 16 |  | 81701 | use JSON 'decode_json'; | 
|  | 16 |  |  |  |  | 9039 |  | 
|  | 16 |  |  |  |  | 144 |  | 
| 8 | 16 |  |  | 16 |  | 2279 | use Moose::Exporter; | 
|  | 16 |  |  |  |  | 25 |  | 
|  | 16 |  |  |  |  | 86 |  | 
| 9 |  |  |  |  |  |  | Moose::Exporter->setup_import_methods(with_caller => ['tumblr_api_method']); | 
| 10 | 16 |  |  | 16 |  | 7150 | use WWW::Tumblr::ResponseError; | 
|  | 16 |  |  |  |  | 38 |  | 
|  | 16 |  |  |  |  | 4210 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | sub tumblr_api_method ($$) { | 
| 13 | 272 |  |  | 272 | 0 | 3514 | my $class = Moose::Meta::Class->initialize( shift ); | 
| 14 | 272 |  |  |  |  | 2357 | my $method_name = $_[0]; | 
| 15 | 272 |  |  |  |  | 218 | my $method_spec = $_[1]; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | my $sub = sub { | 
| 18 | 16 |  |  | 16 |  | 14603 | my $self = shift; | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
|  |  |  |  | 16 |  |  |  | 
| 19 | 16 |  |  |  |  | 46 | my $args = { @_ }; | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 16 |  |  |  |  | 36 | my ( $http_method, $auth_method, $req_params, $url_param ) = @{ $method_spec }; | 
|  | 16 |  |  |  |  | 58 |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 16 |  |  |  |  | 28 | my $kind = lc( pop( @{ [ split '::', ref $self ] })); | 
|  | 16 |  |  |  |  | 123 |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | my $response = $self->_tumblr_api_request({ | 
| 26 |  |  |  |  |  |  | auth        => $auth_method, | 
| 27 |  |  |  |  |  |  | http_method => $http_method, | 
| 28 |  |  |  |  |  |  | url_path    => $kind . '/' . ( $kind eq 'blog' ? $self->base_hostname . '/' : '' ) . | 
| 29 |  |  |  |  |  |  | join('/', split /_/, $method_name) . | 
| 30 |  |  |  |  |  |  | ( defined $url_param && defined $args->{ $url_param } ? | 
| 31 | 16 | 100 | 100 |  |  | 605 | '/' . delete( $args->{ $url_param } ) : '' | 
|  |  | 100 |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | ), | 
| 33 |  |  |  |  |  |  | extra_args  => $args, | 
| 34 |  |  |  |  |  |  | }); | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 16 | 100 | 33 |  |  | 3275504 | if ( $response->is_success || ( $response->code == 301 && $method_name eq 'avatar') ) { | 
|  |  |  | 66 |  |  |  |  | 
| 37 | 15 |  |  |  |  | 378 | return decode_json($response->decoded_content)->{response}; | 
| 38 |  |  |  |  |  |  | } else { | 
| 39 | 1 |  |  |  |  | 53 | $self->error( WWW::Tumblr::ResponseError->new( | 
| 40 |  |  |  |  |  |  | response => $response | 
| 41 |  |  |  |  |  |  | ) ); | 
| 42 | 1 |  |  |  |  | 9 | return; | 
| 43 |  |  |  |  |  |  | } | 
| 44 | 272 |  |  |  |  | 966 | }; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 272 |  |  |  |  | 1520 | $class->add_method($method_name, $sub ); | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | 1; |