| 1 | package WWW::Google::Contacts::Roles::List; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 17 | $WWW::Google::Contacts::Roles::List::VERSION = '0.38'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use MooseX::Types::Moose qw( ArrayRef Int ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use Perl6::Junction qw( any ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 17 | ▶ | use WWW::Google::Contacts::Data; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 17 | requires 'baseurl', 'element_class'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 17 | has elements => ( | |||||||||||||||||||||||||||
| 16 | isa => ArrayRef, | ||||||||||||||||||||||||||||
| 17 | is => 'rw', | ||||||||||||||||||||||||||||
| 18 | lazy_build => 1, | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 17 | has server => ( | |||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||
| 23 | required => 1, | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 17 | has pointer => ( | |||||||||||||||||||||||||||
| 27 | isa => Int, | ||||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||
| 29 | default => 0, | ||||||||||||||||||||||||||||
| 30 | init_arg => undef, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub search { | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my ( $self, $search ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
search: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $class = $self->element_class; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # TODO - make something clever to match XML keys without having to bless all the objects for comparison | ||||||||||||||||||||||||||||
| 39 | # this could be a start; | ||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||
| 41 | #my $element = $class->new( server => $self->server ); | ||||||||||||||||||||||||||||
| 42 | #my $search_params = []; | ||||||||||||||||||||||||||||
| 43 | #foreach my $key ( keys %{ $search } ) { | ||||||||||||||||||||||||||||
| 44 | # my $xml_key = $element->get_xml_key( $key ); | ||||||||||||||||||||||||||||
| 45 | # if ( $xml_key ) { | ||||||||||||||||||||||||||||
| 46 | # push @{ $search_params }, | ||||||||||||||||||||||||||||
| 47 | # { | ||||||||||||||||||||||||||||
| 48 | # xml_key => $xml_key, | ||||||||||||||||||||||||||||
| 49 | # value => $search->{ $key }, | ||||||||||||||||||||||||||||
| 50 | # }; | ||||||||||||||||||||||||||||
| 51 | # } | ||||||||||||||||||||||||||||
| 52 | # else { | ||||||||||||||||||||||||||||
| 53 | # croak "Can't find XML key for [$key]"; | ||||||||||||||||||||||||||||
| 54 | # } | ||||||||||||||||||||||||||||
| 55 | #} | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # This doesn't scale well.... SLOW | ||||||||||||||||||||||||||||
| 58 | 0 | my $to_ret = []; | |||||||||||||||||||||||||||
| 59 | ELEM: | ||||||||||||||||||||||||||||
| 60 | 0 | foreach my $elem ( @{ $self->elements } ) { | |||||||||||||||||||||||||||
| 61 | 0 | my $obj = $class->new( server => $self->server ); | |||||||||||||||||||||||||||
| 62 | 0 | $obj->set_from_server($elem); | |||||||||||||||||||||||||||
| 63 | 0 | foreach my $key ( keys %{$search} ) { | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | next ELEM unless ( defined $obj->$key ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( ref( $obj->$key ) and ref( $obj->$key ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $obj->$key and ref $obj->$key eq "ARRAY"
MC/DC0%0/2
ref $obj->$key and ref $obj->$key eq "ARRAY"
ref $obj->$key
ref $obj->$key eq "ARRAY"
Truth table0%0/3
A and B
A= ref $obj->$keyB= ref $obj->$key eq "ARRAY"
| |||||||||||||||||||||||||||||
| 66 | 0 | my $search_field = $obj->$key->[0]->search_field; | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | next ELEM unless ( defined $search_field ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | my @values = map { $_->$search_field } @{ $obj->$key }; | |||||||||||||||||||||||||||
| 69 | 0 | my $search_key = $search->{$key}; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # protocol might not match, that doesn't matter | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ( $search_key =~ s{^http.?:}{} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $_ =~ s{^http.?:}{} foreach (@values); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | next ELEM unless ( any(@values) eq $search_key ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||
| 78 | 0 | my $search_key = $search->{$key}; | |||||||||||||||||||||||||||
| 79 | 0 | my $obj_key = $obj->$key; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # protocol might not match, that doesn't matter | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ( $search_key =~ s{^http.?:}{} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | $obj_key =~ s{^http.?:}{}; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 0 | ▶ | next ELEM unless ( $obj_key eq $search_key ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 0 | push @{$to_ret}, $obj; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return wantarray ? @{$to_ret} : $to_ret; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub next { | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return undef unless ( $self->elements->[ $self->pointer ] ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | my $next = $self->elements->[ $self->pointer ]; | |||||||||||||||||||||||||||
| 97 | 0 | $self->pointer( $self->pointer + 1 ); | |||||||||||||||||||||||||||
| 98 | 0 | my $class = $self->element_class; | |||||||||||||||||||||||||||
| 99 | 0 | return $class->new( server => $self->server )->set_from_server($next); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub _build_elements { | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_elements: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | my $args = {}; | |||||||||||||||||||||||||||
| 106 | 0 | $args->{'alt'} = 'atom'; # must be atom | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | $args->{'max-results'} ||= 9999; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"max-results"} ||= 9999
MC/DC0%0/1
$args->{"max-results"} ||= 9999
$args->{"max-results"}
Truth table0%0/2
A
A= $args->{"max-results"}
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $group = delete $args->{group} || 'full'; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args->{'group'} || 'full'
MC/DC0%0/1
delete $args->{'group'} || 'full'
delete $args->{'group'}
Truth table0%0/2
A
A= delete $args->{'group'}
| |||||||||||||||||||||||||||||
| 109 | 0 | my $url = sprintf( '%s/%s?v=3.0', $self->baseurl, uri_escape($group) ); | |||||||||||||||||||||||||||
| 110 | 0 | foreach my $key ( keys %$args ) { | |||||||||||||||||||||||||||
| 111 | 0 | $url .= '&' . uri_escape($key) . '=' . uri_escape( $args->{$key} ); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 0 | my $res = $self->server->get($url); | |||||||||||||||||||||||||||
| 114 | 0 | my $content = $res->content; | |||||||||||||||||||||||||||
| 115 | 0 | my $data = WWW::Google::Contacts::Data->decode_xml($content); | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $array = $data->{entry} || []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$data->{'entry'} || []
MC/DC0%0/1
$data->{'entry'} || []
$data->{'entry'}
Truth table0%0/2
A
A= $data->{'entry'}
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ( ref($array) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | $array = [$array]; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # ..lots of overhead to bless them all now. | ||||||||||||||||||||||||||||
| 123 | #my $class = $self->element_class; | ||||||||||||||||||||||||||||
| 124 | #$array = [ map { $class->new( server => $self->server )->set_from_server( $_ ) } @{ $array } ]; | ||||||||||||||||||||||||||||
| 125 | 0 | return $array; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 17 | 1; | |||||||||||||||||||||||||||