| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 7 |  |  | 7 |  | 34 | use strict; | 
|  | 7 |  |  |  |  | 12 |  | 
|  | 7 |  |  |  |  | 176 |  | 
| 2 | 7 |  |  | 7 |  | 34 | use warnings; | 
|  | 7 |  |  |  |  | 14 |  | 
|  | 7 |  |  |  |  | 193 |  | 
| 3 | 7 |  |  | 7 |  | 33 | use MRO::Compat 'c3'; | 
|  | 7 |  |  |  |  | 13 |  | 
|  | 7 |  |  |  |  | 219 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package WebService::Shippo::Collection; | 
| 6 | 7 |  |  | 7 |  | 35 | use Params::Callbacks ( 'callbacks' ); | 
|  | 7 |  |  |  |  | 14 |  | 
|  | 7 |  |  |  |  | 326 |  | 
| 7 | 7 |  |  | 7 |  | 36 | use base              ( 'WebService::Shippo::Object' ); | 
|  | 7 |  |  |  |  | 12 |  | 
|  | 7 |  |  |  |  | 4925 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub count | 
| 10 |  |  |  |  |  |  | { | 
| 11 | 0 |  |  | 0 | 0 |  | my ( $invocant ) = @_; | 
| 12 |  |  |  |  |  |  | return $invocant->{count} | 
| 13 | 0 | 0 |  |  |  |  | if ref $invocant; | 
| 14 | 0 |  |  |  |  |  | return $invocant->all( results => 1 )->{count}; | 
| 15 |  |  |  |  |  |  | } | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub page_size | 
| 18 |  |  |  |  |  |  | { | 
| 19 | 0 |  |  | 0 | 0 |  | my ( $invocant ) = @_; | 
| 20 | 0 |  |  |  |  |  | return scalar( @{ $invocant->{results} } ); | 
|  | 0 |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | } | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | sub next_page | 
| 24 |  |  |  |  |  |  | { | 
| 25 | 0 |  |  | 0 | 0 |  | my ( $callbacks, $invocant ) = &callbacks; | 
| 26 | 0 | 0 |  |  |  |  | return unless defined $invocant->{next}; | 
| 27 | 0 |  |  |  |  |  | my $response = WebService::Shippo::Request->get( $invocant->{next} ); | 
| 28 | 0 |  |  |  |  |  | return $invocant->item_class->construct_from( $response, $callbacks ); | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub plus_next_pages | 
| 32 |  |  |  |  |  |  | { | 
| 33 | 0 |  |  | 0 | 0 |  | my ( $callbacks, $invocant ) = &callbacks; | 
| 34 | 0 | 0 |  |  |  |  | return $invocant unless defined $invocant->{next}; | 
| 35 | 0 |  |  |  |  |  | my $current = $invocant; | 
| 36 | 0 |  |  |  |  |  | while ( defined( $current->{next} ) ) { | 
| 37 | 0 |  |  |  |  |  | my $r = WebService::Shippo::Request->get( $current->{next} ); | 
| 38 | 0 |  |  |  |  |  | $current = $invocant->item_class->construct_from( $r, $callbacks ); | 
| 39 | 0 |  |  |  |  |  | push @{ $invocant->{results} }, @{ $current->{results} }; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | } | 
| 41 | 0 |  |  |  |  |  | undef $invocant->{next}; | 
| 42 | 0 |  |  |  |  |  | return $invocant; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub previous_page | 
| 46 |  |  |  |  |  |  | { | 
| 47 | 0 |  |  | 0 | 0 |  | my ( $callbacks, $invocant ) = &callbacks; | 
| 48 | 0 | 0 |  |  |  |  | return unless defined $invocant->{previous}; | 
| 49 | 0 |  |  |  |  |  | my $response = WebService::Shippo::Request->get( $invocant->{previous} ); | 
| 50 | 0 |  |  |  |  |  | return $invocant->item_class->construct_from( $response, $callbacks ); | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | sub plus_previous_pages | 
| 54 |  |  |  |  |  |  | { | 
| 55 | 0 |  |  | 0 | 0 |  | my ( $callbacks, $invocant ) = &callbacks; | 
| 56 | 0 | 0 |  |  |  |  | return $invocant unless defined $invocant->{previous}; | 
| 57 | 0 |  |  |  |  |  | my $current = $invocant; | 
| 58 | 0 |  |  |  |  |  | while ( defined( $current->{previous} ) ) { | 
| 59 | 0 |  |  |  |  |  | my $r = WebService::Shippo::Request->get( $current->{previous} ); | 
| 60 | 0 |  |  |  |  |  | $current = $invocant->item_class->construct_from( $r, $callbacks ); | 
| 61 | 0 |  |  |  |  |  | unshift @{ $invocant->{results} }, @{ $current->{results} }; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | } | 
| 63 | 0 |  |  |  |  |  | undef $invocant->{previous}; | 
| 64 | 0 |  |  |  |  |  | return $invocant; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub items | 
| 68 |  |  |  |  |  |  | { | 
| 69 | 0 |  |  | 0 | 0 |  | my ( $callbacks, $invocant ) = &callbacks; | 
| 70 | 0 | 0 |  |  |  |  | return $callbacks->transform( @{ $invocant->{results} } ) | 
|  | 0 |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | if wantarray; | 
| 72 | 0 |  |  |  |  |  | return [ $callbacks->transform( @{ $invocant->{results} } ) ]; | 
|  | 0 |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub item | 
| 76 |  |  |  |  |  |  | { | 
| 77 | 0 |  |  | 0 | 0 |  | my ( $callbacks, $invocant, $position ) = &callbacks; | 
| 78 |  |  |  |  |  |  | return | 
| 79 | 0 | 0 | 0 |  |  |  | unless $position > 0 && $position <= $invocant->{count}; | 
| 80 | 0 |  |  |  |  |  | return $callbacks->smart_transform( $invocant->{results}[ $position - 1 ] ); | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | sub item_at_index | 
| 84 |  |  |  |  |  |  | { | 
| 85 | 0 |  |  | 0 | 0 |  | my ( $callbacks, $invocant, $index ) = &callbacks; | 
| 86 | 0 |  |  |  |  |  | return $callbacks->smart_transform( $invocant->{results}[$index] ); | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | BEGIN { | 
| 90 | 7 |  |  | 7 |  | 39 | no warnings 'once'; | 
|  | 7 |  |  |  |  | 114 |  | 
|  | 7 |  |  |  |  | 319 |  | 
| 91 | 7 |  |  | 7 |  | 25 | *Shippo::Collection:: = *WebService::Shippo::Collection::; | 
| 92 | 7 |  |  |  |  | 143 | *to_array = *items; | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | 1; |