| 1 | package WWW::Ohloh::API::Collection; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use Object::InsideOut; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 16 | our $VERSION = '1.0_1'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 16 | ▶ | use overload '<>' => \&next; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 16 | my @cache_of : Field; | |||||||||||||||||||||||||||
| 14 | 16 | my @total_entries_of : Field : Default(-1); | |||||||||||||||||||||||||||
| 15 | 16 | my @page_of : Field; | |||||||||||||||||||||||||||
| 16 | 16 | my @max_entries_of : Field : Arg(max) : Get(max) : Default(undef); | |||||||||||||||||||||||||||
| 17 | 16 | my @element_of : Field : Arg(element) : Get(element); | |||||||||||||||||||||||||||
| 18 | 16 | my @sort_order_of : Field : Arg(sort); | |||||||||||||||||||||||||||
| 19 | 16 | my @query_of : Field : Arg(query); | |||||||||||||||||||||||||||
| 20 | 16 | my @ohloh_of : Field : Arg( name => 'ohloh', mandatory => 1); | |||||||||||||||||||||||||||
| 21 | 16 | my @read_so_far : Field : Get(get_read_so_far) : Set(set_read_so_far) : | |||||||||||||||||||||||||||
| 22 | Default(0); | ||||||||||||||||||||||||||||
| 23 | 16 | my @all_read : Field; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub _init : Init { | ||||||||||||||||||||||||||||
| 26 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 5 | $cache_of[$$self] = []; # initialize to empty array | |||||||||||||||||||||||||||
| 29 | 16 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub total_entries { | ||||||||||||||||||||||||||||
| 34 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
total_entries: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # if not initialized, get a first bunch of entries | ||||||||||||||||||||||||||||
| 37 | 4 | ▶ | if ( $total_entries_of[$$self] == -1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 1 | $self->_gather_more; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 4 | return $total_entries_of[$$self]; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub next { | ||||||||||||||||||||||||||||
| 47 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=6 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | my $nbr_requested = shift || 1; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | while ( @{ $cache_of[$$self] } < $nbr_requested | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@{$cache_of[$$self];} < $nbr_requested and not $all_read[$$self]
MC/DC50%1/2
@{$cache_of[$$self];} < $nbr_requested and not $all_read[$$self]
@{$cache_of[$$self];} < $nbr_requested
not $all_read[$$self]
Truth table66%2/3
A and not(B)
A= @{$cache_of[$$self];} < $nbr_requestedB= not $all_read[$$self]
| |||||||||||||||||||||||||||||
| 51 | and not $all_read[$$self] ) { | ||||||||||||||||||||||||||||
| 52 | 1 | $self->_gather_more; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | my @bunch = splice @{ $cache_of[$$self] }, 0, $nbr_requested; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if (@bunch) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | return wantarray ? @bunch : $bunch[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # we've nothing else to return | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | $page_of[$$self] = 0; | |||||||||||||||||||||||||||
| 64 | 0 | $all_read[$$self] = 0; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | return; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub _gather_more { | ||||||||||||||||||||||||||||
| 72 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_gather_more: called CC=5 SCAR=17.5
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 3 | my ( $url, $xml ) = $ohloh_of[$$self]->_query_server( | |||||||||||||||||||||||||||
| 75 | $self->query_path, | ||||||||||||||||||||||||||||
| 76 | { ( query => $query_of[$$self] ) x !!$query_of[$$self], | ||||||||||||||||||||||||||||
| 77 | ( sort => $sort_order_of[$$self] ) x !!$sort_order_of[$$self], | ||||||||||||||||||||||||||||
| 78 | page => ++$page_of[$$self] } ); | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | my $class = $self->element; | |||||||||||||||||||||||||||
| 81 | my @new_batch = | ||||||||||||||||||||||||||||
| 82 | 3 | map { $class->new( ohloh => $ohloh_of[$$self], xml => $_, ) } | |||||||||||||||||||||||||||
| 83 | $xml->findnodes( $self->element_name ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 3 | ▶ | if ( defined( $self->max ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->max and $self->get_read_so_far + @new_batch > $self->max
MC/DC0%0/2
defined $self->max and $self->get_read_so_far + @new_batch > $self->max
defined $self->max
$self->get_read_so_far + @new_batch > $self->max
Truth table33%1/3
A and B
A= defined $self->maxB= $self->get_read_so_far + @new_batch > $self->max
| |||||||||||||||||||||||||||||
| 86 | and $self->get_read_so_far + @new_batch > $self->max ) { | ||||||||||||||||||||||||||||
| 87 | 0 | @new_batch = | |||||||||||||||||||||||||||
| 88 | @new_batch[ 0 .. $self->max - $self->get_read_so_far - 1 ]; | ||||||||||||||||||||||||||||
| 89 | 0 | $all_read[$$self] = 1; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 3 | $read_so_far[$$self] += @new_batch; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 3 | ▶ | if ( @new_batch == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | $all_read[$$self] = 1; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # get total elements + where we are (but don't trust it) | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 3 | $total_entries_of[$$self] = | |||||||||||||||||||||||||||
| 101 | $xml->findvalue('/response/items_available/text()'); | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 3 | my $first_item = $xml->findvalue('/response/first_item_position/text()'); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | push @{ $cache_of[$$self] }, @new_batch; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 3 | ▶ | $all_read[$$self] = 1 if $self->total_entries == $self->get_read_so_far; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 3 | return; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub all { | ||||||||||||||||||||||||||||
| 115 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
all: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | $self->_gather_more until ( $all_read[$$self] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 1 | my @bunch = @{ $cache_of[$$self] }; | |||||||||||||||||||||||||||
| 120 | 1 | $cache_of[$$self] = []; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 1 | $page_of[$$self] = 0; | |||||||||||||||||||||||||||
| 123 | 1 | $all_read[$$self] = 0; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 1 | return @bunch; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 16 | 1; | |||||||||||||||||||||||||||