DataAPI/Auth/ClientLogin/Multiple.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 8 / 8 Conditioncond 77.7% 7 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 91.6% 66 / 72 CC 9 SCAR 14.4
CC
9
Cov
97%
_get_auth_params
7.0
sign_request
3.0
BEGIN
1.0
CRAP 4.2
« DataAPI/Role/Service.pm ↑ Summary DataAPI.pm »
1 package Net::Google::DataAPI::Auth::ClientLogin::Multiple;
2 1 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Net::Google::AuthSub;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Text::Glob;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 with 'Net::Google::DataAPI::Role::Auth';
6  
7 1 our $VERSION = '0.05';
8  
9 1 has account_type => ( is => 'ro', isa => 'Str', required => 1, default => 'HOSTED_OR_GOOGLE' );
10 1 has source => ( is => 'ro', isa => 'Str', required => 1, default => __PACKAGE__ );
11 1 has username => ( is => 'ro', isa => 'Str', required => 1 );
12 1 has password => ( is => 'ro', isa => 'Str', required => 1 );
13 1 has services => ( is => 'ro', isa => 'HashRef', required => 1 );
14 1 ▶has tokens => ( is => 'rw', isa => 'HashRef', default => sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 sub sign_request {
17 7 ▶ my ($self, $req, $host) = @_;
Subroutine sign_request: called CC=3 SCAR=11.0
Pod undocumented
18 7 ▶ $host ||= $req->uri->host;
Condition66%2/3
$host ||= $req->uri->host
l!l&&r!l&&!r
160
MC/DC0%0/2
$host ||= $req->uri->host
$host $req->uri->host
Truth table66%2/3
A ||= B
A= $hostB= $req->uri->host
ABresult
1X1
011
000
19 7 ▶ $self->tokens->{$host} ||= $self->_get_auth_params($host);
Condition100%3/3
$self->tokens->{$host} ||= $self->_get_auth_params($host)
l!l&&r!l&&!r
241
MC/DC100%2/2
$self->tokens->{$host} ||= $self->_get_auth_params($host)
$self->tokens->{$host} $self->_get_auth_params($host)
Truth table100%3/3
A ||= B
A= $self->tokens->{$host}B= $self->_get_auth_params($host)
ABresult
1X1
011
000
20 5 $req->header(@{$self->tokens->{$host}});
21 5 return $req;
22 }
23  
24 sub _get_auth_params {
25 5 ▶ my ($self, $host) = @_;
Subroutine _get_auth_params: called CC=7 SCAR=19.5
26 5 my $service = $self->services->{$host};
27 5 ▶ unless ($service) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($service) 2 3 5
28 2 for my $s (grep {$_ =~ m/\*/} keys %{$self->services}) {
29 Text::Glob::match_glob($s, $host)
30 2 ▶ and $service = $self->services->{$s} and last;
Branch: 1 branch
BranchTrueFalseTotal
Text::Glob::match_glob($s, $host) and $service = $self->services->{$s} and last 1 1 2
Condition66%2/3
Text::Glob::match_glob($s, $host) and $service = $self->services->{$s}
!ll&&!rl&&r
101
MC/DC50%1/2
Text::Glob::match_glob($s, $host) and $service = $self->services->{$s}
Text::Glob::match_glob($s, $host) $service = $self->services->{$s}
Truth table66%2/3
A and B
A= Text::Glob::match_glob($s, $host)B= $service = $self->services->{$s}
ABresult
0X0
100
111
31 }
32 }
33 5 ▶ $service or confess "service for $host not defined";
Branch: 1 branch
BranchTrueFalseTotal
$service or confess("service for $host not defined") 1 4 5
34 4 my $authsub = Net::Google::AuthSub->new(
35 source => $self->source,
36 service => $service,
37 accountType => $self->account_type,
38 _compat => {uncuddled_auth => 1}, #to export docs
39 );
40 4 my $res = $authsub->login(
41 $self->username,
42 $self->password,
43 );
44 4 ▶ $res->is_success or confess "login for $host failed";
Branch: 1 branch
BranchTrueFalseTotal
$res->is_success or confess("login for $host failed") 1 3 4
45 3 return [ $authsub->auth_params ];
46 }
47  
48 1 __PACKAGE__->meta->make_immutable;
49  
50 1 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 1 1;
53 __END__
54  
55 =head1 NAME
56  
57 Net::Google::DataAPI::Auth::ClientLogin::Multiple - keeps and sings auth_params for multiple Google Data API domains
58  
59 =head1 SYNOPSIS
60  
61 use Net::Google::DataAPI::Auth::ClientLogin::Multiple;
62  
63 my $auth = Net::Google::DataAPI::Auth::ClientLogin::Multiple->new(
64 username => 'foo.bar@gmail.com',
65 password => 'p4ssw0rd',
66 services => {
67 'docs.google.com' => 'writely',
68 'spreadsheets.google.com' => 'wise',
69 }
70 );
71 my $req = HTTP::Request->new(
72 'GET' => 'https://docs.google.com/feeds/default/private/full'
73 );
74 $auth->sign_request($req);
75 # sets $req Authorization header
76  
77 $auth->sign_request($req, 'spreadsheets.google.com');
78 # set authorization header for 'spreadsheets.google.com', not for 'docs.google.com'.
79  
80 =head1 DESCRIPTION
81  
82 This module keeps and sings auth_params for multiple google Data API domains.
83  
84 =head1 AUTHOR
85  
86 Nobuo Danjou E<lt>danjou@soffritto.orgE<gt>
87  
88 =head1 SEE ALSO
89  
90 L<Net::Google::AuthSub>
91  
92 L<Net::Google::DataAPI>
93  
94 L<http://code.google.com/intl/en/apis/accounts/docs/AuthForInstalledApps.html>
95  
96 L<http://code.google.com/intl/en/apis/gdata/faq.html#clientlogin>
97  
98 =head1 LICENSE
99  
100 This library is free software; you can redistribute it and/or modify
101 it under the same terms as Perl itself.
102  
103 =cut
« DataAPI/Role/Service.pm ↑ Summary DataAPI.pm »