Lite/Response.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 10 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 96.9% 63 / 65 SCAR 20.8
CC
8
Cov
98%
from_encoded
7.0
param
2.0
BEGIN
1.0
CRAP 8.0
« Lite/Token.pm ↑ Summary Lite/Agent.pm »
1 package OAuth::Lite::Response;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use OAuth::Lite::Util qw(decode_param);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 __PACKAGE__->mk_accessors(qw/token/);
11  
12 5 ▶use OAuth::Lite::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 OAuth::Lite::Response - response class
17  
18 =head1 SYNOPSIS
19  
20 my $res = $consumer->obtain_access_token(
21 ...
22 );
23  
24 my $token = $res->token;
25 say $token->token;
26 say $token->secret;
27  
28 my $other_param = $res->param('xauth_expires');
29  
30 =head1 DESCRIPTION
31  
32 Response class
33  
34 =head1 METHODS
35  
36 =head2 new
37  
38 =cut
39  
40 sub new {
41 6 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
42 6 bless {
43 _params => {},
44 token => undef,
45 }, $class;
46 }
47  
48 =head2 from_encoded
49  
50 Generate response from encoded line (that service provider provides as response of request token.).
51  
52 my $line = "oauth_token=foo&oauth_token_secret=bar&xauth_expires=0";
53 my $res = OAuth::Lite::Response->from_encoded($encoded);
54  
55 my $token = $res->token;
56 say $token->token;
57 say $token->secret;
58  
59 say $res->param('xauth_expires');
60  
61 =cut
62  
63 sub from_encoded {
64 6 ▶ my ($class, $encoded) = @_;
Subroutine from_encoded: called CC=7 SCAR=19.5
Pod documented
65 6 $encoded =~ s/\r\n$//;
66 6 $encoded =~ s/\n$//;
67 6 my $res = $class->new;
68 6 my $token = OAuth::Lite::Token->new;
69 6 for my $pair (split /&/, $encoded) {
70 16 my ($key, $val) = split /=/, $pair;
71 16 ▶ if ($key eq 'oauth_token') {
Branch: 3 branches
BranchTrueFalseTotal
if ($key eq 'oauth_token') { } 6 10 16
elsif ($key eq 'oauth_token_secret') { } 6 4 10
elsif ($key eq 'oauth_callback_confirmed') { } 3 1 4
72 6 $token->token(decode_param($val));
73 } elsif ($key eq 'oauth_token_secret') {
74 6 $token->secret(decode_param($val));
75 } elsif ($key eq 'oauth_callback_confirmed') {
76 3 my $p = decode_param($val);
77 3 ▶ if ($p && $p eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($p and $p eq "true") 1 2 3
Condition66%2/3
$p and $p eq "true"
!ll&&!rl&&r
021
MC/DC50%1/2
$p and $p eq "true"
$p $p eq "true"
Truth table66%2/3
A and B
A= $pB= $p eq "true"
ABresult
0X0
100
111
78 1 $token->callback_confirmed(1);
79 }
80 } else {
81 1 $res->param($key, decode_param($val));
82 }
83 }
84 6 $res->token($token);
85 6 $res;
86 }
87  
88 =head2 param
89  
90 Get parameter.
91  
92 say $res->param('xauth_expires');
93  
94 =cut
95  
96 sub param {
97 3 ▶ my ($self, $key, $value) = @_;
Subroutine param: called CC=2 SCAR=6.9
Pod documented
98 3 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1 2 3
99 1 $self->{_params}{$key} = $value;
100 }
101 3 $self->{_params}{$key};
102 }
103  
104 =head1 AUTHOR
105  
106 Lyo Kato, C<lyo.kato _at_ gmail.com>
107  
108 =head1 COPYRIGHT AND LICENSE
109  
110 This library is free software; you can redistribute it and/or modify
111 it under the same terms as Perl itself, either Perl version 5.8.6 or,
112 at your option, any later version of Perl 5 you may have available.
113  
114 =cut
115  
116  
117 5 1;
118  
« Lite/Token.pm ↑ Summary Lite/Agent.pm »