| 1 | package WWW::Lovefilm::API; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | our $VERSION = '0.13'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use base qw(Class::Accessor); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Net::OAuth; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 10 | __PACKAGE__->mk_accessors(qw/ | |||||||||||||||||||||||||||
| 16 | consumer_key | ||||||||||||||||||||||||||||
| 17 | consumer_secret | ||||||||||||||||||||||||||||
| 18 | content_filter | ||||||||||||||||||||||||||||
| 19 | ua | ||||||||||||||||||||||||||||
| 20 | access_token | ||||||||||||||||||||||||||||
| 21 | access_secret | ||||||||||||||||||||||||||||
| 22 | user_id | ||||||||||||||||||||||||||||
| 23 | _levels | ||||||||||||||||||||||||||||
| 24 | rest_url | ||||||||||||||||||||||||||||
| 25 | _url | ||||||||||||||||||||||||||||
| 26 | _params | ||||||||||||||||||||||||||||
| 27 | privateapi | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | content_ref | ||||||||||||||||||||||||||||
| 30 | _filtered_content | ||||||||||||||||||||||||||||
| 31 | content_error | ||||||||||||||||||||||||||||
| 32 | /); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 3 | ▶ | my $fields = shift || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 37 | 3 | ▶ | $fields->{ua} ||= LWP::UserAgent->new(); | ||||||||||||||||||||||||||
|
Condition33%1/3
$fields->{"ua"} ||= "LWP::UserAgent"->new
MC/DC0%0/2
$fields->{"ua"} ||= "LWP::UserAgent"->new
$fields->{"ua"}
"LWP::UserAgent"->new
Truth table33%1/3
A ||= B
A= $fields->{"ua"}B= "LWP::UserAgent"->new
| |||||||||||||||||||||||||||||
| 38 | 3 | return $self->SUPER::new( $fields, @_ ); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | sub content { | ||||||||||||||||||||||||||
|
Subroutine
content: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 4 | ▶ | return $self->_filtered_content if $self->_filtered_content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 4 | ▶ | return unless $self->content_ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | return ${$self->content_ref} unless $self->content_filter && ref($self->content_filter); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->content_filter and ref $self->content_filter
MC/DC50%1/2
$self->content_filter and ref $self->content_filter
$self->content_filter
ref $self->content_filter
Truth table66%2/3
A and B
A= $self->content_filterB= ref $self->content_filter
| |||||||||||||||||||||||||||||
| 46 | return $self->_filtered_content( | ||||||||||||||||||||||||||||
| 47 | 1 | &{$self->content_filter}( ${$self->content_ref}, @_ ) | |||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | sub original_content { | ||||||||||||||||||||||||||
|
Subroutine
original_content: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | 4 | ▶ | return $self->content_ref ? ${$self->content_ref} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 10 | ▶ | sub _set_content { | ||||||||||||||||||||||||||
|
Subroutine
_set_content: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | 10 | my $content_ref = shift; | |||||||||||||||||||||||||||
| 59 | 10 | $self->content_error( undef ); | |||||||||||||||||||||||||||
| 60 | 10 | $self->_filtered_content( undef ); | |||||||||||||||||||||||||||
| 61 | 10 | return $self->content_ref( $content_ref ); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 6 | ▶ | sub REST { | ||||||||||||||||||||||||||
|
Subroutine
REST: called CC=4 SCAR=19.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 6 | my $url = shift; | |||||||||||||||||||||||||||
| 67 | 6 | $self->_levels([]); | |||||||||||||||||||||||||||
| 68 | 6 | $self->_set_content(undef); | |||||||||||||||||||||||||||
| 69 | 6 | ▶ | if( $url ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($url, $querystring) = split '\?', $url, 2; | |||||||||||||||||||||||||||
| 71 | 0 | $self->_url($url); | |||||||||||||||||||||||||||
| 72 | $self->_params({ | ||||||||||||||||||||||||||||
| 73 | map { | ||||||||||||||||||||||||||||
| 74 | 0 | my ($k,$v) = split /=/, $_, 2; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | $k !~ /^oauth_/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$querystring || ''
MC/DC0%0/1
$querystring || ''
$querystring
Truth table0%0/2
A
A= $querystring
| |||||||||||||||||||||||||||||
| 76 | ? ( $k => uri_unescape($v) ) | ||||||||||||||||||||||||||||
| 77 | : () | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | split /&/, $querystring||'' | ||||||||||||||||||||||||||||
| 80 | }); | ||||||||||||||||||||||||||||
| 81 | 0 | return $self->url; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 6 | $self->_url(undef); | |||||||||||||||||||||||||||
| 84 | 6 | $self->_params({}); | |||||||||||||||||||||||||||
| 85 | 6 | return WWW::Lovefilm::API::_UrlAppender->new( stack => $self->_levels, append => {users=>$self->user_id} ); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 8 | ▶ | sub _base_url { | ||||||||||||||||||||||||||
|
Subroutine
_base_url: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 89 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | 8 | ▶ | return $self->privateapi ? 'http://api.lovefilm.com' : 'http://openapi.lovefilm.com'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 10 | ▶ | sub url { | ||||||||||||||||||||||||||
|
Subroutine
url: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | 10 | ▶ | return $self->_url if $self->_url; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 8 | my $api_url = $self->_base_url; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 8 | ▶ | return join '/', $api_url, @{ $self->_levels || [] }; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->_levels || []
MC/DC100%1/1
$self->_levels || []
$self->_levels
Truth table100%2/2
A
A= $self->_levels
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub _submit { | ||||||||||||||||||||||||||
|
Subroutine
_submit: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 102 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 103 | 0 | my $method = shift; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | my %options = ( %{$self->_params || {}}, @_ ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->_params || {}
MC/DC0%0/1
$self->_params || {}
$self->_params
Truth table0%0/2
A
A= $self->_params
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $which = $self->access_token ? 'protected resource' : 'consumer'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | my $res = $self->__OAuth_Request( | ||||||||||||||||||||||||||||
| 107 | $which, | ||||||||||||||||||||||||||||
| 108 | request_url => $self->url, | ||||||||||||||||||||||||||||
| 109 | request_method => $method, | ||||||||||||||||||||||||||||
| 110 | token => $self->access_token, | ||||||||||||||||||||||||||||
| 111 | token_secret => $self->access_secret, | ||||||||||||||||||||||||||||
| 112 | extra_params => \%options, | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | ) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | warn $self->content_error; | |||||||||||||||||||||||||||
| 115 | 0 | return; | |||||||||||||||||||||||||||
| 116 | }; | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | return 1; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub Get { | ||||||||||||||||||||||||||
|
Subroutine
Get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 122 | 0 | return $self->_submit('GET', @_); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub Post { | ||||||||||||||||||||||||||
|
Subroutine
Post: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 125 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 126 | 0 | return $self->_submit('POST', @_); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub Delete { | ||||||||||||||||||||||||||
|
Subroutine
Delete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 130 | 0 | return $self->_submit('DELETE', @_); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 6 | ▶ | sub rest2sugar { | ||||||||||||||||||||||||||
|
Subroutine
rest2sugar: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 135 | 6 | my $url = shift; | |||||||||||||||||||||||||||
| 136 | 6 | my @stack = ( '$lovefilm', 'REST' ); | |||||||||||||||||||||||||||
| 137 | 6 | my @params; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 6 | $url =~ s#^http://openapi.lovefilm.com##; | |||||||||||||||||||||||||||
| 140 | 6 | $url =~ s#^http://api.lovefilm.com##; | |||||||||||||||||||||||||||
| 141 | 6 | $url =~ s#(/users/)(\w|-){30,}/#$1#i; | |||||||||||||||||||||||||||
| 142 | 6 | $url =~ s#/(\d+)(?=/|$)#('$1')#; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 6 | ▶ | if( $url =~ s#\?(.+)## ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 2 | my $querystring = $1; | |||||||||||||||||||||||||||
| 146 | @params = map { | ||||||||||||||||||||||||||||
| 147 | 2 | my ($k,$v) = split /=/, $_, 2; | |||||||||||||||||||||||||||
| 148 | 8 | [ $k, uri_unescape($v) ] | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | split /&/, $querystring; | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | push @stack, map { | ||||||||||||||||||||||||||||
| 153 | 16 | join '_', map { ucfirst } split '_', lc $_ | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 6 | grep { length($_) } | |||||||||||||||||||||||||||
| 156 | split '/', $url | ||||||||||||||||||||||||||||
| 157 | ; | ||||||||||||||||||||||||||||
| 158 | return ( | ||||||||||||||||||||||||||||
| 159 | join('->', @stack), | ||||||||||||||||||||||||||||
| 160 | sprintf('$lovefilm->Get(%s)', | ||||||||||||||||||||||||||||
| 161 | 6 | join( ', ', map { sprintf "'%s' => '%s'", @$_ } @params ), | |||||||||||||||||||||||||||
| 162 | ), | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub RequestToken { | ||||||||||||||||||||||||||
|
Subroutine
RequestToken: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 168 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 169 | 0 | my ($request, $response); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | $request = $self->__OAuth_Request( | ||||||||||||||||||||||||||||
| 172 | 'request token', | ||||||||||||||||||||||||||||
| 173 | request_url => $self->_base_url . '/oauth/request_token', | ||||||||||||||||||||||||||||
| 174 | request_method => 'POST', | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | ) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | warn $self->content_error; | |||||||||||||||||||||||||||
| 177 | 0 | return; | |||||||||||||||||||||||||||
| 178 | }; | ||||||||||||||||||||||||||||
| 179 | 0 | $response = Net::OAuth->response('request token')->from_post_body( $self->original_content ); | |||||||||||||||||||||||||||
| 180 | 0 | ▶ | my $request_token = $response->token | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | or return; | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | return ( | ||||||||||||||||||||||||||||
| 184 | token => $request_token, | ||||||||||||||||||||||||||||
| 185 | login_url => $response->extra_params->{login_url}, | ||||||||||||||||||||||||||||
| 186 | 0 | token_secret => $response->token_secret | |||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub RequestAccessToken { | ||||||||||||||||||||||||||
|
Subroutine
RequestAccessToken: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 191 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 192 | 0 | my (%args) = @_; | |||||||||||||||||||||||||||
| 193 | 0 | my ($request_token, $request_secret) = @_; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | my $request = $self->__OAuth_Request( | ||||||||||||||||||||||||||||
| 196 | 'access token', | ||||||||||||||||||||||||||||
| 197 | request_url => $self->_base_url . '/oauth/access_token', | ||||||||||||||||||||||||||||
| 198 | request_method => 'POST', | ||||||||||||||||||||||||||||
| 199 | token => $args{oauth_token}, | ||||||||||||||||||||||||||||
| 200 | token_secret => $args{token_secret}, | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | ) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | warn $self->content_error; | |||||||||||||||||||||||||||
| 203 | 0 | return; | |||||||||||||||||||||||||||
| 204 | }; | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | my $response = Net::OAuth->response('access token')->from_post_body( $self->original_content ); | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | $self->access_token( $response->token ); | |||||||||||||||||||||||||||
| 209 | 0 | $self->access_secret( $response->token_secret ); | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # Get the uses ID. See POD for this routine as to why | ||||||||||||||||||||||||||||
| 212 | # | ||||||||||||||||||||||||||||
| 213 | 0 | $self->REST->Users(); | |||||||||||||||||||||||||||
| 214 | 0 | $self->Get(); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ($self->content) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 0 | my $href = $self->content->{link}->{href}; | |||||||||||||||||||||||||||
| 218 | 0 | my ($user_id) = ($href =~ m!([^/]+)$!); | |||||||||||||||||||||||||||
| 219 | 0 | $self->user_id($user_id); | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | return (access_token => $self->access_token, access_secret => $self->access_secret, user_id => $self->user_id); | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | ▶ | sub __OAuth_Request { | ||||||||||||||||||||||||||
|
Subroutine
__OAuth_Request: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 227 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 228 | 0 | my $request_type = shift; | |||||||||||||||||||||||||||
| 229 | 0 | my $params = { # Options to pass-through to Net::OAuth::*Request constructor | |||||||||||||||||||||||||||
| 230 | # Static: | ||||||||||||||||||||||||||||
| 231 | consumer_key => $self->consumer_key, | ||||||||||||||||||||||||||||
| 232 | consumer_secret => $self->consumer_secret, | ||||||||||||||||||||||||||||
| 233 | signature_method => 'HMAC-SHA1', | ||||||||||||||||||||||||||||
| 234 | timestamp => time, | ||||||||||||||||||||||||||||
| 235 | nonce => join('::', $0, $$), | ||||||||||||||||||||||||||||
| 236 | version => '1.0', | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | # Defaults: | ||||||||||||||||||||||||||||
| 239 | request_url => $self->url, | ||||||||||||||||||||||||||||
| 240 | request_method => 'POST', | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | # User overrides/additions: | ||||||||||||||||||||||||||||
| 243 | @_ | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | # Most common user-provided params will be: | ||||||||||||||||||||||||||||
| 246 | # request_url | ||||||||||||||||||||||||||||
| 247 | # request_method | ||||||||||||||||||||||||||||
| 248 | # token | ||||||||||||||||||||||||||||
| 249 | # token_secret | ||||||||||||||||||||||||||||
| 250 | # extra_params | ||||||||||||||||||||||||||||
| 251 | }; | ||||||||||||||||||||||||||||
| 252 | 0 | $self->_set_content(undef); | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | my $request = Net::OAuth->request( $request_type )->new( %$params ); | |||||||||||||||||||||||||||
| 255 | 0 | $request->sign; | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 0 | my $url = $request->to_url; | |||||||||||||||||||||||||||
| 258 | 0 | $self->rest_url( "$url" ); | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 0 | my $method = $params->{request_method}; | |||||||||||||||||||||||||||
| 261 | 0 | my $req; | |||||||||||||||||||||||||||
| 262 | 0 | ▶ | if( $method eq 'GET' ){ | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 263 | 0 | $req = GET $url; | |||||||||||||||||||||||||||
| 264 | }elsif( $method eq 'POST' ){ | ||||||||||||||||||||||||||||
| 265 | 0 | $req = POST $url; | |||||||||||||||||||||||||||
| 266 | }elsif( $method eq 'DELETE' ){ | ||||||||||||||||||||||||||||
| 267 | 0 | $req = HTTP::Request->new( 'DELETE', $url ); | |||||||||||||||||||||||||||
| 268 | }else{ | ||||||||||||||||||||||||||||
| 269 | 0 | $self->content_error( "Unknown method '$method'" ); | |||||||||||||||||||||||||||
| 270 | 0 | return; | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | # if content_filter exists and is a scalar, then use it as the filename to write to instead of content being in memory. | ||||||||||||||||||||||||||||
| 273 | 0 | ▶ | my $response = $self->ua->request( $req, ($self->content_filter && !ref($self->content_filter) ? $self->content_filter : ()) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->content_filter and not ref $self->content_filter
MC/DC0%0/2
$self->content_filter and not ref $self->content_filter
$self->content_filter
not ref $self->content_filter
Truth table0%0/3
A and not(B)
A= $self->content_filterB= not ref $self->content_filter
| |||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ( ! $response->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 276 | 0 | $self->content_error( sprintf '%s Request to "%s" failed (%s): "%s"', $method, $url, $response->status_line, $response->content ); | |||||||||||||||||||||||||||
| 277 | 0 | return; | |||||||||||||||||||||||||||
| 278 | 0 | }elsif( ! length ${$response->content_ref} ){ | |||||||||||||||||||||||||||
| 279 | 0 | $self->content_error( sprintf '%s Request to "%s" failed (%s) (__EMPTY_CONTENT__): "%s"', $method, $url, $response->status_line, $response->content ); | |||||||||||||||||||||||||||
| 280 | 0 | return; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | 0 | $self->_set_content( $response->content_ref ); | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 0 | return $response; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | ######################################## | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | package WWW::Lovefilm::API::_UrlAppender; | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 292 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 293 | 10 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 8 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 296 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 297 | 8 | my $params = { @_ }; | |||||||||||||||||||||||||||
| 298 | 8 | ▶ | return bless { stack => $params->{stack}, append => $params->{append}||{} }, $self; | ||||||||||||||||||||||||||
|
Condition100%2/2
$params->{'append'} || {}
MC/DC100%1/1
$params->{'append'} || {}
$params->{'append'}
Truth table100%2/2
A
A= $params->{'append'}
| |||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 30 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 302 | 30 | my $self = shift; | |||||||||||||||||||||||||||
| 303 | 30 | my $dir = lc $AUTOLOAD; | |||||||||||||||||||||||||||
| 304 | 30 | $dir =~ s/.*:://; | |||||||||||||||||||||||||||
| 305 | 30 | ▶ | if( $dir ne 'destroy' ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 22 | push @{ $self->{stack} }, $dir; | |||||||||||||||||||||||||||
| 307 | 22 | ▶ | push @{ $self->{stack} }, @_ if scalar @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 22 | ▶ | push @{ $self->{stack} }, $self->{append}->{$dir} if exists $self->{append}->{$dir}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | 30 | return $self; | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | ######################################## | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 10 | 1; # End of WWW::Lovefilm::API | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | __END__ | ||||||||||||||||||||||||||||