| 1 | =head1 NAME | ||||||||||
| 2 | |||||||||||
| 3 | Net::Google::Service - SOAP widget(s) for Net::Google | ||||||||||
| 4 | |||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||
| 6 | |||||||||||
| 7 | use Net::Google::Service; | ||||||||||
| 8 | my $search = Net::Google::Service->search({debug=>1}); | ||||||||||
| 9 | |||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||
| 11 | |||||||||||
| 12 | SOAP widget(s) for Net::Google | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | package Net::Google::Service; | ||||||||||
| 17 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 3 | $Net::Google::Service::VERSION = '1.0'; | |||||||||
| 20 | |||||||||||
| 21 | 3 | ▶ | use SOAP::Lite; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | # This clever hack is courtesy Matt Webb: | ||||||||||
| 25 | # http://interconnected.org/home/more/GoogleSearch.pl.txt | ||||||||||
| 26 | |||||||||||
| 27 | # Redefine how the default deserializer handles booleans. | ||||||||||
| 28 | # Workaround because the 1999 schema implementation incorrectly doesn't | ||||||||||
| 29 | # accept "true" and "false" for boolean values. | ||||||||||
| 30 | # See http://groups.yahoo.com/group/soaplite/message/895 | ||||||||||
| 31 | |||||||||||
| 32 | 3 | *SOAP::XMLSchema1999::Deserializer::as_boolean = | |||||||||
| 33 | *SOAP::XMLSchemaSOAP1_1::Deserializer::as_boolean = | ||||||||||
| 34 | \&SOAP::XMLSchema2001::Deserializer::as_boolean; | ||||||||||
| 35 | |||||||||||
| 36 | 3 | ▶ | use constant SERVICES => { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | "cache" => "GoogleSearch.wsdl", | ||||||||||
| 38 | "search" => "GoogleSearch.wsdl", | ||||||||||
| 39 | "spelling" => "GoogleSearch.wsdl", | ||||||||||
| 40 | 3 | }; | |||||||||
| 41 | |||||||||||
| 42 | 3 | ▶ | use constant SERVICE_CACHE => {}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | |||||||||||
| 44 | =head1 PACKAGE METHODS | ||||||||||
| 45 | |||||||||||
| 46 | =head2 __PACKAGE__->search(\%args) | ||||||||||
| 47 | |||||||||||
| 48 | =cut | ||||||||||
| 49 | |||||||||||
| 50 | 1 | ▶ | sub search { | ||||||||
|
Subroutine
search: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 51 | 1 | my $pkg = shift; | |||||||||
| 52 | 1 | return $pkg->_soap("search",@_); | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | =head2 __PACKAGE__->spelling(\%args) | ||||||||||
| 56 | |||||||||||
| 57 | =cut | ||||||||||
| 58 | |||||||||||
| 59 | 1 | ▶ | sub spelling { | ||||||||
|
Subroutine
spelling: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 60 | 1 | my $pkg = shift; | |||||||||
| 61 | 1 | return $pkg->_soap("spelling",@_); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | =head2 __PACKAGE_->cache(\%args) | ||||||||||
| 65 | |||||||||||
| 66 | =cut | ||||||||||
| 67 | |||||||||||
| 68 | 1 | ▶ | sub cache { | ||||||||
|
Subroutine
cache: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 69 | 1 | my $pkg = shift; | |||||||||
| 70 | 1 | return $pkg->_soap("cache",@_); | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | # Private methods | ||||||||||
| 74 | |||||||||||
| 75 | 3 | ▶ | sub _soap { | ||||||||
|
Subroutine
_soap: called CC=4 SCAR=25.7
| |||||||||||
| 76 | 3 | my $pkg = shift; | |||||||||
| 77 | 3 | my $service = shift; | |||||||||
| 78 | 3 | my $args = shift; | |||||||||
| 79 | |||||||||||
| 80 | 3 | my $soap = SOAP::Lite->service("file:".__PACKAGE__->_service($service)); | |||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | if ($args->{'http_proxy'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | # Get the SOAP transport object | ||||||||||
| 84 | # Then get its proxy object (note the args) | ||||||||||
| 85 | # Which is really just an LWP::UserAgent | ||||||||||
| 86 | # so we get that and set the args (again) | ||||||||||
| 87 | 0 | $soap->transport()->proxy($args->{'http_proxy'})->proxy(http=>$args->{'http_proxy'}); | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | if ($args->{'debug'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | ▶ | SOAP::Trace->import(debug=>((ref($args->{debug}) eq "CODE") ? $args->{'debug'} : sub {print STDERR @_})); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | $soap->on_fault(sub{ | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 95 | 0 | my ($soap,$res) = @_; | |||||||||
| 96 | 0 | ▶ | my $err = (ref($res)) ? $res->faultstring() : $soap->transport()->status(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | carp $err; | |||||||||
| 98 | 0 | return undef; | |||||||||
| 99 | 0 | }); | |||||||||
| 100 | |||||||||||
| 101 | 0 | return $soap; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 3 | ▶ | sub _service { | ||||||||
|
Subroutine
_service: called CC=4 SCAR=15.9
| |||||||||||
| 105 | 3 | my $pkg = shift; | |||||||||
| 106 | 3 | my $service = shift; | |||||||||
| 107 | |||||||||||
| 108 | # This is not the droid you're looking for. | ||||||||||
| 109 | # We're talking to the constants this way | ||||||||||
| 110 | # for two reasons : | ||||||||||
| 111 | |||||||||||
| 112 | # 1) The SERVICE_CACHE->{foo} syntax causes Perl | ||||||||||
| 113 | # Perl 5.00502 to break since the "inlined | ||||||||||
| 114 | # subroutined-ness" of scalar constants | ||||||||||
| 115 | # https://rt.cpan.org/Ticket/Display.html?id=1753 | ||||||||||
| 116 | |||||||||||
| 117 | # 2) Rather than creating a whole bunch of separate | ||||||||||
| 118 | # subroutines to abstract away all the ($] > 5.00502) | ||||||||||
| 119 | # stuff, I might as well just tack the '&' on | ||||||||||
| 120 | # now and be done with it. | ||||||||||
| 121 | |||||||||||
| 122 | 3 | ▶ | if (exists &SERVICE_CACHE->{$service}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | return &SERVICE_CACHE->{$service} | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | 3 | foreach my $dir (@INC) { | |||||||||
| 127 | 27 | ▶ | if (-f "$dir/Net/Google/Services/".&SERVICES->{$service}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | 0 | &SERVICE_CACHE->{$service} = "$dir/Net/Google/Services/".&SERVICES->{$service}; | |||||||||
| 129 | 0 | return &SERVICE_CACHE->{$service}; | |||||||||
| 130 | } | ||||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | 3 | return undef; | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | =head1 VERSION | ||||||||||
| 137 | |||||||||||
| 138 | 1.0 | ||||||||||
| 139 | |||||||||||
| 140 | =head1 DATE | ||||||||||
| 141 | |||||||||||
| 142 | $Date: 2005/03/26 20:49:03 $ | ||||||||||
| 143 | |||||||||||
| 144 | =head1 AUTHOR | ||||||||||
| 145 | |||||||||||
| 146 | Aaron Straup Cope | ||||||||||
| 147 | |||||||||||
| 148 | =head1 SEE ALSO | ||||||||||
| 149 | |||||||||||
| 150 | L<Net::Google> | ||||||||||
| 151 | |||||||||||
| 152 | =head1 LICENSE | ||||||||||
| 153 | |||||||||||
| 154 | Copyright (c) 2002-2005, Aaron Straup Cope. All Rights Reserved. | ||||||||||
| 155 | |||||||||||
| 156 | This is free software, you may use it and distribute it under the same terms as Perl itself. | ||||||||||
| 157 | |||||||||||
| 158 | =cut | ||||||||||
| 159 | |||||||||||
| 160 | 3 | return 1; | |||||||||