blib/lib/OAuth/Simple.pm

filter: Statementstmt 26.2% 16 / 61 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 44.4% 4 / 9 Podpod 100% 5 / 5 totaltotal 15.4% 25 / 162 CC 29 SCAR 40.3
CC
29
Cov
13%
request_data
110.0
request_access_token
56.0
new
42.0
CRAP 56.2
↑ Summary
1 package OAuth::Simple;
2  
3 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 require LWP::UserAgent;
9 2 require JSON;
10 2 require Carp;
11  
12 2 our $VERSION = '1.03';
13  
14  
15 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
16 0 my $class = shift;
17 0 my $self = bless {@_}, $class;
18  
19 Carp::croak("app_id, secret and postback required for this action")
20 0 ▶ unless ($self->{app_id} && $self->{secret} && $self->{postback});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"app_id"} and $self->{"secret"} and $self->{"postback"} 0 0 0
Condition0%0/6
$self->{"app_id"} and $self->{"secret"} and $self->{"postback"}
!ll&&!rl&&r
000
$self->{"app_id"} and $self->{"secret"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"app_id"} and $self->{"secret"} and $self->{"postback"}
$self->{"app_id"} $self->{"secret"} $self->{"postback"}
Truth table0%0/4
A and B and C
A= $self->{"app_id"}B= $self->{"secret"}C= $self->{"postback"}
ABCresult
0XX0
10X0
1100
1111
21  
22 0 ▶ $self->{ua} ||= LWP::UserAgent->new();
Condition0%0/3
$self->{"ua"} ||= "LWP::UserAgent"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"ua"} ||= "LWP::UserAgent"->new
$self->{"ua"} "LWP::UserAgent"->new
Truth table0%0/3
A ||= B
A= $self->{"ua"}B= "LWP::UserAgent"->new
ABresult
1X1
011
000
23 0 ▶ $self->{json} ||= JSON->new;
Condition0%0/3
$self->{"json"} ||= "JSON"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"json"} ||= "JSON"->new
$self->{"json"} "JSON"->new
Truth table0%0/3
A ||= B
A= $self->{"json"}B= "JSON"->new
ABresult
1X1
011
000
24  
25 0 return $self;
26 }
27  
28  
29 0 ▶sub authorize {
Subroutine authorize: not called CC=4 SCAR=30.0
Pod documented
30 0 my ($self, $params) = @_;
31  
32 0 ▶ my %params; %params = %$params if $params && %$params;
Branch: 1 branch
BranchTrueFalseTotal
if $params and %$params 0 0 0
Condition0%0/3
$params and %$params
!ll&&!rl&&r
000
MC/DC0%0/2
$params and %$params
$params %$params
Truth table0%0/3
A and B
A= $paramsB= %$params
ABresult
0X0
100
111
33  
34 0 my $url = delete $params{url};
35 0 ▶ Carp::croak("Authorize method URL required for this action") unless ($url);
Branch: 1 branch
BranchTrueFalseTotal
unless $url 0 0 0
36 0 $url = URI->new($url);
37 $url->query_form(
38 client_id => $self->{app_id},
39 redirect_uri => $self->{postback},
40 0 %params,
41 );
42  
43 0 return $url;
44 }
45  
46 0 ▶sub request_access_token {
Subroutine request_access_token: not called CC=7 SCAR=40.3
Pod documented
47 0 my ( $self, $params ) = @_;
48  
49 0 ▶ my %params; %params = %$params if $params && %$params;
Branch: 1 branch
BranchTrueFalseTotal
if $params and %$params 0 0 0
Condition0%0/3
$params and %$params
!ll&&!rl&&r
000
MC/DC0%0/2
$params and %$params
$params %$params
Truth table0%0/3
A and B
A= $paramsB= %$params
ABresult
0X0
100
111
50  
51 0 my ( $url, $code, $raw, $http_method ) = delete @params{ qw(url code raw http_method) };
52 0 ▶ Carp::croak("code and url required for this action") unless $code && $url;
Branch: 1 branch
BranchTrueFalseTotal
unless $code and $url 0 0 0
Condition0%0/3
$code and $url
!ll&&!rl&&r
000
MC/DC0%0/2
$code and $url
$code $url
Truth table0%0/3
A and B
A= $codeB= $url
ABresult
0X0
100
111
53  
54 my $response = $self->{ua}->request($self->prepare_http_request(
55 url => $url,
56 http_method => $http_method,
57 params => {
58 client_secret => $self->{secret},
59 client_id => $self->{app_id},
60 code => $code,
61 redirect_uri => $self->{postback},
62 0 %params,
63 },
64 ));
65  
66 0 ▶ return $response->decoded_content unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
67 0 ▶ return $response->content if $raw;
Branch: 1 branch
BranchTrueFalseTotal
if $raw 0 0 0
68 0 return $self->{json}->decode($response->content);
69 }
70  
71 0 ▶sub request_data {
Subroutine request_data: not called CC=10 SCAR=47.0
Pod documented
72 0 my ( $self, $params ) = @_;
73  
74 0 ▶ my %params; %params = %$params if $params && %$params;
Branch: 1 branch
BranchTrueFalseTotal
if $params and %$params 0 0 0
Condition0%0/3
$params and %$params
!ll&&!rl&&r
000
MC/DC0%0/2
$params and %$params
$params %$params
Truth table0%0/3
A and B
A= $paramsB= %$params
ABresult
0X0
100
111
75  
76 my ( $url, $access_token, $raw, $http_method, $token_name ) =
77 0 delete @params{ qw(url access_token raw http_method token_name) };
78 0 ▶ Carp::croak("url required for this action")
Branch: 1 branch
BranchTrueFalseTotal
unless $url 0 0 0
79 unless ($url);
80 Carp::croak("access_token required for this action")
81 0 ▶ unless ($access_token || $self->{no_token});
Branch: 1 branch
BranchTrueFalseTotal
unless $access_token or $self->{"no_token"} 0 0 0
Condition0%0/3
$access_token or $self->{"no_token"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$access_token or $self->{"no_token"}
$access_token $self->{"no_token"}
Truth table0%0/3
A or B
A= $access_tokenB= $self->{"no_token"}
ABresult
1X1
011
000
82  
83  
84 my $response = $self->{ua}->request($self->prepare_http_request(
85 url => $url,
86 http_method => $http_method,
87 params => {
88 0 ▶ $self->{no_token} ? () : ( ($token_name || 'access_token') => $access_token ),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'no_token'} ? : 0 0 0
Condition0%0/2
$token_name or "access_token"
l!l
00
MC/DC0%0/1
$token_name or "access_token"
$token_name
Truth table0%0/2
A
A= $token_name
Aresult
11
00
89 %params
90 },
91 ));
92
93 0 ▶ return 0 unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
94 0 ▶ return $response->content if $raw;
Branch: 1 branch
BranchTrueFalseTotal
if $raw 0 0 0
95 0 return $self->{json}->decode($response->content);
96 }
97  
98 0 ▶sub prepare_http_request {
Subroutine prepare_http_request: not called CC=6 SCAR=37.4
Pod documented
99 0 my ( $self, %params ) = @_;
100
101 0 ▶ $params{http_method} ||= 'GET';
Condition0%0/2
$params{"http_method"} ||= "GET"
l!l
00
MC/DC0%0/1
$params{"http_method"} ||= "GET"
$params{"http_method"}
Truth table0%0/2
A
A= $params{"http_method"}
Aresult
11
00
102  
103 0 my $req;
104 0 ▶ if ($params{http_method} eq 'GET') {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'http_method'} eq 'GET') { } 0 0 0
105 0 my $url = URI->new($params{url});
106 0 ▶ $url->query_form( %{$params{params}} ) if $params{params};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"params"} 0 0 0
107 0 $req = GET $url;
108 }
109 else {
110 $req = POST $params{url},
111 0 $self->{headers} && %{ $self->{headers} } ? %{ $self->{headers} } : (),
112 0 ▶ Content => $params{params};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'headers'} && %{$self->{'headers'};} ? : 0 0 0
Condition0%0/3
$self->{"headers"} and %{$self->{"headers"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"headers"} and %{$self->{"headers"};}
$self->{"headers"} %{$self->{"headers"};}
Truth table0%0/3
A and B
A= $self->{"headers"}B= %{$self->{"headers"};}
ABresult
0X0
100
111
113 }
114  
115 0 return $req;
116 }
117  
118  
119 2 1;
120  
121  
122 __END__
↑ Summary