OAuth/Message.pm

filter: Statementstmt 91.7% 221 / 241 Branchbran 79.7% 59 / 74 Conditioncond 64.5% 40 / 62 MC/DCmcdc 36.1% 13 / 36 Subroutinesub 95.0% 38 / 40 Podpod 3.7% 1 / 27 totaltotal 77.5% 372 / 480 CC 69 SCAR 18.9
CC
69
Cov
85%
gather_message_parameters
17.0
from_hash
10.2
_check_signature_method_allowed
8.1
CRAP 6.6
↑ Summary OAuth/Client.pm »
1 package Net::OAuth::Message;
2 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use base qw/Class::Data::Inheritable Class::Accessor/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use Net::OAuth;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 14 ▶use constant OAUTH_PREFIX => 'oauth_';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 14 our $OAUTH_PREFIX_RE = do {my $p = OAUTH_PREFIX; qr/^$p/};
14  
15 14 __PACKAGE__->mk_classdata(extension_param_patterns => []);
16  
17 21 ▶sub add_required_message_params {
Subroutine add_required_message_params: called CC=1 SCAR=0.0
Pod undocumented
18 21 my $class = shift;
19 21 $class->required_message_params([@{$class->required_message_params}, @_]);
20 21 $class->all_message_params([@{$class->all_message_params}, @_]);
21 21 $class->all_params([@{$class->all_params}, @_]);
22 21 $class->mk_accessors(@_);
23 }
24  
25 0 ▶sub add_optional_message_params {
Subroutine add_optional_message_params: not called CC=1 SCAR=6.9
Pod undocumented
26 0 my $class = shift;
27 0 $class->optional_message_params([@{$class->optional_message_params}, @_]);
28 0 $class->all_message_params([@{$class->all_message_params}, @_]);
29 0 $class->all_params([@{$class->all_params}, @_]);
30 0 $class->mk_accessors(@_);
31 }
32  
33 11 ▶sub add_required_api_params {
Subroutine add_required_api_params: called CC=1 SCAR=0.0
Pod undocumented
34 11 my $class = shift;
35 11 $class->required_api_params([@{$class->required_api_params}, @_]);
36 11 $class->all_api_params([@{$class->all_api_params}, @_]);
37 11 $class->all_params([@{$class->all_params}, @_]);
38 11 $class->mk_accessors(@_);
39 }
40  
41 1 ▶sub add_extension_param_pattern {
Subroutine add_extension_param_pattern: called CC=1 SCAR=0.0
Pod undocumented
42 1 my $class = shift;
43 1 $class->extension_param_patterns([@{$class->extension_param_patterns}, @_]);
44 }
45  
46 0 ▶sub add_to_signature {
Subroutine add_to_signature: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my $class = shift;
48 0 $class->signature_elements([@{$class->signature_elements}, @_]);
49 }
50  
51 54 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
52 54 my $proto = shift;
53 54 ▶ my $class = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0540
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
54 54 my %params = @_;
55 54 $class = get_versioned_class($class, \%params);
56 54 my $self = bless \%params, $class;
57 54 $self->set_defaults;
58 54 $self->check;
59 51 return $self;
60 }
61  
62 63 ▶sub get_versioned_class {
Subroutine get_versioned_class: called CC=6 SCAR=18.0
Pod undocumented
63 63 my $class = shift;
64 63 my $params = shift;
65 63 ▶ my $protocol_version = $params->{protocol_version} || $Net::OAuth::PROTOCOL_VERSION;
Condition66%2/3
$params->{'protocol_version'} || $Net::OAuth::PROTOCOL_VERSION
l!l&&r!l&&!r
7560
MC/DC0%0/2
$params->{'protocol_version'} || $Net::OAuth::PROTOCOL_VERSION
$params->{'protocol_version'} $Net::OAuth::PROTOCOL_VERSION
Truth table66%2/3
A || B
A= $params->{'protocol_version'}B= $Net::OAuth::PROTOCOL_VERSION
ABresult
1X1
011
000
66 63 ▶ if (defined $protocol_version and $protocol_version == Net::OAuth::PROTOCOL_VERSION_1_0A and $class !~ /\::V1_0A\::/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $protocol_version and $protocol_version == "1.001" and not $class =~ /\::V1_0A\::/) 13 50 63
Condition83%5/6
defined $protocol_version and $protocol_version == "1.001" and not $class =~ /\::V1_0A\::/
!ll&&!rl&&r
46413
defined $protocol_version and $protocol_version == "1.001"
!ll&&!rl&&r
04617
MC/DC66%2/3
defined $protocol_version and $protocol_version == "1.001" and not $class =~ /\::V1_0A\::/
defined $protocol_version $protocol_version == "1.001" not $class =~ /\::V1_0A\::/
Truth table75%3/4
A and B and not(C)
A= defined $protocol_versionB= $protocol_version == "1.001"C= not $class =~ /\::V1_0A\::/
ABCresult
0XX0
10X0
1100
1111
67 13 (my $versioned_class = $class) =~ s/::(\w+)$/::V1_0A::$1/;
68 13 ▶ return $versioned_class if Net::OAuth::smart_require($versioned_class);
Branch: 1 branch
BranchTrueFalseTotal
if Net::OAuth::smart_require($versioned_class) 11 2 13
69 }
70 52 return $class;
71 }
72  
73 54 ▶sub set_defaults {
Subroutine set_defaults: called CC=4 SCAR=13.9
Pod undocumented
74 54 my $self = shift;
75 54 ▶ $self->{extra_params} ||= {};
Condition100%2/2
$self->{"extra_params"} ||= {}
l!l
1737
MC/DC100%1/1
$self->{"extra_params"} ||= {}
$self->{"extra_params"}
Truth table100%2/2
A
A= $self->{"extra_params"}
Aresult
11
00
76 54 ▶ $self->{version} ||= Net::OAuth::OAUTH_VERSION unless $self->{from_hash};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"from_hash"} 46 8 54
Condition50%1/2
$self->{"version"} ||= "1.0"
l!l
046
MC/DC0%0/1
$self->{"version"} ||= "1.0"
$self->{"version"}
Truth table50%1/2
A
A= $self->{"version"}
Aresult
11
00
77 }
78  
79 552 ▶sub is_extension_param {
Subroutine is_extension_param: called CC=1 SCAR=0.0
Pod undocumented
80 552 my $self = shift;
81 552 my $param = shift;
82 552 return grep ($param =~ $_, @{$self->extension_param_patterns});
83 }
84  
85 54 ▶sub check {
Subroutine check: called CC=7 SCAR=19.7
Pod undocumented
86 54 my $self = shift;
87 54 foreach my $k (@{$self->required_message_params}, @{$self->required_api_params}) {
88 370 ▶ if (not defined $self->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$k}) 3 367 370
89 3 croak "Missing required parameter '$k'";
90 }
91 }
92 51 ▶ if ($self->{extra_params} and $self->allow_extra_params) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_params"} and $self->allow_extra_params) 44 7 51
Condition66%2/3
$self->{"extra_params"} and $self->allow_extra_params
!ll&&!rl&&r
0744
MC/DC50%1/2
$self->{"extra_params"} and $self->allow_extra_params
$self->{"extra_params"} $self->allow_extra_params
Truth table66%2/3
A and B
A= $self->{"extra_params"}B= $self->allow_extra_params
ABresult
0X0
100
111
93 44 foreach my $k (keys %{$self->{extra_params}}) {
94 24 ▶ if ($k =~ $OAUTH_PREFIX_RE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /$Net::OAuth::Message::OAUTH_PREFIX_RE/) 0 24 24
95 0 croak "Parameter '$k' not allowed in arbitrary params"
96 }
97 }
98 }
99 }
100  
101 1552 ▶sub encode {
Subroutine encode: called CC=5 SCAR=16.1
Pod undocumented
102 1552 my $str = shift;
103 1552 ▶ $str = "" unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 29 1523 1552
104 1552 ▶ unless($Net::OAuth::SKIP_UTF8_DOUBLE_ENCODE_CHECK) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Net::OAuth::SKIP_UTF8_DOUBLE_ENCODE_CHECK) 1552 0 1552
105 1552 ▶ if ($str =~ /[\x80-\xFF]/ and !utf8::is_utf8($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /[\x80-\xFF]/ and not utf8::is_utf8($str)) 1 1551 1552
Condition100%3/3
$str =~ /[\x80-\xFF]/ and not utf8::is_utf8($str)
!ll&&!rl&&r
154921
MC/DC100%2/2
$str =~ /[\x80-\xFF]/ and not utf8::is_utf8($str)
$str =~ /[\x80-\xFF]/ not utf8::is_utf8($str)
Truth table100%3/3
A and not(B)
A= $str =~ /[\x80-\xFF]/B= not utf8::is_utf8($str)
ABresult
0X0
100
111
106 1 warn "Net::OAuth warning: your OAuth message appears to contain some multi-byte characters that need to be decoded via Encode.pm or a PerlIO layer first. This may result in an incorrect signature.";
107 }
108 }
109 1552 return URI::Escape::uri_escape_utf8($str);
110 }
111  
112 62 ▶sub decode {
Subroutine decode: called CC=1 SCAR=0.0
Pod undocumented
113 62 my $str = shift;
114 62 return uri_unescape($str);
115 }
116  
117 46 ▶sub allow_extra_params {1}
Subroutine allow_extra_params: called CC=1 SCAR=0.0
Pod undocumented
118  
119 10 ▶sub sign_message {0}
Subroutine sign_message: called CC=1 SCAR=0.0
Pod undocumented
120  
121 92 ▶sub gather_message_parameters {
Subroutine gather_message_parameters: called CC=17 SCAR=28.3
Pod undocumented
122 92 my $self = shift;
123 92 my %opts = @_;
124 92 ▶ $opts{quote} = "" unless defined $opts{quote};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"quote"} 88 4 92
125 92 ▶ $opts{params} ||= [];
Condition50%1/2
$opts{"params"} ||= []
l!l
092
MC/DC0%0/1
$opts{"params"} ||= []
$opts{"params"}
Truth table50%1/2
A
A= $opts{"params"}
Aresult
11
00
126 92 my %params;
127 92 foreach my $k (@{$self->required_message_params}, @{$self->optional_message_params}, @{$opts{add}}) {
128 617 ▶ next if $k eq 'signature' and (!$self->sign_message or !grep ($_ eq 'signature', @{$opts{add}}));
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "signature" and not $self->sign_message && grep(($_ eq "signature"), @{$opts{"add"};}) 67 550 617
Condition100%6/6
$k eq "signature" and not $self->sign_message && grep(($_ eq "signature"), @{$opts{"add"};})
!ll&&!rl&&r
5005067
$self->sign_message && grep(($_ eq 'signature'), @{$opts{'add'};})
!ll&&!rl&&r
105750
MC/DC100%3/3
$k eq "signature" and not $self->sign_message && grep(($_ eq "signature"), @{$opts{"add"};})
$k eq "signature" $self->sign_message grep(($_ eq 'signature'), @{$opts{'add'};})
Truth table100%4/4
A and not(B && C)
A= $k eq "signature"B= $self->sign_messageC= grep(($_ eq 'signature'), @{$opts{'add'};})
ABCresult
0XX0
1110
10X1
1101
129 550 ▶ my $message_key = $self->is_extension_param($k) ? $k : OAUTH_PREFIX . $k;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_extension_param($k) ? : 3 547 550
130 550 my $v = $self->$k;
131 550 ▶ $params{$message_key} = $v if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 549 1 550
132 }
133 92 ▶ if ($self->{extra_params} and !$opts{no_extra} and $self->allow_extra_params) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_params"} and not $opts{"no_extra"} and $self->allow_extra_params) 76 16 92
Condition83%5/6
$self->{"extra_params"} and not $opts{"no_extra"} and $self->allow_extra_params
!ll&&!rl&&r
41276
$self->{"extra_params"} and not $opts{"no_extra"}
!ll&&!rl&&r
0488
MC/DC66%2/3
$self->{"extra_params"} and not $opts{"no_extra"} and $self->allow_extra_params
$self->{"extra_params"} not $opts{"no_extra"} $self->allow_extra_params
Truth table75%3/4
A and not(B) and C
A= $self->{"extra_params"}B= not $opts{"no_extra"}C= $self->allow_extra_params
ABCresult
0XX0
10X0
1100
1111
134 76 foreach my $k (keys %{$self->{extra_params}}) {
135 45 $params{$k} = $self->{extra_params}{$k};
136 }
137 76 ▶ if ($self->can('request_url')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("request_url")) 66 10 76
138 66 my $url = $self->request_url;
139 66 _ensure_uri_object($url);
140 66 foreach my $k ($url->query_param) {
141 12 $params{$k} = $url->query_param($k);
142 }
143 }
144 }
145 92 ▶ if ($opts{hash}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"hash"}) 15 77 92
146 15 return \%params;
147 }
148 77 my @pairs;
149 77 ▶ while (my ($k,$v) = each %params) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %params) 483 77 560
150 483 push @pairs, join('=', encode($k), $opts{quote} . encode($v) . $opts{quote});
151 }
152 77 return sort(@pairs);
153 }
154  
155 57 ▶sub normalized_message_parameters {
Subroutine normalized_message_parameters: called CC=1 SCAR=0.0
Pod undocumented
156 57 my $self = shift;
157 57 return join('&', $self->gather_message_parameters);
158 }
159  
160 57 ▶sub signature_base_string {
Subroutine signature_base_string: called CC=1 SCAR=0.0
Pod undocumented
161 57 my $self = shift;
162 57 return join('&', map(encode($self->$_), @{$self->signature_elements}));
163 }
164  
165 35 ▶sub sign {
Subroutine sign: called CC=1 SCAR=0.0
Pod undocumented
166 35 my $self = shift;
167 35 my $class = $self->_signature_method_class;
168 35 $self->signature($class->sign($self, @_));
169 }
170  
171 29 ▶sub verify {
Subroutine verify: called CC=1 SCAR=0.0
Pod undocumented
172 29 my $self = shift;
173 29 $self->_check_signature_method_allowed;
174 25 my $class = $self->_signature_method_class;
175 25 return $class->verify($self, @_);
176 }
177  
178 # The signature method named in a message we are verifying was chosen by
179 # whoever sent that message, so on the verifying side it is untrusted
180 # input. Dispatching on it means the sender decides which key we check
181 # their signature against. The verifying party has to say which methods
182 # it is prepared to accept; anything else - including saying nothing at
183 # all - is refused before we dispatch.
184 29 ▶sub _check_signature_method_allowed {
Subroutine _check_signature_method_allowed: called CC=8 SCAR=20.9
185 29 my $self = shift;
186 29 my $allowed = $self->{allowed_signature_methods};
187 29 ▶ $allowed = \@Net::OAuth::ALLOWED_SIGNATURE_METHODS unless defined $allowed;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $allowed 25 4 29
188 29 ▶ unless (ref $allowed eq 'ARRAY' and @$allowed) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $allowed eq "ARRAY" and @$allowed) 1 28 29
Condition66%2/3
ref $allowed eq "ARRAY" and @$allowed
!ll&&!rl&&r
0128
MC/DC50%1/2
ref $allowed eq "ARRAY" and @$allowed
ref $allowed eq "ARRAY" @$allowed
Truth table66%2/3
A and B
A= ref $allowed eq "ARRAY"B= @$allowed
ABresult
0X0
100
111
189 1 croak "Cannot verify: no acceptable signature method has been stated. "
190 . "Pass allowed_signature_methods => [...] to this message, or set "
191 . "\@Net::OAuth::ALLOWED_SIGNATURE_METHODS, naming the method or "
192 . "methods this party expects. Verifying with the method the "
193 . "message itself names would let the sender choose the algorithm, "
194 . "and so the key";
195 }
196 28 my $named = $self->signature_method;
197 28 ▶ $named = '' unless defined $named;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $named 0 28 28
198 # compare on the same normalisation _signature_method_class resolves
199 # with, so 'HMAC-SHA1' and 'HMAC_SHA1' are not two different answers
200 28 (my $want = $named) =~ s/\W+/_/g;
201 28 foreach my $ok (@$allowed) {
202 38 ▶ next unless defined $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ok 0 38 38
203 38 (my $have = $ok) =~ s/\W+/_/g;
204 38 ▶ return if $have eq $want;
Branch: 1 branch
BranchTrueFalseTotal
if $have eq $want 25 13 38
205 }
206 croak "Signature method '$named' is not an allowed signature method ("
207 3 . join(', ', grep {defined} @$allowed) . ")";
208 }
209  
210 60 ▶sub _signature_method_class {
Subroutine _signature_method_class: called CC=2 SCAR=7.0
211 60 my $self = shift;
212 60 (my $signature_method = $self->signature_method) =~ s/\W+/_/g;
213 60 my $sm_class = 'Net::OAuth::SignatureMethod::' . $signature_method;
214 60 ▶ croak "Unable to load $signature_method plugin" unless Net::OAuth::smart_require($sm_class);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::OAuth::smart_require($sm_class) 0 60 60
215 60 return $sm_class;
216 }
217  
218 4 ▶sub to_authorization_header {
Subroutine to_authorization_header: called CC=3 SCAR=11.6
Pod undocumented
219 4 my $self = shift;
220 4 my $realm = shift;
221 4 ▶ my $sep = shift || ",";
Condition50%1/2
shift() || ','
l!l
40
MC/DC0%0/1
shift() || ','
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
222 4 ▶ if (defined $realm) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $realm) { } 4 0 4
223 4 $realm = "realm=\"$realm\"$sep";
224 }
225 else {
226 0 $realm = "";
227 }
228 4 return "OAuth $realm" .
229 join($sep, $self->gather_message_parameters(quote => '"', add => [qw/signature/], no_extra => 1));
230 }
231  
232 1 ▶sub from_authorization_header {
Subroutine from_authorization_header: called CC=4 SCAR=14.8
Pod undocumented
233 1 my $proto = shift;
234 1 my $header = shift;
235 1 ▶ my $class = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
236 1 ▶ croak "Header must start with \"OAuth \"" unless $header =~ s/OAuth //;
Branch: 1 branch
BranchTrueFalseTotal
unless $header =~ s/OAuth // 0 1 1
237 1 my @header = split /[\s]*,[\s]*/, $header;
238 1 ▶ shift @header if $header[0] =~ /^realm=/i;
Branch: 1 branch
BranchTrueFalseTotal
if $header[0] =~ /^realm=/i 1 0 1
239 1 return $class->_from_pairs(\@header, @_)
240 }
241  
242 4 ▶sub _from_pairs() {
Subroutine _from_pairs: called CC=5 SCAR=17.0
243 4 my $class = shift;
244 4 my $pairs = shift;
245 4 ▶ if (ref $pairs ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pairs ne "ARRAY") 0 4 4
246 0 croak 'Expected an array!';
247 }
248 4 my %params;
249 4 foreach my $pair (@$pairs) {
250 16 my ($k,$v) = split /=/, $pair;
251 16 ▶ if (defined $k and defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k and defined $v) 16 0 16
Condition33%1/3
defined $k and defined $v
!ll&&!rl&&r
0016
MC/DC0%0/2
defined $k and defined $v
defined $k defined $v
Truth table33%1/3
A and B
A= defined $kB= defined $v
ABresult
0X0
100
111
252 16 $v =~ s/(^"|"$)//g;
253 16 ($k,$v) = map decode($_), $k, $v;
254 16 $params{$k} = $v;
255 }
256 }
257 4 return $class->from_hash(\%params, @_);
258 }
259  
260 9 ▶sub from_hash {
Subroutine from_hash: called CC=8 SCAR=23.2
Pod undocumented
261 9 my $proto = shift;
262 9 ▶ my $class = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
090
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
263 9 my $hash = shift;
264 9 ▶ if (ref $hash ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash ne "HASH") 0 9 9
265 0 croak 'Expected a hash!';
266 }
267 9 my %api_params = @_;
268 # need to do this earlier than Message->new because
269 # the below validation step needs the correct class.
270 # https://rt.cpan.org/Public/Bug/Display.html?id=47293
271 9 $class = get_versioned_class($class, \%api_params);
272 9 my %msg_params;
273 9 foreach my $k (keys %$hash) {
274 47 ▶ if ($k =~ s/$OAUTH_PREFIX_RE//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($k =~ s/$Net::OAuth::Message::OAUTH_PREFIX_RE//) { } 45 2 47
elsif ($class->is_extension_param($k)) { } 0 2 2
275 45 ▶ if (!grep ($_ eq $k, @{$class->all_message_params})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not grep(($_ eq $k), @{$class->all_message_params;})) { } 1 44 45
276 1 croak "Parameter ". OAUTH_PREFIX ."$k not valid for a message of type $class";
277 }
278 else {
279 44 $msg_params{$k} = $hash->{OAUTH_PREFIX . $k};
280 }
281 }
282 elsif ($class->is_extension_param($k)) {
283 0 ▶ if (!grep ($_ eq $k, @{$class->all_message_params})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not grep(($_ eq $k), @{$class->all_message_params;})) { } 0 0 0
284 0 croak "Parameter $k not valid for a message of type $class";
285 }
286 else {
287 0 $msg_params{$k} = $hash->{$k};
288 }
289 }
290 else {
291 2 $msg_params{extra_params}->{$k} = $hash->{$k};
292 }
293 }
294 8 $api_params{from_hash} = 1;
295 8 return $class->new(%msg_params, %api_params);
296 }
297  
298 140 ▶sub _ensure_uri_object {
Subroutine _ensure_uri_object: called CC=2 SCAR=6.9
299 140 ▶ $_[0] = UNIVERSAL::isa($_[0], 'URI') ? $_[0] : URI->new($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], 'URI') ? : 23 117 140
300 }
301  
302 2 ▶sub from_url {
Subroutine from_url: called CC=2 SCAR=7.2
Pod undocumented
303 2 my $proto = shift;
304 2 ▶ my $class = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
305 2 my $url = shift;
306 2 _ensure_uri_object($url);
307 2 return $class->from_hash($url->query_form_hash, @_);
308 }
309  
310 16 ▶sub to_post_body {
Subroutine to_post_body: called CC=1 SCAR=0.0
Pod undocumented
311 16 my $self = shift;
312 16 return join('&', $self->gather_message_parameters(add => [qw/signature/]));
313 }
314  
315 3 ▶sub from_post_body {
Subroutine from_post_body: called CC=2 SCAR=7.4
Pod undocumented
316 3 my $proto = shift;
317 3 ▶ my $class = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
030
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
318 3 my @pairs = split '&', shift;
319 3 return $class->_from_pairs(\@pairs, @_);
320 }
321  
322 15 ▶sub to_hash {
Subroutine to_hash: called CC=1 SCAR=0.0
Pod undocumented
323 15 my $self = shift;
324 15 return $self->gather_message_parameters(hash => 1, add => [qw/signature/]);
325 }
326  
327 15 ▶sub to_url {
Subroutine to_url: called CC=7 SCAR=19.7
Pod undocumented
328 15 my $self = shift;
329 15 my $url = shift;
330 15 ▶ if (!defined $url and $self->can('request_url') and defined $self->request_url) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $url and $self->can("request_url") and defined $self->request_url) 12 3 15
Condition66%4/6
not defined $url and $self->can("request_url") and defined $self->request_url
!ll&&!rl&&r
3012
not defined $url and $self->can("request_url")
!ll&&!rl&&r
3012
MC/DC33%1/3
not defined $url and $self->can("request_url") and defined $self->request_url
not defined $url $self->can("request_url") defined $self->request_url
Truth table50%2/4
not(A) and B and C
A= not defined $urlB= $self->can("request_url")C= defined $self->request_url
ABCresult
0XX0
10X0
1100
1111
331 12 $url = $self->request_url;
332 }
333 15 ▶ if (defined $url) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url) { } 15 0 15
334 15 _ensure_uri_object($url);
335 15 $url = $url->clone; # don't modify the URL that was passed in
336 15 $url->query(undef); # remove any existing query params, as these may cause the signature to break
337 15 my $params = $self->to_hash;
338 15 my $sep = '?';
339 15 foreach my $k (sort keys %$params) {
340 98 $url .= $sep . encode($k) . '=' . encode( $params->{$k} );
341 98 ▶ $sep = '&' if $sep eq '?';
Branch: 1 branch
BranchTrueFalseTotal
if $sep eq "?" 15 83 98
342 }
343 15 return $url;
344 }
345 else {
346 0 return $self->to_post_body;
347 }
348 }
349  
350 =head1 NAME
351  
352 Net::OAuth::Message - base class for OAuth messages
353  
354 =head1 SEE ALSO
355  
356 L<Net::OAuth>, L<http://oauth.net>
357  
358 =head1 AUTHOR
359  
360 Originally by Keith Grennan <foss@nearlyfree.org>
361  
362 Currently maintained by Robert Rothenberg <perl@rhizomnic.com>
363  
364 =head1 COPYRIGHT & LICENSE
365  
366 Copyright 2007-2012, 2024-2026 Keith Grennan
367  
368 This program is free software; you can redistribute it and/or modify it
369 under the same terms as Perl itself.
370  
371 =cut
372  
373 14 1;
↑ Summary OAuth/Client.pm »