API.pm

filter: Statementstmt 44.1% 15 / 34 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 45.6% 21 / 46 CC 3 SCAR 12.5
CC
3
Cov
39%
new
6.0
do
6.0
BEGIN
1.0
CRAP 3.5
« API/Account/ProgrammaticLogin.pm ↑ Summary API/Account.pm »
1 package WWW::Google::API;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 WWW::Google::API - Perl client to the Google API C<< <http://code.google.com/apis/> >>
9  
10 =head1 VERSION
11  
12 version 0.003
13  
14 $Id$
15  
16 =head1 SYNOPSIS
17  
18 A base Google API client.
19  
20 You probably want one of the subclasses of this module L<WWW::Google::API::Base>
21  
22 =cut
23  
24 2 our $VERSION = '0.003';
25  
26 2 ▶use base qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30  
31 2 __PACKAGE__->mk_accessors(qw(ua token auth_client));
32  
33 =head1 METHODS
34  
35 =head2 new
36  
37 Create a new client.
38  
39 =cut
40  
41 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
42 0 my $class = shift;
43 0 my $service = shift;
44 0 my $connection = shift;
45 0 my $lwp_cnf = shift;
46
47
48 0 my $auth_class = 'WWW::Google::API::Account::'.$connection->{auth_type};
49 0 ▶ eval "require $auth_class" or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $auth_class" or die $@ 0 0 0
50
51 0 my $self = { ua => LWP::UserAgent->new( agent => 'WWW::Google::API',
52 %$lwp_cnf ) };
53
54 0 bless($self, $class);
55  
56 0 $self->ua->default_header( 'X-Google-Key' => $connection->{api_key} );
57
58 0 $self->auth_client("$auth_class"->new($self->ua));
59
60 0 $self->token( $self->auth_client->authenticate( ( { service => $service,
61 %$connection
62 },
63 )
64 )
65 );
66 0 $self->ua->default_header( 'Authorization' => "GoogleLogin auth=" . $self->token );
67
68 0 return $self;
69 }
70  
71 =head2 do
72  
73 Execute some action with the client.
74  
75 =cut
76  
77 0 ▶sub do {
Subroutine do: not called CC=2 SCAR=17.9
Pod documented
78 0 my $self = shift;
79 0 my $request = shift;
80  
81 0 my $response = $self->ua->request($request);
82  
83 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
84 0 return $response;
85 } else {
86 0 die $response;
87 }
88 }
89  
90 =head1 AUTHOR
91  
92 John Cappiello, C<< <jcap@cpan.org> >>
93  
94 =head1 BUGS
95  
96 L<http://rt.cpan.org/Public/Dist/Display.html?Name=WWW-Google-API>
97  
98 =head1 COPYRIGHT
99  
100 Copyright 2006-2007 John Cappiello, all rights reserved.
101  
102 This program is free software; you may redistribute it and/or modify it
103 under the same terms as Perl itself.
104  
105 =cut
106  
107 2 1;
« API/Account/ProgrammaticLogin.pm ↑ Summary API/Account.pm »