| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## Stripe API - ~/lib/Net/API/Stripe/List.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.200.3 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2020 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2019/11/02 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2022/10/25 | ||||||||||||||||||||||||||||
| 8 | ## All rights reserved. | ||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | package Net::API::Stripe::List; | ||||||||||||||||||||||||||||
| 15 | # To be inherited | ||||||||||||||||||||||||||||
| 16 | BEGIN | ||||||||||||||||||||||||||||
| 17 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use parent qw( Net::API::Stripe::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | # use B; | ||||||||||||||||||||||||||||
| 23 | # use B::Deparse; | ||||||||||||||||||||||||||||
| 24 | 1 | our( $VERSION ) = 'v0.200.3'; | |||||||||||||||||||||||||||
| 25 | }; | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Provide our own version of as_hash to avoid our helper methods from being called by Module::Generic::as_hash | ||||||||||||||||||||||||||||
| 31 | sub as_hash | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 34 | 0 | my $p = {}; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | $p = CORE::shift( @_ ) if( scalar( @_ ) == 1 && ref( $_[0] ) eq 'HASH' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
scalar @_ == 1 and ref $_[0] eq "HASH"
scalar @_ == 1
ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= scalar @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 36 | 0 | my $data = $self->_data; | |||||||||||||||||||||||||||
| 37 | 0 | my $res = []; | |||||||||||||||||||||||||||
| 38 | 0 | foreach my $this ( @$data ) | |||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if( $self->_is_object( $this ) && $this->can( 'as_hash' ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->_is_object($this) and $this->can("as_hash")
MC/DC0%0/2
$self->_is_object($this) and $this->can("as_hash")
$self->_is_object($this)
$this->can("as_hash")
Truth table0%0/3
A and B
A= $self->_is_object($this)B= $this->can("as_hash")
| |||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 0 | my $v = $this->as_hash( $p ); | |||||||||||||||||||||||||||
| 43 | 0 | CORE::push( @$res, $v ); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 0 | return( { data => $res } ); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub object { return( CORE::shift->_set_get_scalar( 'object', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
object: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub count { return( CORE::shift->total_count( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
count: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub data { return( CORE::shift->_data( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub has_more { return( CORE::shift->_set_get_boolean( 'has_more', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
has_more: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub url { return( CORE::shift->_set_get_uri( 'url', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub total_count | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
total_count: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||
| 64 | 0 | $self->_set_get_scalar( 'total_count', @_ ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 0 | my $total = $self->_set_get_scalar( 'total_count' ); | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | if( !defined( $total ) || !CORE::length( $total ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $total && CORE::length $total
MC/DC0%0/2
defined $total && CORE::length $total
defined $total
CORE::length $total
Truth table0%0/3
A && B
A= defined $totalB= CORE::length $total
| |||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | 0 | return( $self->_data->size ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | else | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 0 | return( $total ); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # Additional methods for navigation to be used like $list->next or $list->prev | ||||||||||||||||||||||||||||
| 78 | sub get | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $pos = @_ ? int( CORE::shift( @_ ) ) : ( $self->{_pos} || 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{"_pos"} or 0
MC/DC0%0/1
$self->{"_pos"} or 0
$self->{"_pos"}
Truth table0%0/2
A
A= $self->{"_pos"}
| |||||||||||||||||||||||||||||
| 82 | 0 | my $data = $self->_data; | |||||||||||||||||||||||||||
| 83 | 0 | return( $data->[ $pos ] ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub length | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
length: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 89 | 0 | my $data = $self->_data; | |||||||||||||||||||||||||||
| 90 | 0 | return( scalar( @$data ) ); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub next | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 96 | 0 | ▶ | $self->{_pos} = -1 if( !exists( $self->{_pos} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | my $data = $self->_data; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | if( $self->{_pos} + 1 < scalar( @$data ) ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||
| 100 | 0 | return( $data->[ ++$self->{_pos} ] ); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | ▶ | elsif( $self->has_more && scalar( @$data ) && $self->_is_object( $data->[-1] ) ) | |||||||||||||||||||||||||||
|
Condition0%0/5
$self->has_more and scalar @$data and $self->_is_object($data->[-1])
$self->has_more and scalar @$data
MC/DC0%0/2
$self->has_more and scalar @$data and $self->_is_object($data->[-1])
$self->has_more
$self->_is_object($data->[-1])
Truth table0%0/3
A and B
A= $self->has_moreB= $self->_is_object($data->[-1])
| |||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||
| 104 | 0 | my $last_id = $data->[-1]->id; | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | $self->{_limit} = scalar( @$data ) if( !$self->{_limit} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | my $opts = | ||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||
| 108 | starting_after => $last_id, | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | limit => ( $self->{_limit} || 10 ), | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'_limit'} || 10
MC/DC0%0/1
$self->{'_limit'} || 10
$self->{'_limit'}
Truth table0%0/2
A
A= $self->{'_limit'}
| |||||||||||||||||||||||||||||
| 110 | }; | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $hash = $self->parent->get( $self->url, $opts ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent->get($self->url, $opts) || (return)
MC/DC0%0/1
$self->parent->get($self->url, $opts) || (return)
$self->parent->get($self->url, $opts)
Truth table0%0/2
A
A= $self->parent->get($self->url, $opts)
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | return( $self->error( "Cannot find property 'object' in this hash reference: ", sub{ $self->dumper( $hash ) } ) ) if( !CORE::exists( $hash->{object} ) ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my $class = $self->_object_type_to_class( $hash->{object} ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->_object_type_to_class($hash->{'object'}) || (return)
MC/DC0%0/1
$self->_object_type_to_class($hash->{'object'}) || (return)
$self->_object_type_to_class($hash->{'object'})
Truth table0%0/2
A
A= $self->_object_type_to_class($hash->{'object'})
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | my $list = $self->parent->_response_to_object( $class, $hash ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent->_response_to_object($class, $hash) || (return)
MC/DC0%0/1
$self->parent->_response_to_object($class, $hash) || (return)
$self->parent->_response_to_object($class, $hash)
Truth table0%0/2
A
A= $self->parent->_response_to_object($class, $hash)
| |||||||||||||||||||||||||||||
| 115 | 0 | $data = $list->_data; | |||||||||||||||||||||||||||
| 116 | 0 | $self->{data} = $data; | |||||||||||||||||||||||||||
| 117 | 0 | $self->{_pos} = 0; | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | return( '' ) if( !scalar( @$data ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | return( $data->[ $self->{_pos} ] ); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | else | ||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||
| 123 | # We do not return undef(), which we use to signal errors | ||||||||||||||||||||||||||||
| 124 | 0 | return( '' ); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub prev | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
prev: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 131 | 0 | ▶ | $self->{_pos} = -1 if( !exists( $self->{_pos} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | my $data = $self->_data; | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | if( $self->{_pos} - 1 >= 0 ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||
| 135 | 0 | return( $data->[ --$self->{_pos} ] ); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | ▶ | elsif( scalar( @$data ) && $self->_is_object( $data->[0] ) ) | |||||||||||||||||||||||||||
|
Condition0%0/3
scalar @$data and $self->_is_object($data->[0])
MC/DC0%0/2
scalar @$data and $self->_is_object($data->[0])
scalar @$data
$self->_is_object($data->[0])
Truth table0%0/3
A and B
A= scalar @$dataB= $self->_is_object($data->[0])
| |||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 0 | my $first_id = $data->[0]->id; | |||||||||||||||||||||||||||
| 140 | 0 | ▶ | $self->{_limit} = scalar( @$data ) if( !$self->{_limit} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | my $opts = | ||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||
| 143 | ending_before => $first_id, | ||||||||||||||||||||||||||||
| 144 | 0 | ▶ | limit => ( $self->{_limit} || 10 ), | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'_limit'} || 10
MC/DC0%0/1
$self->{'_limit'} || 10
$self->{'_limit'}
Truth table0%0/2
A
A= $self->{'_limit'}
| |||||||||||||||||||||||||||||
| 145 | }; | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my $hash = $self->parent->get( $self->url, $opts ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent->get($self->url, $opts) || (return)
MC/DC0%0/1
$self->parent->get($self->url, $opts) || (return)
$self->parent->get($self->url, $opts)
Truth table0%0/2
A
A= $self->parent->get($self->url, $opts)
| |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | return( $self->error( "Cannot find property 'object' in this hash reference: ", sub{ $self->dumper( $hash ) } ) ) if( !CORE::exists( $hash->{object} ) ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $class = $self->_object_type_to_class( $hash->{object} ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->_object_type_to_class($hash->{'object'}) || (return)
MC/DC0%0/1
$self->_object_type_to_class($hash->{'object'}) || (return)
$self->_object_type_to_class($hash->{'object'})
Truth table0%0/2
A
A= $self->_object_type_to_class($hash->{'object'})
| |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $list = $self->parent->_response_to_object( $class, $hash ) || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent->_response_to_object($class, $hash) || (return)
MC/DC0%0/1
$self->parent->_response_to_object($class, $hash) || (return)
$self->parent->_response_to_object($class, $hash)
Truth table0%0/2
A
A= $self->parent->_response_to_object($class, $hash)
| |||||||||||||||||||||||||||||
| 150 | 0 | $data = $list->_data; | |||||||||||||||||||||||||||
| 151 | 0 | $self->{data} = $data; | |||||||||||||||||||||||||||
| 152 | # $self->_data( $data ); | ||||||||||||||||||||||||||||
| 153 | 0 | $self->{_pos} = $#$data; | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | return( '' ) if( !scalar( @$data ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | return( $data->[ $self->{_pos} ] ); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | else | ||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||
| 159 | # We do not return undef(), which we use to signal errors | ||||||||||||||||||||||||||||
| 160 | 0 | return( '' ); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | sub pop | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
pop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 166 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 167 | 0 | return( $self->_data->pop ); | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | sub push | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
push: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 172 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 173 | 0 | ▶ | my $this = CORE::shift( @_ ) || return( $self->error( "Nothing was provided to add to the list of object." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
CORE::shift @_ || (return $self->error('Nothing was provided to add to the list of object.'))
MC/DC0%0/1
CORE::shift @_ || (return $self->error('Nothing was provided to add to the list of object.'))
CORE::shift @_
Truth table0%0/2
A
A= CORE::shift @_
| |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $self->_check( $this ) || return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | $self->_data->push( $this ); | |||||||||||||||||||||||||||
| 176 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | sub shift | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
shift: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 181 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 182 | 0 | return( $self->_data->shift ); | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | sub unshift | ||||||||||||||||||||||||||||
| 186 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unshift: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 187 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 188 | 0 | ▶ | my $this = CORE::shift( @_ ) || return( $self->error( "Nothing was provided to add to the list of object." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
CORE::shift @_ || (return $self->error('Nothing was provided to add to the list of object.'))
MC/DC0%0/1
CORE::shift @_ || (return $self->error('Nothing was provided to add to the list of object.'))
CORE::shift @_
Truth table0%0/2
A
A= CORE::shift @_
| |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | $self->_check( $this ) || return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | $self->_data->unshift( $this ); | |||||||||||||||||||||||||||
| 191 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | sub _check | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_check: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 196 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 197 | 0 | ▶ | my $this = CORE::shift( @_ ) || return( $self->error( "No data was provided to check." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
CORE::shift @_ || (return $self->error('No data was provided to check.'))
MC/DC0%0/1
CORE::shift @_ || (return $self->error('No data was provided to check.'))
CORE::shift @_
Truth table0%0/2
A
A= CORE::shift @_
| |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | return( $self->error( "Data provided is not an object." ) ) if( !$self->_is_object( $this ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | # Check if there is any data and if there is find out what kind of object we are holding so we can maintain consistency | ||||||||||||||||||||||||||||
| 200 | 0 | my $data = $self->_data; | |||||||||||||||||||||||||||
| 201 | 0 | my $obj_name; | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | if( scalar( @$data ) && $self->_is_object( $data->[0] ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @$data and $self->_is_object($data->[0])
MC/DC0%0/2
scalar @$data and $self->_is_object($data->[0])
scalar @$data
$self->_is_object($data->[0])
Truth table0%0/3
A and B
A= scalar @$dataB= $self->_is_object($data->[0])
| |||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||
| 204 | 0 | ▶ | $obj_name = $data->[0]->object if( $data->[0]->can( 'object' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if( $this->can( 'object' ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return( $self->error( "Object provided ($this) has an object type (", $this->object, ") different from the ones currently in our stack ($obj_name)." ) ) if( $this->object ne $obj_name ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | 0 | return( $this ); | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | sub _data | ||||||||||||||||||||||||||||
| 214 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_data: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||
| 215 | 0 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 216 | 0 | my $field = 'data'; | |||||||||||||||||||||||||||
| 217 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | { | ||||||||||||||||||||||||||||
| 219 | 0 | my $ref = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 220 | 0 | ▶ | return( $self->error( "I was expecting an array ref, but instead got '$ref'. _is_array returned: '", $self->_is_array( $ref ), "'" ) ) if( !$self->_is_array( $ref ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | my $arr = []; | |||||||||||||||||||||||||||
| 222 | # Are we provided with an array of existing objects? No need to do anything then | ||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if( $self->_is_object( $ref->[0] ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||
| 225 | # Unless it is already an array object, we make it one | ||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $arr = $self->_is_object( $ref ) ? $ref : $self->new_array( $ref ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | else | ||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if( scalar( @$ref ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||
| 232 | 0 | my $type; | |||||||||||||||||||||||||||
| 233 | 0 | ▶ | if( $self->_is_object( $ref->[0] ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | { | ||||||||||||||||||||||||||||
| 235 | 0 | ▶ | return( $self->error( "I found an array of objects, but they do not have the method \"object\"." ) ) if( !$ref->[0]->can( 'object' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | ▶ | $type = $ref->[0]->object || return( $self->error( "Somehow, the object property for this object (", $ref->[0], ") is empty." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$ref->[0]->object || (return $self->error('Somehow, the object property for this object (', $ref->[0], ') is empty.'))
MC/DC0%0/1
$ref->[0]->object || (return $self->error('Somehow, the object property for this object (', $ref->[0], ') is empty.'))
$ref->[0]->object
Truth table0%0/2
A
A= $ref->[0]->object
| |||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | else | ||||||||||||||||||||||||||||
| 239 | { | ||||||||||||||||||||||||||||
| 240 | 0 | ▶ | return( $self->error( "I was expecting an array of hash reference, but instead of hash I found $ref->[0]" ) ) if( ref( $ref->[0] ) ne 'HASH' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 0 | ▶ | return( $self->error( "Found an hash reference in this array, but it is empty: ", sub{ $self->dumper( $ref ) } ) ) if( !scalar( keys( %{$ref->[0]} ) ) ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | $type = $ref->[0]->{object} || return( $self->error( "I was expecting a string in property 'object', but found nothing: ", sub{ $self->dumper( $ref ) } ) ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/2
$ref->[0]{'object'} || (return $self->error(q[I was expecting a string in property 'object', but found nothing: ], sub {
$self->dumper($ref);
}
))
MC/DC0%0/1
$ref->[0]{'object'} || (return $self->error(q[I was expecting a string in property 'object', but found nothing: ], sub {
$self->dumper($ref);
}
))
$ref->[0]{'object'}
Truth table0%0/2
A
A= $ref->[0]{'object'}
| |||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | 0 | ▶ | my $class = $self->_object_type_to_class( $type ) || return( $self->error( "Could not find corresponding class for ojbect type \"$type\"." ) ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->_object_type_to_class($type) || (return $self->error(qq[Could not find corresponding class for ojbect type "$type".]))
MC/DC0%0/1
$self->_object_type_to_class($type) || (return $self->error(qq[Could not find corresponding class for ojbect type "$type".]))
$self->_object_type_to_class($type)
Truth table0%0/2
A
A= $self->_object_type_to_class($type)
| |||||||||||||||||||||||||||||
| 245 | 0 | $arr = $self->_set_get_object_array_object( $field, $class, $ref ); | |||||||||||||||||||||||||||
| 246 | # Store this value used by next() and prev() to replicate the query with the right limit | ||||||||||||||||||||||||||||
| 247 | # If initial query made by the user was 10 this array would be 10 or less if there is no more data | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | 0 | $self->{ $field } = $arr; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if( !$self->{ $field } || !$self->_is_object( $self->{ $field } ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{$field} and $self->_is_object($self->{$field})
MC/DC0%0/2
$self->{$field} and $self->_is_object($self->{$field})
$self->{$field}
$self->_is_object($self->{$field})
Truth table0%0/3
A and B
A= $self->{$field}B= $self->_is_object($self->{$field})
| |||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $o = $self->new_array( ( defined( $self->{ $field } ) && CORE::length( $self->{ $field } ) ) ? $self->{ $field } : [] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{$field} and CORE::length $self->{$field}
MC/DC0%0/2
defined $self->{$field} and CORE::length $self->{$field}
defined $self->{$field}
CORE::length $self->{$field}
Truth table0%0/3
A and B
A= defined $self->{$field}B= CORE::length $self->{$field}
| |||||||||||||||||||||||||||||
| 255 | 0 | $self->{ $field } = $o; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | 0 | return( $self->{ $field } ); | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 1 | 1; | |||||||||||||||||||||||||||
| 261 | # NOTE: POD | ||||||||||||||||||||||||||||
| 262 | __END__ | ||||||||||||||||||||||||||||