| 1 | package Net::Safari::Response; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | Net::Safari::Response - Results of a Safari search | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | use Net::Safari::Response; | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | $resp = $net_safari->search(); | ||||||||||||||||||||
| 12 | $resp = Net::Safari::Response->new( xml => $xml); | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | my @books = $resp->books; | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | See Net::Safari for general usage info. | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | Normally this object will be created for you after a call to | ||||||||||||||||||||
| 21 | Net::Safari->search(). | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =head1 USAGE | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | #TODO - Add error message method, see Safari.pm SYNOPSIS. | ||||||||||||||||||||
| 29 | 13 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 13 | ▶ | use XML::Simple; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 13 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 13 | ▶ | use URI::Escape; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | 13 | ▶ | use Class::Accessor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | 13 | ▶ | use Class::Fields; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 13 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 13 | ▶ | use Net::Safari::Response::Book; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 13 | ▶ | use base qw(Class::Accessor Class::Fields); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | 13 | ▶ | use fields qw(raw_response is_success); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | 13 | Net::Safari::Response->mk_accessors( Net::Safari::Response->show_fields('Public') ); | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =head2 new() | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | my $resp = Net::Safari::Response->new( xml => $xml ); | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | The Response object is created from the raw xml returned by calls to Safari. | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | sub new | ||||||||||||||||||||
| 51 | 10 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||||||||||||
| 52 | 10 | my ($class, %args) = @_; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 10 | ▶ | my $self = bless ({}, ref ($class) || $class); | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 10 | $self->raw_response( $args{xml} ); | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 10 | $self->_init(); | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | return ($self); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 10 | ▶ | sub _init { | ||||||||||||||||||
|
Subroutine
_init: called CC=3 SCAR=20.3
| |||||||||||||||||||||
| 64 | 10 | my $self = shift; | |||||||||||||||||||
| 65 | #TODO: Handle error responses; | ||||||||||||||||||||
| 66 | 10 | my $ref = XMLin($self->raw_response, | |||||||||||||||||||
| 67 | 'noattr' => 1, | ||||||||||||||||||||
| 68 | 'forcearray' => [ qw(book author content hlhit subject) ] | ||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | ▶ | if ( !(ref $ref eq "HASH") ) | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 72 | { | ||||||||||||||||||||
| 73 | #TODO: Error handling | ||||||||||||||||||||
| 74 | 0 | $self->is_success(0); | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | elsif ($ref->{book}) | ||||||||||||||||||||
| 77 | { | ||||||||||||||||||||
| 78 | 0 | $self->is_success(1); | |||||||||||||||||||
| 79 | 0 | $self->_set_books($ref->{book}); | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | sub _set_books { | ||||||||||||||||||
|
Subroutine
_set_books: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||||||||
| 85 | 0 | my $books_ref = shift; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | my @books; | |||||||||||||||||||
| 88 | 0 | foreach my $book (@$books_ref) { | |||||||||||||||||||
| 89 | 0 | push @books, Net::Safari::Response::Book->new(%$book); | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | 0 | $self->{_books} = \@books; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =head2 books() | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 0 | ▶ | sub books { | ||||||||||||||||||
|
Subroutine
books: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 100 | 0 | my $self = shift; | |||||||||||||||||||
| 101 | 0 | ▶ | if ($self->{_books}) { return @{$self->{_books}}; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 0 | else { return (); } | |||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | ▶ | sub sections { | ||||||||||||||||||
|
Subroutine
sections: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | sub as_xml { | ||||||||||||||||||
|
Subroutine
as_xml: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 110 | 0 | my $self = shift; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | return $self->raw_response(); | |||||||||||||||||||
| 113 | } | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =head1 BUGS | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =head1 SUPPORT | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =head1 AUTHOR | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | Tony Stubblebine | ||||||||||||||||||||
| 127 | cpan@tonystubblebine.com | ||||||||||||||||||||
| 128 | http://www.tonystubblebine.com/ | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | =head1 COPYRIGHT | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | This program is free software; you can redistribute | ||||||||||||||||||||
| 133 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | The full text of the license can be found in the | ||||||||||||||||||||
| 136 | LICENSE file included with this module. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | =head1 SEE ALSO | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | perl(1). | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 13 | 1; #this line is important and will help the module return a true value | |||||||||||||||||||
| 147 | __END__ | ||||||||||||||||||||