blib/lib/Flickr/API/Request.pm

filter: Statementstmt 71.0% 49 / 69 Branchbran 37.5% 3 / 8 Conditioncond 40.0% 4 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 9 / 9 Podpod 50.0% 1 / 2 totaltotal 64.0% 66 / 103 CC 11 SCAR 22.9
CC
11
Cov
64%
new
20.3
encode_args
4.3
BEGIN
1.0
CRAP 9.8
« blib/lib/Flickr/API/Reflection.pm ↑ Summary blib/lib/Flickr/API/Cameras.pm »
1 package Flickr::API::Request;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Net::OAuth;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶use Encode qw(encode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 15 ▶use parent qw(HTTP::Request);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 15 our $VERSION = '1.28';
13  
14 2 ▶sub new {
Subroutine new: called CC=8 SCAR=30.1
Pod documented
15 2 my $class = shift;
16 2 my $options = shift;
17 2 my $self;
18  
19 2 ▶ if (($options->{api_type} || '') eq 'oauth') {
Branch: 1 branch
BranchTrueFalseTotal
if (($options->{'api_type'} || '') eq 'oauth') { } 0 2 2
Condition50%1/2
$options->{'api_type'} || ''
l!l
20
MC/DC0%0/1
$options->{'api_type'} || ''
$options->{'api_type'}
Truth table50%1/2
A
A= $options->{'api_type'}
Aresult
11
00
20  
21 0 $options->{args}->{request_method}='POST';
22 0 $options->{args}->{request_url}=$options->{rest_uri};
23  
24 0 $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A;
25  
26 0 my $orequest;
27  
28 0 ▶ if (defined($options->{args}->{token})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{'args'}{'token'}) { } 0 0 0
29  
30 0 $orequest = Net::OAuth->request('protected resource')->new(%{$options->{args}});
31  
32 }
33 else {
34  
35 0 $orequest = Net::OAuth->request('consumer')->new(%{$options->{args}});
36  
37 }
38  
39 0 $orequest->sign();
40  
41 0 my $h = HTTP::Headers->new;
42 0 $h->header('Content-Type' => 'application/x-www-form-urlencoded');
43 0 $h->header('Content-Length' => length($orequest->to_post_body));
44  
45 $self = HTTP::Request->new(
46 $options->{args}->{request_method},
47 $options->{rest_uri},
48 0 $h,
49 $orequest->to_post_body());
50  
51 0 $self->{api_method} = $options->{method};
52 0 $self->{api_type} = $options->{api_type};
53 0 ▶ $self->{unicode} = $options->{unicode} || 0;
Condition0%0/2
$options->{'unicode'} || 0
l!l
00
MC/DC0%0/1
$options->{'unicode'} || 0
$options->{'unicode'}
Truth table0%0/2
A
A= $options->{'unicode'}
Aresult
11
00
54  
55 }
56 else {
57  
58 2 $self = HTTP::Request->new;
59  
60 2 $self->{api_method} = $options->{method};
61  
62 2 ▶ $self->{api_type} = $options->{api_type} || 'flickr';
Condition50%1/2
$options->{'api_type'} || 'flickr'
l!l
20
MC/DC0%0/1
$options->{'api_type'} || 'flickr'
$options->{'api_type'}
Truth table50%1/2
A
A= $options->{'api_type'}
Aresult
11
00
63 2 ▶ $self->{unicode} = $options->{unicode} || 0;
Condition50%1/2
$options->{'unicode'} || 0
l!l
02
MC/DC0%0/1
$options->{'unicode'} || 0
$options->{'unicode'}
Truth table50%1/2
A
A= $options->{'unicode'}
Aresult
11
00
64 2 $self->{api_args} = $options->{args};
65 2 ▶ $self->{rest_uri} = $options->{rest_uri} || 'https://api.flickr.com/services/rest/';
Condition50%1/2
$options->{'rest_uri'} || 'https://api.flickr.com/services/rest/'
l!l
20
MC/DC0%0/1
$options->{'rest_uri'} || 'https://api.flickr.com/services/rest/'
$options->{'rest_uri'}
Truth table50%1/2
A
A= $options->{'rest_uri'}
Aresult
11
00
66 2 $self->method('POST');
67 2 $self->uri($self->{rest_uri});
68  
69 }
70  
71 2 bless $self, $class;
72  
73 2 return $self;
74 }
75  
76 2 ▶sub encode_args {
Subroutine encode_args: called CC=4 SCAR=14.6
Pod undocumented
77 2 my ($self) = @_;
78  
79 2 my $content;
80 2 my $url = URI->new('https:');
81  
82 2 ▶ if ($self->{unicode}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"unicode"}) 0 2 2
83 0 for my $k(keys %{$self->{api_args}}){
84 0 $self->{api_args}->{$k} = encode_utf8($self->{api_args}->{$k});
85 }
86 }
87 2 $url->query_form(%{$self->{api_args}});
88 2 $content = $url->query;
89  
90  
91 2 $self->header('Content-Type' => 'application/x-www-form-urlencoded');
92 2 ▶ if (defined($content)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content) 2 0 2
93 2 $self->header('Content-Length' => length($content));
94 2 $self->content($content);
95 }
96 2 return;
97 }
98  
99 15 1;
100  
101 __END__
« blib/lib/Flickr/API/Reflection.pm ↑ Summary blib/lib/Flickr/API/Cameras.pm »