blib/lib/OAuth/Lite2/Util.pm

filter: Statementstmt 100% 45 / 45 Branchbran 100% 4 / 4 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 91.8% 68 / 74 SCAR 22.0
CC
9
Cov
95%
build_content
6.0
parse_content
4.1
BEGIN
1.0
CRAP 9.0
« blib/lib/OAuth/Lite2/Client/TokenResponseParser.pm ↑ Summary Build »
1 package OAuth::Lite2::Util;
2  
3 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use Hash::MultiValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 18 our %EXPORT_TAGS = ( all => [qw(
12 encode_param
13 decode_param
14 parse_content
15 build_content
16 )] );
17  
18 18 our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;
19  
20 =head1 NAME
21  
22 OAuth::Lite2::Util - utility methods for OAuth 2.0
23  
24 =head1 SYNOPSIS
25  
26 use OAuth::Lite2::Util qw(encode_param, decode_param);
27 my $encoded = encode_param($str);
28 my $origin = decode_param($encoded);
29  
30 =head1 DESCRIPTION
31  
32 This module exports utility methods for OAuth 2.0.
33  
34 =head1 METHODS
35  
36 =head2 encode_param ($str)
37  
38 =cut
39  
40 sub encode_param {
41 805 ▶ my $param = shift;
Subroutine encode_param: called CC=1 SCAR=0.0
Pod documented
42 805 return URI::Escape::uri_escape($param, '^\w.~-');
43 }
44  
45 =head2 decode_param ($str)
46  
47 =cut
48  
49 sub decode_param {
50 21 ▶ my $param = shift;
Subroutine decode_param: called CC=1 SCAR=0.0
Pod documented
51 21 return URI::Escape::uri_unescape($param);
52 }
53  
54 =head2 parse_content ($content)
55  
56 =cut
57  
58 sub parse_content {
59 2 ▶ my $content = shift;
Subroutine parse_content: called CC=4 SCAR=14.0
Pod documented
60 2 my $params = Hash::MultiValue->new;
61 2 for my $pair (split /\&/, $content) {
62 8 my ($key, $value) = split /\=/, $pair;
63 8 ▶ $key = decode_param($key ||'');
Condition50%1/2
$key || ''
l!l
80
MC/DC0%0/1
$key || ''
$key
Truth table50%1/2
A
A= $key
Aresult
11
00
64 8 ▶ $value = decode_param($value||'');
Condition50%1/2
$value || ''
l!l
80
MC/DC0%0/1
$value || ''
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
65 8 $params->add($key, $value);
66 }
67 2 return $params;
68 }
69  
70 =head2 build_content ($params)
71  
72 =cut
73  
74 sub build_content {
75 111 ▶ my $params = shift;
Subroutine build_content: called CC=6 SCAR=17.9
Pod documented
76 111 ▶ $params = $params->as_hashref_mixed
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($params) and $params->isa("Hash::MultiValue") 1 110 111
Condition66%2/3
builtin::blessed($params) and $params->isa("Hash::MultiValue")
!ll&&!rl&&r
11001
MC/DC50%1/2
builtin::blessed($params) and $params->isa("Hash::MultiValue")
builtin::blessed($params) $params->isa("Hash::MultiValue")
Truth table66%2/3
A and B
A= builtin::blessed($params)B= $params->isa("Hash::MultiValue")
ABresult
0X0
100
111
77 if blessed($params) && $params->isa('Hash::MultiValue');
78 111 my @pairs;
79 111 for my $key (keys %$params) {
80 397 my $k = encode_param($key);
81 397 my $v = $params->{$key};
82 397 ▶ if (ref($v) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 2 395 397
83 2 for my $av (@$v) {
84 4 push(@pairs, sprintf(q{%s=%s}, $k, encode_param($av)));
85 }
86 } else {
87 395 push(@pairs, sprintf(q{%s=%s}, $k, encode_param($v)));
88 }
89 }
90 111 return join("&", sort @pairs);
91 }
92  
93 18 1;
94  
95 =head1 AUTHOR
96  
97 Lyo Kato, E<lt>lyo.kato@gmail.comE<gt>
98  
99 =head1 COPYRIGHT AND LICENSE
100  
101 Copyright (C) 2010 by Lyo Kato
102  
103 This library is free software; you can redistribute it and/or modify
104 it under the same terms as Perl itself, either Perl version 5.8.8 or,
105 at your option, any later version of Perl 5 you may have available.
106  
107 =cut
« blib/lib/OAuth/Lite2/Client/TokenResponseParser.pm ↑ Summary Build »