| 1 | package Atompub::Client; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Atompub; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Atompub::DateTime qw(datetime); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Atompub::MediaType qw(media_type); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Atompub::Util qw(is_acceptable_media_type is_allowed_category); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Digest::SHA qw(sha1); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Encode qw(encode_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use HTTP::Status; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use MIME::Base64 qw(encode_base64); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use NEXT; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use XML::Atom::Entry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use XML::Atom::Service; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 4 | ▶ | use base qw(XML::Atom::Client Class::Accessor::Fast); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 4 | my @ATTRS = qw(request response resource); | |||||||||||||||||||||||||||
| 23 | 4 | __PACKAGE__->mk_accessors(@ATTRS, qw(ua info cache)); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 4 | *req = \&request; | |||||||||||||||||||||||||||
| 26 | 4 | *res = \&response; | |||||||||||||||||||||||||||
| 27 | 4 | *rc = \&resource; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 0 | my $client = shift; | |||||||||||||||||||||||||||
| 31 | 0 | $client->NEXT::init(@_); | |||||||||||||||||||||||||||
| 32 | 0 | $client->ua->agent('Atompub::Client/'.Atompub->VERSION); | |||||||||||||||||||||||||||
| 33 | 0 | $client->info(Atompub::Client::Info->instance); | |||||||||||||||||||||||||||
| 34 | 0 | $client->cache(Atompub::Client::Cache->instance); | |||||||||||||||||||||||||||
| 35 | 0 | $client; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub proxy { | ||||||||||||||||||||||||||
|
Subroutine
proxy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my($client, $proxy) = @_; | |||||||||||||||||||||||||||
| 40 | 0 | $client->ua->proxy(['http', 'https'], $proxy); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub getService { | ||||||||||||||||||||||||||
|
Subroutine
getService: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 0 | my($client, $uri) = @_; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $client->_get_service({ uri => $uri }) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | $client->rc; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub getCategories { | ||||||||||||||||||||||||||
|
Subroutine
getCategories: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | my($client, $uri) = @_; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $client->_get_categories({ uri => $uri }) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | $client->rc; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub getFeed { | ||||||||||||||||||||||||||
|
Subroutine
getFeed: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | my($client, $uri) = @_; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $client->_get_feed({ uri => $uri }) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $client->rc; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub createEntry { | ||||||||||||||||||||||||||
|
Subroutine
createEntry: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | my($client, $uri, $entry, $slug) = @_; | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return $client->error('No Entry') unless $entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | unless (UNIVERSAL::isa($entry, 'XML::Atom::Entry')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $entry = XML::Atom::Entry->new($entry) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | or return $client->error(XML::Atom::Entry->errstr); | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 0 | my $headers = HTTP::Headers->new; | |||||||||||||||||||||||||||
| 73 | 0 | $headers->content_type(media_type('entry')); | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | $headers->slug(_escape(uri_unescape $slug)) if defined $slug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $client->_create_resource({ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | uri => $uri, | ||||||||||||||||||||||||||||
| 77 | rc => $entry, | ||||||||||||||||||||||||||||
| 78 | headers => $headers, | ||||||||||||||||||||||||||||
| 79 | }) or return; | ||||||||||||||||||||||||||||
| 80 | 0 | $client->res->location; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub createMedia { | ||||||||||||||||||||||||||
|
Subroutine
createMedia: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | my($client, $uri, $stream, $content_type, $slug) = @_; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return $client->error('No stream') unless $stream; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | return $client->error('No Content-Type') unless $content_type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $media = ref $stream ? $$stream : read_file($stream, binmode => ':raw') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 89 | or return $client->error('No media'); | ||||||||||||||||||||||||||||
| 90 | 0 | my $headers = HTTP::Headers->new; | |||||||||||||||||||||||||||
| 91 | 0 | $headers->content_type($content_type); | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | $headers->slug(_escape( uri_unescape $slug)) if defined $slug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $client->_create_resource({ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | uri => $uri, | ||||||||||||||||||||||||||||
| 95 | rc => \$media, | ||||||||||||||||||||||||||||
| 96 | headers => $headers, | ||||||||||||||||||||||||||||
| 97 | }) or return; | ||||||||||||||||||||||||||||
| 98 | 0 | $client->res->location; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub getEntry { | ||||||||||||||||||||||||||
|
Subroutine
getEntry: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 0 | my($client, $uri) = @_; | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $client->_get_resource({ uri => $uri }) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return $client->error('Response is not Atom Entry') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | unless UNIVERSAL::isa($client->rc, 'XML::Atom::Entry'); | ||||||||||||||||||||||||||||
| 107 | 0 | $client->rc; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub getMedia { | ||||||||||||||||||||||||||
|
Subroutine
getMedia: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 0 | my($client, $uri) = @_; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $client->_get_resource({ uri => $uri }) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return $client->error('Response is not Media Resource') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | if UNIVERSAL::isa($client->rc, 'XML::Atom::Entry'); | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | wantarray ? ($client->rc, $client->res->content_type) : $client->rc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub updateEntry { | ||||||||||||||||||||||||||
|
Subroutine
updateEntry: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 0 | my($client, $uri, $entry) = @_; | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | return $client->error('No Entry') unless $entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | unless (UNIVERSAL::isa( $entry, 'XML::Atom::Entry')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $entry = XML::Atom::Entry->new($entry) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | or return $client->error(XML::Atom::Entry->errstr); | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 0 | my $headers = HTTP::Headers->new; | |||||||||||||||||||||||||||
| 128 | 0 | $headers->content_type(media_type('entry')); | |||||||||||||||||||||||||||
| 129 | 0 | $client->_update_resource({ | |||||||||||||||||||||||||||
| 130 | uri => $uri, | ||||||||||||||||||||||||||||
| 131 | rc => $entry, | ||||||||||||||||||||||||||||
| 132 | headers => $headers, | ||||||||||||||||||||||||||||
| 133 | }); | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub updateMedia { | ||||||||||||||||||||||||||
|
Subroutine
updateMedia: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | 0 | my($client, $uri, $stream, $content_type) = @_; | |||||||||||||||||||||||||||
| 138 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | return $client->error('No stream') unless $stream; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return $client->error('No Content-Type') unless $content_type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $media = ref $stream ? $$stream : read_file($stream, binmode => ':raw') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 142 | or return $client->error('No media resource'); | ||||||||||||||||||||||||||||
| 143 | 0 | my $headers = HTTP::Headers->new; | |||||||||||||||||||||||||||
| 144 | 0 | $headers->content_type($content_type); | |||||||||||||||||||||||||||
| 145 | 0 | $client->_update_resource({ | |||||||||||||||||||||||||||
| 146 | uri => $uri, | ||||||||||||||||||||||||||||
| 147 | rc => \$media, | ||||||||||||||||||||||||||||
| 148 | headers => $headers, | ||||||||||||||||||||||||||||
| 149 | }); | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub deleteEntry { | ||||||||||||||||||||||||||
|
Subroutine
deleteEntry: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 0 | my($client, $uri) = @_; | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | $client->_delete_resource({ uri => $uri }); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 4 | *deleteMedia = \&deleteEntry; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub _get_service { | ||||||||||||||||||||||||||
|
Subroutine
_get_service: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 161 | 0 | my($client, $args) = @_; | |||||||||||||||||||||||||||
| 162 | 0 | my $uri = $args->{uri}; | |||||||||||||||||||||||||||
| 163 | 0 | $client->_clear; | |||||||||||||||||||||||||||
| 164 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 0 | $client->req(HTTP::Request->new(GET => $uri)); | |||||||||||||||||||||||||||
| 166 | 0 | $client->res($client->make_request($client->req)); | |||||||||||||||||||||||||||
| 167 | 0 | ▶ | return $client->error(join "\n", $client->res->status_line, $client->res->content) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | unless is_success $client->res->code; | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | warn 'Bad Content-Type: '.$client->res->content_type | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | unless media_type($client->res->content_type)->is_a('service'); | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | $client->rc(XML::Atom::Service->new(\$client->res->content)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | or return $client->error(XML::Atom::Service->errstr); | ||||||||||||||||||||||||||||
| 173 | 0 | for my $work ($client->rc->workspaces) { | |||||||||||||||||||||||||||
| 174 | 0 | $client->info->put($_->href, $_) for $work->collections; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 0 | $client; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub _get_categories { | ||||||||||||||||||||||||||
|
Subroutine
_get_categories: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 180 | 0 | my($client, $args) = @_; | |||||||||||||||||||||||||||
| 181 | 0 | my $uri = $args->{uri}; | |||||||||||||||||||||||||||
| 182 | 0 | $client->_clear; | |||||||||||||||||||||||||||
| 183 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | $client->req(HTTP::Request->new(GET => $uri)); | |||||||||||||||||||||||||||
| 185 | 0 | $client->res($client->make_request($client->req)); | |||||||||||||||||||||||||||
| 186 | 0 | ▶ | return $client->error(join "\n", $client->res->status_line, $client->res->content) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | unless is_success $client->res->code; | ||||||||||||||||||||||||||||
| 188 | 0 | ▶ | warn 'Bad Content-Type: '.$client->res->content_type | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | unless media_type($client->res->content_type)->is_a('categories'); | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | $client->rc(XML::Atom::Categories->new(\$client->res->content)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | or return $client->error(XML::Atom::Categories->errstr); | ||||||||||||||||||||||||||||
| 192 | 0 | $client; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub _get_feed { | ||||||||||||||||||||||||||
|
Subroutine
_get_feed: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 196 | 0 | my($client, $args) = @_; | |||||||||||||||||||||||||||
| 197 | 0 | my $uri = $args->{uri}; | |||||||||||||||||||||||||||
| 198 | 0 | $client->_clear; | |||||||||||||||||||||||||||
| 199 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | $client->req(HTTP::Request->new(GET => $uri)); | |||||||||||||||||||||||||||
| 201 | 0 | $client->res($client->make_request($client->req)); | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | return $client->error(join "\n", $client->res->status_line, $client->res->content) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | unless is_success $client->res->code; | ||||||||||||||||||||||||||||
| 204 | 0 | ▶ | warn 'Bad Content-Type: '.$client->res->content_type | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | unless media_type($client->res->content_type)->is_a('feed'); | ||||||||||||||||||||||||||||
| 206 | 0 | ▶ | $client->rc(XML::Atom::Feed->new(\$client->res->content)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | or return $client->error(XML::Atom::Feed->errstr); | ||||||||||||||||||||||||||||
| 208 | 0 | $client; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | ▶ | sub _create_resource { | ||||||||||||||||||||||||||
|
Subroutine
_create_resource: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||
| 212 | 0 | my($client, $args) = @_; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | my $uri = $args->{uri}; | |||||||||||||||||||||||||||
| 215 | 0 | ▶ | my $rc = $args->{resource} || $args->{rc}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$args->{'resource'} || $args->{'rc'}
MC/DC0%0/2
$args->{'resource'} || $args->{'rc'}
$args->{'resource'}
$args->{'rc'}
Truth table0%0/3
A || B
A= $args->{'resource'}B= $args->{'rc'}
| |||||||||||||||||||||||||||||
| 216 | 0 | my $headers = $args->{headers}; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | $client->_clear; | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | return $client->error('No resource') unless $rc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 0 | ▶ | return $client->error('No headers') unless $headers; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | my $content_type = $headers->content_type; | |||||||||||||||||||||||||||
| 225 | 0 | my $info = $client->info->get($uri); | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | return $client->error("Unsupported media type: $content_type") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | unless is_acceptable_media_type($info, $content_type); | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | my $content; | |||||||||||||||||||||||||||
| 231 | 0 | ▶ | if (UNIVERSAL::isa($rc, 'XML::Atom::Entry')) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 232 | 0 | my $entry = $rc; | |||||||||||||||||||||||||||
| 233 | 0 | ▶ | return $client->error('Forbidden category') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | unless is_allowed_category($info, $entry->category); | ||||||||||||||||||||||||||||
| 235 | 0 | $content = $entry->as_xml; | |||||||||||||||||||||||||||
| 236 | 0 | XML::Atom::Client::_utf8_off($content); | |||||||||||||||||||||||||||
| 237 | 0 | $headers->content_type(media_type('entry')); | |||||||||||||||||||||||||||
| 238 | 0 | $headers->content_length(length $content); | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | elsif (UNIVERSAL::isa($rc, 'SCALAR')) { | ||||||||||||||||||||||||||||
| 241 | 0 | $content = $$rc; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | $client->req(HTTP::Request->new(POST => $uri, $headers, $content)); | |||||||||||||||||||||||||||
| 245 | 0 | $client->res($client->make_request($client->req)); | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | return $client->error(join "\n", $client->res->status_line, $client->res->content) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | unless is_success $client->res->code; | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 0 | ▶ | warn 'Bad status code: '.$client->res->code | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | unless $client->res->code == RC_CREATED; | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | return $client->error('No Locaiton') unless $client->res->location; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | # warn 'No Content-Locaiton' unless $client->res->content_location; | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 0 | ▶ | return $client unless $client->res->content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | warn 'Bad Content-Type: '.$client->res->content_type | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | unless media_type($client->res->content_type)->is_a('entry'); | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 0 | ▶ | $client->rc(XML::Atom::Entry->new(\$client->res->content)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | or return $client->error(XML::Atom::Entry->errstr); | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 0 | my $last_modified = $client->res->last_modified; | |||||||||||||||||||||||||||
| 266 | 0 | my $etag = $client->res->etag; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | $client->cache->put($client->res->location, { | |||||||||||||||||||||||||||
| 269 | rc => $client->rc, | ||||||||||||||||||||||||||||
| 270 | last_modified => $last_modified, | ||||||||||||||||||||||||||||
| 271 | etag => $etag, | ||||||||||||||||||||||||||||
| 272 | }); | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | $client; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 0 | ▶ | sub _get_resource { | ||||||||||||||||||||||||||
|
Subroutine
_get_resource: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 278 | 0 | my($client, $args) = @_; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | my $uri = $args->{uri}; | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | $client->_clear; | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 0 | my $headers = HTTP::Headers->new; | |||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | my $cache = $client->cache->get($uri); | |||||||||||||||||||||||||||
| 289 | 0 | ▶ | if ($cache) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 0 | ▶ | $headers->if_modified_since(datetime($cache->last_modified)->epoch) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | if $cache->last_modified; | ||||||||||||||||||||||||||||
| 292 | 0 | ▶ | $headers->if_none_match($cache->etag) if defined $cache->etag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | $client->req(HTTP::Request->new(GET => $uri, $headers)); | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | $client->res($client->make_request($client->req)); | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | ▶ | if (is_success $client->res->code) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if (media_type($client->res->content_type)->is_a('entry')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 0 | ▶ | $client->rc(XML::Atom::Entry->new(\$client->res->content)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | or return $client->error(XML::Atom::Entry->errstr); | ||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | else { | ||||||||||||||||||||||||||||
| 305 | 0 | $client->rc($client->res->content); | |||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 0 | my $last_modified = $client->res->last_modified; | |||||||||||||||||||||||||||
| 309 | 0 | my $etag = $client->res->etag; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 0 | $client->cache->put($uri, { | |||||||||||||||||||||||||||
| 312 | rc => $client->rc, | ||||||||||||||||||||||||||||
| 313 | last_modified => $last_modified, | ||||||||||||||||||||||||||||
| 314 | etag => $etag, | ||||||||||||||||||||||||||||
| 315 | }); | ||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | elsif ($client->res->code == RC_NOT_MODIFIED) { | ||||||||||||||||||||||||||||
| 318 | 0 | $client->rc($cache->rc); | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | else { | ||||||||||||||||||||||||||||
| 321 | 0 | return $client->error(join "\n", $client->res->status_line, $client->res->content); | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | $client; | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub _update_resource { | ||||||||||||||||||||||||||
|
Subroutine
_update_resource: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||
| 328 | 0 | my($client, $args) = @_; | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 0 | my $uri = $args->{uri}; | |||||||||||||||||||||||||||
| 331 | 0 | ▶ | my $rc = $args->{resource} || $args->{rc}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$args->{'resource'} || $args->{'rc'}
MC/DC0%0/2
$args->{'resource'} || $args->{'rc'}
$args->{'resource'}
$args->{'rc'}
Truth table0%0/3
A || B
A= $args->{'resource'}B= $args->{'rc'}
| |||||||||||||||||||||||||||||
| 332 | 0 | my $headers = $args->{headers}; | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | $client->_clear; | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | return $client->error('No resource') unless $rc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | 0 | ▶ | return $client->error('No headers') unless $headers; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 0 | my $content; | |||||||||||||||||||||||||||
| 341 | 0 | ▶ | if (UNIVERSAL::isa($rc, 'XML::Atom::Entry')) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 342 | 0 | my $entry = $rc; | |||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 0 | $content = $entry->as_xml; | |||||||||||||||||||||||||||
| 345 | 0 | XML::Atom::Client::_utf8_off($content); | |||||||||||||||||||||||||||
| 346 | 0 | $headers->content_type(media_type('entry')); | |||||||||||||||||||||||||||
| 347 | 0 | $headers->content_length(length $content); | |||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | elsif (UNIVERSAL::isa($rc, 'SCALAR')) { | ||||||||||||||||||||||||||||
| 350 | 0 | $content = $$rc; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if (my $cache = $client->cache->get($uri)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | $headers->if_unmodified_since(datetime($cache->last_modified)->epoch) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | if $cache->last_modified; | ||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $headers->if_match($cache->etag) if defined $cache->etag; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | $client->req(HTTP::Request->new(PUT => $uri, $headers, $content)); | |||||||||||||||||||||||||||
| 360 | 0 | $client->res($client->make_request($client->req)); | |||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 0 | ▶ | return $client->error(join "\n", $client->res->status_line, $client->res->content) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | unless is_success $client->res->code; | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 0 | ▶ | return $client unless $client->res->content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if (media_type($client->res->content_type)->is_a('entry')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 0 | ▶ | $client->rc(XML::Atom::Entry->new(\$client->res->content)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | or return $client->error(XML::Atom::Entry->errstr); | ||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | else { | ||||||||||||||||||||||||||||
| 372 | 0 | $client->rc($client->res->content); | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 0 | my $last_modified = $client->res->last_modified; | |||||||||||||||||||||||||||
| 376 | 0 | my $etag = $client->res->etag; | |||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | $client->cache->put($uri, { | |||||||||||||||||||||||||||
| 379 | rc => $client->rc, | ||||||||||||||||||||||||||||
| 380 | last_modified => $last_modified, | ||||||||||||||||||||||||||||
| 381 | etag => $etag, | ||||||||||||||||||||||||||||
| 382 | }); | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | 0 | $client; | |||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | 0 | ▶ | sub _delete_resource { | ||||||||||||||||||||||||||
|
Subroutine
_delete_resource: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 388 | 0 | my($client, $args) = @_; | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | 0 | my $uri = $args->{uri}; | |||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 0 | $client->_clear; | |||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 0 | ▶ | return $client->error('No URI') unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 0 | my $headers = HTTP::Headers->new; | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | # If-Match nor If-Unmodified-Since header is not required on DELETE | ||||||||||||||||||||||||||||
| 399 | # if (my $cache = $client->cache->get($uri)) { | ||||||||||||||||||||||||||||
| 400 | # $headers->if_unmodified_since(datetime($cache->last_modified)->epoch) | ||||||||||||||||||||||||||||
| 401 | # if $cache->last_modified; | ||||||||||||||||||||||||||||
| 402 | # $headers->if_match($cache->etag) if defined $cache->etag; | ||||||||||||||||||||||||||||
| 403 | # } | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 0 | $client->req(HTTP::Request->new(DELETE => $uri, $headers)); | |||||||||||||||||||||||||||
| 406 | 0 | $client->res($client->make_request($client->req)); | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 0 | ▶ | return $client->error(join "\n", $client->res->status_line, $client->res->content) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 409 | unless is_success $client->res->code; | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 0 | $client; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 0 | ▶ | sub _clear { | ||||||||||||||||||||||||||
|
Subroutine
_clear: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 415 | 0 | my($client) = @_; | |||||||||||||||||||||||||||
| 416 | 0 | $client->error(''); | |||||||||||||||||||||||||||
| 417 | 0 | $client->{$_} = undef for @ATTRS; | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 0 | ▶ | sub munge_request { | ||||||||||||||||||||||||||
|
Subroutine
munge_request: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 421 | 0 | my($client, $req) = @_; | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 0 | $req->accept(join(',', | |||||||||||||||||||||||||||
| 424 | media_type('entry')->without_parameters, | ||||||||||||||||||||||||||||
| 425 | media_type('service'), media_type('categories'), | ||||||||||||||||||||||||||||
| 426 | '*/*', | ||||||||||||||||||||||||||||
| 427 | )); | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 0 | ▶ | return unless $client->username; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 0 | my $nonce = sha1(sha1(time.{}.rand().$$)); | |||||||||||||||||||||||||||
| 432 | 0 | my $now = datetime->w3cz; | |||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | 0 | ▶ | my $wsse = sprintf( | ||||||||||||||||||||||||||
|
Condition0%0/4
$client->username || ''
$client->password || ''
MC/DC0%0/1
$client->username || ''
$client->username
MC/DC0%0/1
$client->password || ''
$client->password
Truth table0%0/2
A
A= $client->username
Truth table0%0/2
A
A= $client->password
| |||||||||||||||||||||||||||||
| 435 | qq{UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"}, | ||||||||||||||||||||||||||||
| 436 | ($client->username || ''), | ||||||||||||||||||||||||||||
| 437 | encode_base64(sha1($nonce.$now.($client->password || '')), ''), | ||||||||||||||||||||||||||||
| 438 | encode_base64($nonce, ''), | ||||||||||||||||||||||||||||
| 439 | $now, | ||||||||||||||||||||||||||||
| 440 | ); | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 0 | $req->header('X-WSSE' => $wsse); | |||||||||||||||||||||||||||
| 443 | 0 | $req->authorization('WSSE profile="UsernameToken"'); | |||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | # see 9.7.1 in RFC 5023 | ||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub _escape { | ||||||||||||||||||||||||||
|
Subroutine
_escape: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 448 | 0 | my ($slug) = @_; | |||||||||||||||||||||||||||
| 449 | 0 | return uri_escape(encode_utf8($slug), "\x00-\x19\x25-\x25\x7e-\xff"); | |||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | package Atompub::Client::Info; | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | 4 | my $Info; | |||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 1 | ▶ | sub instance { | ||||||||||||||||||||||||||
|
Subroutine
instance: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 457 | 1 | my($class) = @_; | |||||||||||||||||||||||||||
| 458 | 1 | ▶ | $Info ||= bless { info => {} }, $class; | ||||||||||||||||||||||||||
|
Condition50%1/2
$Info ||= bless({"info", {}}, $class)
MC/DC0%0/1
$Info ||= bless({"info", {}}, $class)
$Info
Truth table50%1/2
A
A= $Info
| |||||||||||||||||||||||||||||
| 459 | 1 | $Info; | |||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 3 | ▶ | sub put { | ||||||||||||||||||||||||||
|
Subroutine
put: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 463 | 3 | my($self, $uri, @args) = @_; | |||||||||||||||||||||||||||
| 464 | 3 | ▶ | return unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 465 | 3 | ▶ | if (@args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | 2 | $self->{info}{$uri} = $self->_clone_collection(@args); | |||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||
| 468 | else { | ||||||||||||||||||||||||||||
| 469 | 1 | delete $self->{info}{$uri}; | |||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | 3 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 474 | 3 | my($self, $uri) = @_; | |||||||||||||||||||||||||||
| 475 | 3 | ▶ | return unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 476 | 3 | $self->{info}{$uri}; | |||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | 0 | ▶ | sub _get_categories { | ||||||||||||||||||||||||||
|
Subroutine
_get_categories: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 480 | 0 | my($self, $client, $href) = @_; | |||||||||||||||||||||||||||
| 481 | 0 | ▶ | return unless $client; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 482 | 0 | $client->getCategories($href); | |||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 2 | ▶ | sub _clone_collection { | ||||||||||||||||||||||||||
|
Subroutine
_clone_collection: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 486 | 2 | my($self, $coll_arg, $client) = @_; | |||||||||||||||||||||||||||
| 487 | 2 | ▶ | return unless UNIVERSAL::isa($coll_arg, 'XML::Atom::Collection'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 488 | 2 | my $coll = XML::Atom::Collection->new; | |||||||||||||||||||||||||||
| 489 | 2 | $coll->title($coll_arg->title); | |||||||||||||||||||||||||||
| 490 | 2 | $coll->href($coll_arg->href); | |||||||||||||||||||||||||||
| 491 | 2 | ▶ | $coll->accept($coll_arg->accepts) if $coll_arg->accept; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | 1 | my @cats = grep { defined $_ } | |||||||||||||||||||||||||||
| 493 | 2 | ▶ | map { $_->href ? $self->_get_categories($client, $_->href) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 494 | : $self->_clone_categories($_) } | ||||||||||||||||||||||||||||
| 495 | $coll_arg->categories; | ||||||||||||||||||||||||||||
| 496 | 2 | $coll->categories(@cats); | |||||||||||||||||||||||||||
| 497 | 2 | $coll; | |||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | 1 | ▶ | sub _clone_categories { | ||||||||||||||||||||||||||
|
Subroutine
_clone_categories: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 501 | 1 | my($self, $cats_arg) = @_; | |||||||||||||||||||||||||||
| 502 | 1 | my $cats = XML::Atom::Categories->new; | |||||||||||||||||||||||||||
| 503 | 1 | ▶ | $cats->fixed($cats_arg->fixed) if $cats_arg->fixed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 504 | 1 | ▶ | $cats->scheme($cats_arg->scheme) if $cats_arg->scheme; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 505 | 1 | my @cat = map { my $cat = XML::Atom::Category->new; | |||||||||||||||||||||||||||
| 506 | 3 | $cat->term($_->term); | |||||||||||||||||||||||||||
| 507 | 3 | ▶ | $cat->scheme($_->scheme) if $_->scheme; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 508 | 3 | ▶ | $cat->label($_->label) if $_->label; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 509 | 3 | $cat } | |||||||||||||||||||||||||||
| 510 | $cats_arg->category; | ||||||||||||||||||||||||||||
| 511 | 1 | $cats->category(@cat); | |||||||||||||||||||||||||||
| 512 | 1 | $cats; | |||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | package Atompub::Client::Cache; | ||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | my $Cache; | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | 1 | ▶ | sub instance { | ||||||||||||||||||||||||||
|
Subroutine
instance: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 520 | 1 | my($class) = @_; | |||||||||||||||||||||||||||
| 521 | 1 | ▶ | $Cache ||= bless { cache => {} }, $class; | ||||||||||||||||||||||||||
|
Condition50%1/2
$Cache ||= bless({"cache", {}}, $class)
MC/DC0%0/1
$Cache ||= bless({"cache", {}}, $class)
$Cache
Truth table50%1/2
A
A= $Cache
| |||||||||||||||||||||||||||||
| 522 | 1 | $Cache; | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | 2 | ▶ | sub put { | ||||||||||||||||||||||||||
|
Subroutine
put: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 526 | 2 | my($self, $uri, @args) = @_; | |||||||||||||||||||||||||||
| 527 | 2 | ▶ | return unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 528 | 2 | ▶ | if (@args) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 529 | 1 | $self->{cache}{$uri} = Atompub::Client::Cache::Resource->new(@args); | |||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||
| 531 | else { | ||||||||||||||||||||||||||||
| 532 | 1 | delete $self->{cache}{$uri}; | |||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 2 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 537 | 2 | my($self, $uri) = @_; | |||||||||||||||||||||||||||
| 538 | 2 | ▶ | return unless $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 539 | 2 | $self->{cache}{$uri}; | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | package Atompub::Client::Cache::Resource; | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 545 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 546 | 4 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | 4 | __PACKAGE__->mk_accessors(qw(resource last_modified etag)); | |||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | 4 | *rc = \&resource; | |||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||
| 553 | 1 | my($class, $args) = @_; | |||||||||||||||||||||||||||
| 554 | 1 | ▶ | my $rc = $args->{resource} || $args->{rc} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args->{'resource'} || $args->{'rc'}
MC/DC0%0/2
$args->{'resource'} || $args->{'rc'}
$args->{'resource'}
$args->{'rc'}
Truth table33%1/3
A || B
A= $args->{'resource'}B= $args->{'rc'}
| |||||||||||||||||||||||||||||
| 555 | bless { | ||||||||||||||||||||||||||||
| 556 | resource => $rc, | ||||||||||||||||||||||||||||
| 557 | last_modified => $args->{last_modified}, | ||||||||||||||||||||||||||||
| 558 | etag => $args->{etag}, | ||||||||||||||||||||||||||||
| 559 | 1 | }, $class; | |||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | 4 | 1; | |||||||||||||||||||||||||||
| 563 | __END__ | ||||||||||||||||||||||||||||