| 1 | package Catalyst::Controller::Atompub::Collection; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Atompub::DateTime qw(datetime); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Atompub::MediaType qw(media_type); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Atompub::Util qw(is_acceptable_media_type is_allowed_category); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Catalyst::Utils; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use HTTP::Status; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use NEXT; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Text::CSV; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use Time::HiRes qw(gettimeofday); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use XML::Atom::Entry; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use base qw(Catalyst::Controller::Atompub::Base); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | __PACKAGE__->mk_accessors(qw(edited)); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | my %COLLECTION_METHOD = ( | |||||||||||||||||||||||||||||||||||||||||
| 26 | GET => '_list', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | HEAD => '_list', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | POST => '_create', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | my %RESOURCE_METHOD = ( | |||||||||||||||||||||||||||||||||||||||||
| 31 | GET => '_read', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | HEAD => '_read', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | POST => '_create', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | PUT => '_update', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | DELETE => '_delete', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | sub auto :Private { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | $self->{resources} = []; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # access to the collection | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub default :Private { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | my $method = $COLLECTION_METHOD{ uc $c->req->method }; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | unless ($method) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $c->res->headers->header(Allow => 'GET, HEAD, POST'); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return $self->error($c, RC_METHOD_NOT_ALLOWED); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | $self->$method($c); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub edit_uri :LocalRegex('^([^-?&#][^?&#]*)') { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edit_uri: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $method = $RESOURCE_METHOD{ uc $c->req->method }; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | unless ($method) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $c->res->headers->header(Allow => 'GET, HEAD, PUT, DELETE'); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return $self->error($c, RC_METHOD_NOT_ALLOWED); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $self->$method($c); | |||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub resource { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resource: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my($self, $rc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($rc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | push @{ $self->{resources} }, $rc; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | [ grep { $_ } @{ $self->{resources} } ]->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | *rc = \&resource; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | my @ACCESSORS = ( | |||||||||||||||||||||||||||||||||||||||||
| 78 | [ 'collection_resource', 'feed', 'is_collection' ], | ||||||||||||||||||||||||||||||||||||||||||
| 79 | [ 'entry_resource', 'entry', 'is_entry' ], | ||||||||||||||||||||||||||||||||||||||||||
| 80 | [ 'media_resource', undef, 'is_media' ], | ||||||||||||||||||||||||||||||||||||||||||
| 81 | [ 'media_link_entry', 'entry', 'is_entry' ], | ||||||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | for my $accessor (@ACCESSORS) { | |||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 16 | my($method, $type, $is) = @$accessor; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | ▶ | *{$method} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 5 | my($self, $rc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 5 | ▶ | if ($rc) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | $rc->type(media_type($type)) if $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | push @{ $self->{resources} }, $rc; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | ▶ | grep { !$_->type || $_->$is } | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
!$_->type || $_->$is
MC/DC0%0/2
!$_->type || $_->$is
!$_->type
$_->$is
Truth table33%1/3
not(A) || B
A= !$_->typeB= $_->$is
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | grep { $_ } | |||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | @{ $self->{resources} } | |||||||||||||||||||||||||||||||||||||||||
| 98 | ]->[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 16 | }; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 5 | ▶ | sub make_collection_uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_collection_uri: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table66%2/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | $c->req->base.$class->action_namespace($c); | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub make_edit_uri { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_edit_uri: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my($self, $c, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $collection_uri = $self->info->get($c, $self)->href; | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $basename; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if (my $slug = $c->req->slug) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $slug = uri_unescape $slug; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $slug =~ s/^\s+//; $slug =~ s/\s+$//; $slug =~ s/[.\s]+/_/; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $basename = uri_escape lc $slug; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my($sec, $usec) = gettimeofday; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $basename | |||||||||||||||||||||||||||||||||||||||||
| 123 | = join '-', strftime('%Y%m%d-%H%M%S', localtime($sec)), sprintf('%06d', $usec); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my @media_types = map { media_type($_) } ('entry', @args); | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my @uris; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | for my $media_type (@media_types) { | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | my $ext = $media_type->extension || 'bin'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$media_type->extension || 'bin'
MC/DC0%0/1
$media_type->extension || 'bin'
$media_type->extension
Truth table0%0/2
A
A= $media_type->extension
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $name = join '.', $basename, $ext; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | push @uris, join '/', $collection_uri, $name; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | wantarray ? @uris : $uris[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | for my $operation (qw(list create read update delete)) { | |||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 20 | ▶ | *{"do_$operation"} = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | my($self, $c, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 142 | return $self->error($c, RC_METHOD_NOT_ALLOWED) | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | unless UNIVERSAL::isa($self->{handler}{$operation}, 'CODE'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | $self->{handler}{$operation}($self, $c, @args); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 20 | }; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | sub _list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_list: called CC=8 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | my $feed = XML::Atom::Feed->new; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | my $title = $self->info->get($c, $self)->title; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | $feed->title($title); | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | if ($self->{author}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $author = XML::Atom::Person->new; | |||||||||||||||||||||||||||||||||||||||||
| 157 | $self->{author}{$_} and $author->$_($self->{author}{$_}) | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | for (qw(name email uri)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $feed->author($author); | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | $feed->updated(datetime->w3c); | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | my $uri = $self->make_collection_uri($c); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | $feed->id($uri); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | $feed->self_link($uri); | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | $self->collection_resource( Catalyst::Controller::Atompub::Collection::Resource->new({ | |||||||||||||||||||||||||||||||||||||||||
| 169 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | body => $feed, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | }) ); | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | ▶ | $self->do_list($c) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | or return $self->error($c, RC_INTERNAL_SERVER_ERROR, "Cannot list collection: $uri"); | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | return unless $self->collection_resource; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | ▶ | $c->res->content_type($self->collection_resource->type) unless $c->res->content_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | ▶ | $c->res->body($self->collection_resource->serialize) unless $c->res->body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub _create { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create: not called CC=22 SCAR=62.3
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $media_type | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
media_type($c->req->content_type) || media_type('application/octet-stream')
MC/DC0%0/2
media_type($c->req->content_type) || media_type('application/octet-stream')
media_type($c->req->content_type)
media_type('application/octet-stream')
Truth table0%0/3
A || B
A= media_type($c->req->content_type)B= media_type('application/octet-stream')
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | = media_type($c->req->content_type) || media_type('application/octet-stream'); | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $coll = $self->info->get($c, $self); | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return $self->error($c, RC_UNSUPPORTED_MEDIA_TYPE, "Unsupported media type: $media_type") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | unless is_acceptable_media_type($coll, $media_type); | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $self->edited(datetime); | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ($media_type->is_a('entry')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my $entry = $self->_fixup_entry($c) or return $self->error($c); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $self->entry_resource( Catalyst::Controller::Atompub::Collection::Resource->new({ | |||||||||||||||||||||||||||||||||||||||||
| 199 | body => $entry, | ||||||||||||||||||||||||||||||||||||||||||
| 200 | }) ); | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my ($uri) = $self->make_edit_uri($c) or return $self->error($c); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | $entry = $self->_assign_uri_for_entry($c, $entry, $uri) or return $self->error($c); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $self->entry_resource->uri($uri); | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | my $entry = $self->_create_media_link_entry($c) or return $self->error($c); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my $media = read_file($c->req->body, binmode => ':raw'); | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $self->media_link_entry( Catalyst::Controller::Atompub::Collection::Resource->new({ | |||||||||||||||||||||||||||||||||||||||||
| 212 | body => $entry, | ||||||||||||||||||||||||||||||||||||||||||
| 213 | }) ); | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $self->media_resource( Catalyst::Controller::Atompub::Collection::Resource->new({ | |||||||||||||||||||||||||||||||||||||||||
| 216 | body => $media, | ||||||||||||||||||||||||||||||||||||||||||
| 217 | type => $media_type, | ||||||||||||||||||||||||||||||||||||||||||
| 218 | }) ); | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my($entry_uri, $media_uri) = $self->make_edit_uri($c, $media_type) or return $self->error($c); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | $entry = $self->_assign_uri_for_entry($c, $entry, $entry_uri, $media_uri) or return $self->error($c); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $self->media_link_entry->uri($entry_uri); | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $self->media_resource->uri($media_uri); | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | return $self->error($c, RC_BAD_REQUEST, 'No body') unless $c->req->body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | $self->do_create($c) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | or return $self->error($c, RC_INTERNAL_SERVER_ERROR, | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 'Cannot create new resource: '.$self->make_collection_uri($c)); | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $c->res->status(RC_CREATED); | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if (!defined $c->res->etag || !$c->res->last_modified) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $c->res->etag and $c->res->last_modified
MC/DC0%0/2
defined $c->res->etag and $c->res->last_modified
defined $c->res->etag
$c->res->last_modified
Truth table0%0/3
A and B
A= defined $c->res->etagB= $c->res->last_modified
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my %ret = $self->find_version($c, $self->entry_resource->uri); | |||||||||||||||||||||||||||||||||||||||||
| 237 | $c->res->etag($ret{etag}) | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if !defined $c->res->etag && defined $ret{etag}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $c->res->etag and defined $ret{"etag"}
MC/DC0%0/2
not defined $c->res->etag and defined $ret{"etag"}
not defined $c->res->etag
defined $ret{"etag"}
Truth table0%0/3
not(A) and B
A= not defined $c->res->etagB= defined $ret{"etag"}
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | $c->res->last_modified($ret{last_modified}) | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if !$c->res->last_modified && $ret{last_modified}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $c->res->last_modified and $ret{"last_modified"}
MC/DC0%0/2
not $c->res->last_modified and $ret{"last_modified"}
not $c->res->last_modified
$ret{"last_modified"}
Truth table0%0/3
not(A) and B
A= not $c->res->last_modifiedB= $ret{"last_modified"}
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | return unless $self->entry_resource; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | $c->res->redirect($self->entry_resource->uri, RC_CREATED) unless $c->res->redirect; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | $c->res->content_type($self->entry_resource->type) unless $c->res->content_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $c->res->body($self->entry_resource->serialize) unless $c->res->body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | sub _read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | return $c->res->status(RC_NOT_MODIFIED) unless $self->_is_modified($c); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $uri = $c->req->uri->no_query; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my @accepts = $self->info->get($c, $self)->accepts; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | my $media_type | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
@accepts == 1 and not $accepts[0] =~ /\*/
MC/DC0%0/2
@accepts == 1 and not $accepts[0] =~ /\*/
@accepts == 1
not $accepts[0] =~ /\*/
Truth table0%0/3
A and not(B)
A= @accepts == 1B= not $accepts[0] =~ /\*/
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | = @accepts == 0 ? media_type('entry') | ||||||||||||||||||||||||||||||||||||||||||
| 260 | : @accepts == 1 && $accepts[0] !~ /\*/ ? media_type($accepts[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 261 | : undef; | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $self->rc( Catalyst::Controller::Atompub::Collection::Resource->new({ | |||||||||||||||||||||||||||||||||||||||||
| 264 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||
| 265 | type => $media_type, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | }) ); | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | $self->do_read($c) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | or return $self->error( $c, RC_INTERNAL_SERVER_ERROR, "Cannot read resource: $uri" ); | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if (!defined $c->res->etag || !$c->res->last_modified) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $c->res->etag and $c->res->last_modified
MC/DC0%0/2
defined $c->res->etag and $c->res->last_modified
defined $c->res->etag
$c->res->last_modified
Truth table0%0/3
A and B
A= defined $c->res->etagB= $c->res->last_modified
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my %ret = $self->find_version($c, $uri); | |||||||||||||||||||||||||||||||||||||||||
| 273 | $c->res->etag($ret{etag}) | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if !defined $c->res->etag && defined $ret{etag}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $c->res->etag and defined $ret{"etag"}
MC/DC0%0/2
not defined $c->res->etag and defined $ret{"etag"}
not defined $c->res->etag
defined $ret{"etag"}
Truth table0%0/3
not(A) and B
A= not defined $c->res->etagB= defined $ret{"etag"}
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | $c->res->last_modified($ret{last_modified}) | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if !$c->res->last_modified && $ret{last_modified}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $c->res->last_modified and $ret{"last_modified"}
MC/DC0%0/2
not $c->res->last_modified and $ret{"last_modified"}
not $c->res->last_modified
$ret{"last_modified"}
Truth table0%0/3
not(A) and B
A= not $c->res->last_modifiedB= $ret{"last_modified"}
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | return unless $self->rc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | $c->res->content_type($self->rc->type) unless $c->res->content_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | return if $c->req->method eq 'HEAD'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | $c->res->body($self->rc->serialize) unless $c->res->body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | sub _update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | return $self->error($c, RC_PRECONDITION_FAILED, 'Missing If-match header') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | if $self->_is_modified($c); | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | my $media_type | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
media_type($c->req->content_type) || media_type('application/octet-stream')
MC/DC0%0/2
media_type($c->req->content_type) || media_type('application/octet-stream')
media_type($c->req->content_type)
media_type('application/octet-stream')
Truth table0%0/3
A || B
A= media_type($c->req->content_type)B= media_type('application/octet-stream')
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | = media_type($c->req->content_type) || media_type('application/octet-stream'); | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my $coll = $self->info->get($c, $self); | |||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | return $self->error($c, RC_UNSUPPORTED_MEDIA_TYPE, "Unsupported media type: $media_type") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
is_acceptable_media_type($coll, $media_type) or $media_type->is_a("entry")
MC/DC0%0/2
is_acceptable_media_type($coll, $media_type) or $media_type->is_a("entry")
is_acceptable_media_type($coll, $media_type)
$media_type->is_a("entry")
Truth table0%0/3
A or B
A= is_acceptable_media_type($coll, $media_type)B= $media_type->is_a("entry")
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | if !is_acceptable_media_type($coll, $media_type) && !$media_type->is_a('entry'); | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $self->edited(datetime); | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $uri = $c->req->uri->no_query; | |||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my $body; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | if ($media_type->is_a('entry')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $media_type = media_type('entry'); | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | $body = $self->_fixup_entry($c) or return $self->error($c); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | $body = $self->_assign_uri_for_entry($c, $body, $uri) or return $self->error($c); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | return $self->error($c, RC_BAD_REQUEST, 'No body') unless $c->req->body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $body = read_file($c->req->body, binmode => ':raw'); | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $self->rc( Catalyst::Controller::Atompub::Collection::Resource->new({ | |||||||||||||||||||||||||||||||||||||||||
| 318 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||
| 319 | body => $body, | ||||||||||||||||||||||||||||||||||||||||||
| 320 | type => $media_type, | ||||||||||||||||||||||||||||||||||||||||||
| 321 | }) ); | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | $self->do_update($c) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | or return $self->error($c, RC_INTERNAL_SERVER_ERROR, "Cannot update resource: $uri"); | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if (!defined $c->res->etag || !$c->res->last_modified) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $c->res->etag and $c->res->last_modified
MC/DC0%0/2
defined $c->res->etag and $c->res->last_modified
defined $c->res->etag
$c->res->last_modified
Truth table0%0/3
A and B
A= defined $c->res->etagB= $c->res->last_modified
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my %ret = $self->find_version($c, $uri); | |||||||||||||||||||||||||||||||||||||||||
| 328 | $c->res->etag($ret{etag}) | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if !defined $c->res->etag && defined $ret{etag}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $c->res->etag and defined $ret{"etag"}
MC/DC0%0/2
not defined $c->res->etag and defined $ret{"etag"}
not defined $c->res->etag
defined $ret{"etag"}
Truth table0%0/3
not(A) and B
A= not defined $c->res->etagB= defined $ret{"etag"}
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | $c->res->last_modified($ret{last_modified}) | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if !$c->res->last_modified && $ret{last_modified}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $c->res->last_modified and $ret{"last_modified"}
MC/DC0%0/2
not $c->res->last_modified and $ret{"last_modified"}
not $c->res->last_modified
$ret{"last_modified"}
Truth table0%0/3
not(A) and B
A= not $c->res->last_modifiedB= $ret{"last_modified"}
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | return unless $self->rc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | return if $c->res->status eq RC_NO_CONTENT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | $c->res->content_type($self->rc->type) unless $c->res->content_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | $c->res->body($self->rc->serialize) unless $c->res->body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | sub _delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_delete: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | # If-Match nor If-Unmodified-Since header is not required on DELETE | ||||||||||||||||||||||||||||||||||||||||||
| 345 | # return $self->error($c, RC_PRECONDITION_FAILED) | ||||||||||||||||||||||||||||||||||||||||||
| 346 | # if $self->_is_modified($c); | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $uri = $c->req->uri->no_query; | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $self->rc( Catalyst::Controller::Atompub::Collection::Resource->new({ | |||||||||||||||||||||||||||||||||||||||||
| 351 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||
| 352 | }) ); | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | $c->res->status(RC_NO_CONTENT); | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $self->do_delete($c) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | or return $self->error($c, RC_INTERNAL_SERVER_ERROR, "Cannot delete resource: $uri"); | ||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | sub find_version {} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_version: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | sub _is_modified { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_modified: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $method = $c->req->method; | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my %ret = $self->find_version($c, $c->req->uri->no_query); | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | my $etag = $ret{etag}; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | my $last_modified = $ret{last_modified}; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | return $method eq 'GET' ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $etag or $last_modified
MC/DC0%0/2
defined $etag or $last_modified
defined $etag
$last_modified
Truth table0%0/3
A or B
A= defined $etagB= $last_modified
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | if !defined $etag && !$last_modified; # if don't check version | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | my $match = $method eq 'GET' ? $c->req->if_none_match : $c->req->if_match; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | $match =~ s/^['"](.+)['"]$/$1/ if $match; #" unquote | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | return 1 if defined $etag && (!defined $match || $etag ne $match); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $etag and !defined($match) || $etag ne $match
not defined $match or $etag ne $match
MC/DC0%0/3
defined $etag and !defined($match) || $etag ne $match
defined $etag
not defined $match
$etag ne $match
Truth table0%0/4
A and not(B) or C
A= defined $etagB= not defined $matchC= $etag ne $match
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | my $since = $method eq 'GET' ? $c->req->if_modified_since : $c->req->if_unmodified_since; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | return 1 if $last_modified && (!$since || datetime($last_modified) != datetime($since)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$last_modified and !$since || datetime($last_modified) != datetime($since)
not $since or datetime($last_modified) != datetime($since)
MC/DC0%0/3
$last_modified and !$since || datetime($last_modified) != datetime($since)
$last_modified
not $since
datetime($last_modified) != datetime($since)
Truth table0%0/4
A and not(B) or C
A= $last_modifiedB= not $sinceC= datetime($last_modified) != datetime($since)
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | sub _fixup_entry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fixup_entry: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $entry; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | $entry = XML::Atom::Entry->new($c->req->body) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | or die XML::Atom::Entry->errstr; | ||||||||||||||||||||||||||||||||||||||||||
| 394 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | return $self->error($c, RC_BAD_REQUEST, $EVAL_ERROR); | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | return $self->error($c, RC_BAD_REQUEST, 'Forbidden category') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | unless is_allowed_category($self->info->get($c, $self), $entry->category); | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $entry->edited($self->edited->w3c); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | $entry->updated($self->edited->w3c) unless $entry->updated; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | if (!$entry->author) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my $author = XML::Atom::Person->new; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $author->name(''); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $entry->author($author); | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | elsif (!$entry->author->name) { | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $entry->author->name(''); | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | $entry->title('') unless defined $entry->title; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $entry; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | sub _assign_uri_for_entry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assign_uri_for_entry: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my($self, $c, $entry, $entry_uri, $media_uri) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | $entry->id(_make_id($entry_uri)) unless $entry->id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $entry->edit_link($entry_uri); | |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | if ($media_uri) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $entry->edit_media_link($media_uri); | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | unless ($entry->content) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | my $content = XML::Atom::Content->new; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | $content->src($media_uri); | |||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $content->type($c->req->content_type); | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $entry->content($content); | |||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $entry; | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | sub _make_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my($uri) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | $uri = URI->new($uri); | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $path = $uri->path; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | $path =~ s{#}{/}g; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my $dt = datetime->dt; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | 'tag:'.$uri->authority.','.$dt->ymd.':'.$path; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | sub _create_media_link_entry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_media_link_entry: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $entry = XML::Atom::Entry->new; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | $entry->edited($self->edited->w3c); | |||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | $entry->updated($self->edited->w3c) unless $entry->updated; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | $entry->title(uri_unescape $c->req->slug || ''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$c->req->slug || ''
MC/DC0%0/1
$c->req->slug || ''
$c->req->slug
Truth table0%0/2
A
A= $c->req->slug
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $entry->summary(''); | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $entry; | |||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 30 | ▶ | sub create_action { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_action: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 30 | my($self, %args) = @_; # %args: namespace, name, reverse, class, attributes, code | |||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 30 | my $attr = lc $args{attributes}{Atompub}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 30 | my $code = $args{code}; | |||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 30 | my $csv = Text::CSV->new({ allow_whitespace => 1 }); | |||||||||||||||||||||||||||||||||||||||||
| 461 | 30 | $csv->parse($attr); | |||||||||||||||||||||||||||||||||||||||||
| 462 | 30 | for ($csv->fields) { | |||||||||||||||||||||||||||||||||||||||||
| 463 | 30 | ▶ | $self->{handler}{$_} = $code if length $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | # %args = (); # removes 'Loaded Private actions' message in initialization | ||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 30 | $self->NEXT::create_action(%args); | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | sub URI::no_query { [ split /[?&]/, shift->canonical ]->[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
no_query: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | package Catalyst::Controller::Atompub::Collection::Resource; | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 4 | ▶ | use Atompub::MediaType qw(media_type); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 4 | ▶ | use base qw(Class::Accessor::Fast); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 4 | __PACKAGE__->mk_accessors(qw(uri type body)); | |||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 1 | my($class, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | ▶ | $args ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args ||= {}
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | bless $args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 4 | ▶ | sub is_collection { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_collection: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 4 | ▶ | my $media_type = media_type($self->type) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 4 | return $media_type->is_a('feed'); | |||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | sub is_entry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_entry: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | my $media_type = media_type($self->type) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | return $media_type->is_a('entry'); | |||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | sub is_media { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_media: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | my $media_type = media_type($self->type) or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | return !$media_type->is_a('application/atom+xml'); | |||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | ▶ | sub serialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | my $body = $self->body; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | ▶ | UNIVERSAL::can($body, 'as_xml') ? $body->as_xml : $body; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 511 | __END__ | ||||||||||||||||||||||||||||||||||||||||||