| 1 | # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # vim:ts=8:sw=2:et:sta:sts=2 | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Author: rmp | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Created: 2007-03-28 | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # method id action aspect result CRUD | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # ===================================== | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # POST n create - create * | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # POST y create update update * | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # POST y create delete delete * | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # GET n read - list | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # GET n read add add/new | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # GET y read - read * | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # GET y read edit edit | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | package ClearPress::controller; | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | ▶ | use ClearPress::decorator; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | ▶ | use ClearPress::view::error; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | use CGI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | use HTTP::Status qw(:constants :is); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | use HTTP::Headers; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | our $VERSION = q[2026.07.25]; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | our $CRUD = { # these map HTTP verbs to $action | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | POST => 'create', | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | GET => 'read', | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | PUT => 'update', | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | DELETE => 'delete', | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | OPTIONS => 'options', | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | HEAD => 'head', | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | TRACE => 'null', | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | our $REST = { # these assist sanitising $aspect | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | create => 'POST', | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | read => 'GET', | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | update => 'PUT|POST', | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | delete => 'DELETE|POST', | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | add => 'GET', | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | edit => 'GET', | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | list => 'GET', | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | options => 'OPTIONS', | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | head => 'HEAD', | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | null => 'TRACE' | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 266 | ▶ | sub accept_extensions { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_extensions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 266 | {'.html' => q[]}, | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | {'.xml' => q[_xml]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | {'.png' => q[_png]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | {'.svg' => q[_svg]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | {'.svgz' => q[_svgz]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | {'.jpg' => q[_jpg]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | {'.rss' => q[_rss]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | {'.atom' => q[_atom]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | {'.js' => q[_json]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | {'.json' => q[_json]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | {'.ical' => q[_ical]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | {'.txt' => q[_txt]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | {'.xls' => q[_xls]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | {'.csv' => q[_csv]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | {'.ajax' => q[_ajax]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 133 | ▶ | sub accept_headers { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_headers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # {'text/html' => q[]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 133 | {'application/json' => q[_json]}, | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | {'text/xml' => q[_xml]}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 132 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 132 | my ($class, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 132 | ▶ | $self ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self ||= {}
MC/DC0%0/1
$self ||= {}
$self
Truth table50%1/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 132 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 132 | $self->init(); | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # We may be given a database handle from the cache with an open | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # transaction (e.g. from running a few selects), so on controller | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # construction (effectively per-page-view), we rollback any open | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # transaction on the database handle we've been given. | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 132 | $self->util->dbh->rollback(); | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 131 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 132 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # ignore any error | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # carp qq[Failed per-request rollback on fresh database handle: $EVAL_ERROR]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 132 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 132 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 132 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 283 | ▶ | sub util { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
util: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 283 | my ($self, $util) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 283 | ▶ | if(defined $util) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->{util} = $util; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 283 | return $self->{util}; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 165 | ▶ | sub packagespace { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
packagespace: called CC=6 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 165 | my ($self, $type, $entity, $util) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 165 | ▶ | if($type ne 'view' && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type ne "view" and $type ne "model"
MC/DC0%0/2
$type ne "view" and $type ne "model"
$type ne "view"
$type ne "model"
Truth table66%2/3
A and B
A= $type ne "view"B= $type ne "model"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | $type ne 'model') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 165 | ▶ | $util ||= $self->util(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$util ||= $self->util
MC/DC0%0/2
$util ||= $self->util
$util
$self->util
Truth table33%1/3
A ||= B
A= $utilB= $self->util
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 165 | my $entity_name = $entity; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 165 | ▶ | if($util->config->SectionExists('packagemap')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # if there are uri-to-package maps, process here | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 165 | my $map = $util->config->val('packagemap', $entity); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 165 | ▶ | if($map) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 3 | $entity = $map; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 165 | my $namespace = $self->namespace($util); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 165 | return "${namespace}::${type}::$entity"; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 133 | ▶ | sub process_request { ## no critic (Subroutines::ProhibitExcessComplexity) | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_request: called CC=56 SCAR=40.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 133 | my ($self, $headers) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 133 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 133 | ▶ | my $method = $ENV{REQUEST_METHOD} || 'GET'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'REQUEST_METHOD'} || 'GET'
MC/DC0%0/1
$ENV{'REQUEST_METHOD'} || 'GET'
$ENV{'REQUEST_METHOD'}
Truth table50%1/2
A
A= $ENV{'REQUEST_METHOD'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 133 | my $action = $CRUD->{uc $method}; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 133 | ▶ | my $pi = $ENV{PATH_INFO} || q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'PATH_INFO'} || ''
MC/DC0%0/1
$ENV{'PATH_INFO'} || ''
$ENV{'PATH_INFO'}
Truth table50%1/2
A
A= $ENV{'PATH_INFO'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 133 | ▶ | my $accept = $ENV{HTTP_ACCEPT} || q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{'HTTP_ACCEPT'} || ''
MC/DC100%1/1
$ENV{'HTTP_ACCEPT'} || ''
$ENV{'HTTP_ACCEPT'}
Truth table100%2/2
A
A= $ENV{'HTTP_ACCEPT'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 133 | ▶ | my $qs = $ENV{QUERY_STRING} || q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{'QUERY_STRING'} || ''
MC/DC100%1/1
$ENV{'QUERY_STRING'} || ''
$ENV{'QUERY_STRING'}
Truth table100%2/2
A
A= $ENV{'QUERY_STRING'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 133 | ▶ | my $hxrw = $ENV{HTTP_X_REQUESTED_WITH} || q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{'HTTP_X_REQUESTED_WITH'} || ''
MC/DC100%1/1
$ENV{'HTTP_X_REQUESTED_WITH'} || ''
$ENV{'HTTP_X_REQUESTED_WITH'}
Truth table100%2/2
A
A= $ENV{'HTTP_X_REQUESTED_WITH'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 133 | my $xhr = ($hxrw =~ /XMLHttpRequest/smix); | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | my $accept_extensions = join q[|], | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1995 | grep { defined } | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1995 | ▶ | map { m{[.](\S+)$}smx; $1 || undef; } ## no critic (ProhibitCaptureWithoutTest, ProhibitComplexMappings) | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$1 || undef
MC/DC0%0/1
$1 || undef
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1995 | map { join q[,], keys %{$_} } | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 133 | @{$self->accept_extensions()}; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 133 | ▶ | if($xhr && $pi !~ m{(?:$accept_extensions)(?:/[^/]*?)?$}smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$xhr and not $pi =~ m[(?:$accept_extensions)(?:/[^/]*?)?$]msx
MC/DC100%2/2
$xhr and not $pi =~ m[(?:$accept_extensions)(?:/[^/]*?)?$]msx
$xhr
not $pi =~ m[(?:$accept_extensions)(?:/[^/]*?)?$]msx
Truth table100%3/3
A and not(B)
A= $xhrB= not $pi =~ m[(?:$accept_extensions)(?:/[^/]*?)?$]msx
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | ▶ | if($pi =~ /[;]/smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | $pi .= q[_ajax]; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 5 | $pi .= q[.ajax]; | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 133 | my ($entity) = $pi =~ m{^/([^/;.]+)}smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 133 | ▶ | $entity ||= q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$entity ||= ""
MC/DC100%1/1
$entity ||= ""
$entity
Truth table100%2/2
A
A= $entity
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 133 | my ($dummy, $aspect_extra, $id) = $pi =~ m{^/$entity(/(.*))?/([[:lower:][:digit:]:,\-_%@.+\s]+)}smix; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 133 | my ($aspect) = $pi =~ m{;(\S+)}smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 133 | ▶ | if(($action eq 'read') && !$id && !$aspect) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$action eq "read" and not $id and not $aspect
$action eq "read" and not $id
MC/DC100%3/3
$action eq "read" and not $id and not $aspect
$action eq "read"
not $id
not $aspect
Truth table100%4/4
A and not(B) and not(C)
A= $action eq "read"B= not $idC= not $aspect
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 12 | $aspect = 'list'; | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 133 | ▶ | if($action eq 'create' && $id) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$action eq "create" and $id
MC/DC100%2/2
$action eq "create" and $id
$action eq "create"
$id
Truth table100%3/3
A and B
A= $action eq "create"B= $id
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 28 | ▶ | if(!$aspect || $aspect =~ /^update/smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
not $aspect or $aspect =~ /^update/msx
MC/DC100%2/2
not $aspect or $aspect =~ /^update/msx
not $aspect
$aspect =~ /^update/msx
Truth table100%3/3
not(A) or B
A= not $aspectB= $aspect =~ /^update/msx
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 25 | $action = 'update'; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } elsif($aspect =~ /^delete/smx) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | $action = 'delete'; | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 133 | ▶ | $aspect ||= q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$aspect ||= ""
MC/DC100%1/1
$aspect ||= ""
$aspect
Truth table100%2/2
A
A= $aspect
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 133 | ▶ | $aspect_extra ||= q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$aspect_extra ||= ""
MC/DC100%1/1
$aspect_extra ||= ""
$aspect_extra
Truth table100%2/2
A
A= $aspect_extra
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # process request extensions | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 133 | ▶ | my $uriaspect = $self->_process_request_extensions(\$pi, $aspect, $action) || q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_process_request_extensions(\$pi, $aspect, $action) || ''
MC/DC100%1/1
$self->_process_request_extensions(\$pi, $aspect, $action) || ''
$self->_process_request_extensions(\$pi, $aspect, $action)
Truth table100%2/2
A
A= $self->_process_request_extensions(\$pi, $aspect, $action)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 133 | ▶ | if($uriaspect ne $aspect) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 59 | $aspect = $uriaspect; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 59 | ($id) = $pi =~ m{^/$entity/?$aspect_extra/([[:lower:][:digit:]:,\-_%@.+\s]+)}smix; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # process HTTP 'Accept' header | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 133 | $aspect = $self->_process_request_headers(\$accept, $aspect, $action); | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 133 | ▶ | $entity ||= $util->config->val('application', 'default_view'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$entity ||= $util->config->val("application", "default_view")
MC/DC100%2/2
$entity ||= $util->config->val("application", "default_view")
$entity
$util->config->val("application", "default_view")
Truth table100%3/3
A ||= B
A= $entityB= $util->config->val("application", "default_view")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 133 | ▶ | $aspect ||= q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$aspect ||= ""
MC/DC100%1/1
$aspect ||= ""
$aspect
Truth table100%2/2
A
A= $aspect
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 133 | ▶ | $id = CGI->unescape($id||'0'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$id || '0'
MC/DC100%1/1
$id || '0'
$id
Truth table100%2/2
A
A= $id
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # no view determined and no configured default_view | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # pull the first one off the list | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 133 | ▶ | if(!$entity) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | ▶ | my $views = $util->config->val('application', 'views') || q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$util->config->val('application', 'views') || ''
MC/DC100%1/1
$util->config->val('application', 'views') || ''
$util->config->val('application', 'views')
Truth table100%2/2
A
A= $util->config->val('application', 'views')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | $entity = (split /[\s,]+/smx, $views)[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # no view determined, no default_view and none in the list | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 133 | ▶ | if(!$entity) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | croak q[No available views]; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 132 | my $viewclass = $self->packagespace('view', $entity, $util); | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 132 | ▶ | if($aspect_extra) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 43 | $aspect_extra =~ s{/}{_}smxg; | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 132 | ▶ | if($id eq '0') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # no primary key: | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # /thing;method | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # /thing;method_xml | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # /thing.xml;method | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 37 | ▶ | my $tmp = $aspect || $action; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$aspect || $action
MC/DC0%0/2
$aspect || $action
$aspect
$action
Truth table66%2/3
A || B
A= $aspectB= $action
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 37 | ▶ | if($aspect_extra) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $tmp =~ s/_/_${aspect_extra}_/smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if($viewclass->can($tmp)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $aspect = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } elsif($id !~ /^\d+$/smx) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # mangled primary key - attempt to match method in view object | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # /thing/method => list_thing_method (if exists), or read(pk=method) | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # /thing/part1/part2 => list_thing_part1_part2 if exists, or read_thing_part1(pk=part2) | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # /thing/method.xml => list_thing_method_xml (if exists), or read_thing_xml (pk=method) | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # /thing/part1/part2.xml => list_thing_part1_part2_xml (if exists), or read_thing_part1_xml (pk=part2) | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 39 | my $tmp = $aspect; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 39 | ▶ | if($tmp =~ /_/smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 25 | $tmp =~ s/_/_${id}_/smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 14 | $tmp = "${action}_$id"; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 39 | $tmp =~ s/^read/list/smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 39 | $tmp =~ s/^update/create/smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 39 | ▶ | if($aspect_extra) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 20 | $tmp =~ s/_/_${aspect_extra}_/smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 39 | ▶ | if($viewclass->can($tmp)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 17 | $id = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | 17 | $aspect = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # id has been modified, so reset action | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 17 | ▶ | if($aspect =~ /^create/smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | $action = 'create'; | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 22 | ▶ | if($aspect_extra) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 18 | ▶ | if($aspect =~ /_/smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 11 | $aspect =~ s/_/_${aspect_extra}_/smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 7 | $aspect .= "_$aspect_extra"; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } elsif($aspect_extra) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # /thing/method/50 => read_thing_method(pk=50) | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 23 | ▶ | if($aspect =~ /_/smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 12 | $aspect =~ s/_/_${aspect_extra}_/smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 11 | $aspect .= "${action}_$aspect_extra"; | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # fix up aspect | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 132 | my ($firstpart) = $aspect =~ /^${action}_([^_]+)_?/smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 306 | 132 | ▶ | if($firstpart) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 66 | my $restpart = $REST->{$firstpart}; | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | 66 | ▶ | if($restpart) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 8 | ($restpart) = $restpart =~ /^([^|]+)/smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | 8 | ▶ | if($restpart) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 8 | my ($crudpart) = $CRUD->{$restpart}; | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | 8 | ▶ | if($crudpart) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 8 | $aspect =~ s/^${crudpart}_//smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 132 | ▶ | if($aspect !~ /^(?:create|read|update|delete|add|list|edit|options|head)/smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 28 | my $action_extended = $action; | |||||||||||||||||||||||||||||||||||||||||||||
| 321 | 28 | ▶ | if(!$id) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 322 | $action_extended = { | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | read => 'list', | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 9 | ▶ | }->{$action} || $action_extended; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
{'read', 'list'}->{$action} || $action_extended
MC/DC0%0/2
{'read', 'list'}->{$action} || $action_extended
{'read', 'list'}->{$action}
$action_extended
Truth table66%2/3
A || B
A= {'read', 'list'}->{$action}B= $action_extended
| |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 28 | ▶ | $aspect = $action_extended . ($aspect?"_$aspect":q[]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # if($method eq 'OPTIONS') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # $action = 'options'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # $aspect = 'options'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # } | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # sanity checks | ||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 132 | my ($type) = $aspect =~ /^([^_]+)/smx; # read|list|add|edit|create|update|delete | |||||||||||||||||||||||||||||||||||||||||||||
| 339 | 132 | ▶ | if($method !~ /^$REST->{$type}$/smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 3 | $headers->header('Status', HTTP_BAD_REQUEST); | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | 3 | croak qq[Bad request. $aspect ($type) is not a $CRUD->{$method} method]; | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 129 | ▶ | if(!$id && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $id and $aspect =~ /^(?:delete|update|edit|read)/msx
MC/DC100%2/2
not $id and $aspect =~ /^(?:delete|update|edit|read)/msx
not $id
$aspect =~ /^(?:delete|update|edit|read)/msx
Truth table100%3/3
not(A) and B
A= not $idB= $aspect =~ /^(?:delete|update|edit|read)/msx
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | $aspect =~ /^(?:delete|update|edit|read)/smx) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 4 | $headers->header('Status', HTTP_BAD_REQUEST); | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | 4 | croak qq[Bad request. Cannot $aspect without an id]; | |||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 125 | ▶ | if($id && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$id and $aspect =~ /^(?:create|add|list)/msx
MC/DC100%2/2
$id and $aspect =~ /^(?:create|add|list)/msx
$id
$aspect =~ /^(?:create|add|list)/msx
Truth table100%3/3
A and B
A= $idB= $aspect =~ /^(?:create|add|list)/msx
| |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | $aspect =~ /^(?:create|add|list)/smx) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 3 | $headers->header('Status', HTTP_BAD_REQUEST); | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | 3 | croak qq[Bad request. Cannot $aspect with an id]; | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 122 | $aspect =~ s/__/_/smxg; | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | 122 | return ($action, $entity, $aspect, $id); | |||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 133 | ▶ | sub _process_request_extensions { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_request_extensions: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 133 | my ($self, $pi, $aspect, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 133 | my $extensions = join q[], reverse ${$pi} =~ m{([.][^;.]+)}smxg; | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 133 | for my $pair (@{$self->accept_extensions}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1995 | my ($ext, $meth) = %{$pair}; | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1995 | $ext =~ s/[.]/\\./smxg; | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1995 | ▶ | if($extensions =~ s{$ext$}{}smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 59 | ${$pi} =~ s{$ext}{}smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | 59 | ▶ | $aspect ||= $action; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$aspect ||= $action
MC/DC0%0/2
$aspect ||= $action
$aspect
$action
Truth table66%2/3
A ||= B
A= $aspectB= $action
| |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 59 | $aspect =~ s/$meth$//smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | 59 | $aspect .= $meth; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 133 | return $aspect; | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 133 | ▶ | sub _process_request_headers { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_request_headers: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 133 | my ($self, $accept, $aspect, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 133 | for my $pair (@{$self->accept_headers()}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | 266 | my ($header, $meth) = %{$pair}; | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | 266 | ▶ | if(${$accept} =~ /$header$/smx) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | ▶ | $aspect ||= $action; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$aspect ||= $action
MC/DC0%0/2
$aspect ||= $action
$aspect
$action
Truth table33%1/3
A ||= B
A= $aspectB= $action
| |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | $aspect =~ s/$meth$//smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 388 | 1 | $aspect .= $meth; | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 133 | return $aspect; | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 50 | ▶ | sub decorator { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decorator: called CC=8 SCAR=21.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 50 | my ($self, $util, $headers) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 50 | ▶ | if(!$self->{decorator}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 16 | ▶ | my $appname = $util->config->val('application', 'name') || 'Application'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$util->config->val('application', 'name') || 'Application'
MC/DC0%0/1
$util->config->val('application', 'name') || 'Application'
$util->config->val('application', 'name')
Truth table50%1/2
A
A= $util->config->val('application', 'name')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 16 | my $namespace = $self->namespace; | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | 16 | my $decorpkg = "${namespace}::decorator"; | |||||||||||||||||||||||||||||||||||||||||||||
| 403 | 16 | my $config = $util->config; | |||||||||||||||||||||||||||||||||||||||||||||
| 404 | 16 | my $decor; | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 16 | my $ref = { | |||||||||||||||||||||||||||||||||||||||||||||
| 407 | headers => $headers, | ||||||||||||||||||||||||||||||||||||||||||||||
| 408 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 16 | $decor = $decorpkg->new($ref); | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | 16 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 16 | $decor = ClearPress::decorator->new($ref); | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 16 | for my $field ($decor->fields) { | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | 352 | $decor->$field($config->val('application', $field)); | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 16 | ▶ | if(!$decor->title) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 16 | ▶ | $decor->title($config->val('application', 'name') || 'ClearPress Application'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->val('application', 'name') || 'ClearPress Application'
MC/DC0%0/1
$config->val('application', 'name') || 'ClearPress Application'
$config->val('application', 'name')
Truth table50%1/2
A
A= $config->val('application', 'name')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # only cache decorator when $headers is passed | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 16 | ▶ | if($headers) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 16 | $self->{decorator} = $decor; | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 50 | return $self->{decorator}; | |||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 16 | ▶ | sub session { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
session: called CC=3 SCAR=13.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 16 | my ($self, $util) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 437 | 16 | ▶ | return $self->decorator($util || $self->util())->session() || {}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$self->decorator($util || $self->util)->session || {}
$util || $self->util
MC/DC0%0/1
$self->decorator($util || $self->util)->session || {}
$self->decorator($util || $self->util)->session
MC/DC0%0/2
$util || $self->util
$util
$self->util
Truth table50%1/2
A
A= $self->decorator($util || $self->util)->session
Truth table33%1/3
A || B
A= $utilB= $self->util
| |||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 16 | ▶ | sub handler { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handler: called CC=17 SCAR=29.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 16 | my ($self, $util) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 442 | 16 | ▶ | if(!ref $self) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 14 | $self = $self->new({util => $util}); | |||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 16 | my $headers = HTTP::Headers->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | 16 | my $cgi = $util->cgi(); | |||||||||||||||||||||||||||||||||||||||||||||
| 448 | 16 | my $decorator = $self->decorator($util, $headers); | |||||||||||||||||||||||||||||||||||||||||||||
| 449 | 16 | my $namespace = $self->namespace($util); | |||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 16 | $headers->header('Status', HTTP_OK); | |||||||||||||||||||||||||||||||||||||||||||||
| 452 | 16 | $headers->header('X-Generator', 'ClearPress'); | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||
| 454 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # no obvious right place for this | ||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 16 | my $lang = $decorator->lang; | |||||||||||||||||||||||||||||||||||||||||||||
| 458 | 16 | ▶ | if($lang && scalar @{$lang}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$lang and scalar @{$lang;}
MC/DC0%0/1
$lang and scalar @{$lang;}
$lang
Truth table50%1/2
A
A= $lang
| |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 16 | $headers->header('Content-Language', join q[,], @{$lang}); | |||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 16 | my ($action, $entity, $aspect, $id, $process_request_error); | |||||||||||||||||||||||||||||||||||||||||||||
| 463 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 16 | ($action, $entity, $aspect, $id) = $self->process_request($headers); | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | 16 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | carp qq[CAUGHT $EVAL_ERROR]; | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | $process_request_error = $EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 16 | my $params = { | |||||||||||||||||||||||||||||||||||||||||||||
| 472 | util => $util, | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | entity => $entity, | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | aspect => $aspect, | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | action => $action, | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | headers => $headers, | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 479 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | # initial header block | ||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 16 | ▶ | $headers->header('Content-Type', ClearPress::view->new($params)->content_type || 'text/html'); # don't forget to add charset | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'ClearPress::view'->new($params)->content_type || 'text/html'
MC/DC0%0/1
'ClearPress::view'->new($params)->content_type || 'text/html'
'ClearPress::view'->new($params)->content_type
Truth table50%1/2
A
A= 'ClearPress::view'->new($params)->content_type
| |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 16 | for my $cookie ($decorator->cookie) { | |||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $self->{headers}->push_header('Set-Cookie', $_); | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 16 | ▶ | if($process_request_error) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # deferred error handling | ||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | return $self->handle_error($process_request_error, $headers); | |||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 16 | $util->username($decorator->username()); | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | 16 | $util->session($self->session($util)); | |||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 16 | my $viewobject; | |||||||||||||||||||||||||||||||||||||||||||||
| 499 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 16 | $viewobject = $self->dispatch($params); | |||||||||||||||||||||||||||||||||||||||||||||
| 501 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | 16 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | return $self->handle_error($EVAL_ERROR, $headers); | |||||||||||||||||||||||||||||||||||||||||||||
| 504 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 16 | my $decor = $viewobject->decor(); # boolean | |||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # let the view have the decorator in case it wants to modify headers | ||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 16 | $viewobject->decorator($decorator); | |||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 16 | my $charset = $viewobject->charset(); | |||||||||||||||||||||||||||||||||||||||||||||
| 514 | 16 | ▶ | $charset = ($charset && !exists $ENV{REDIRECT_STATUS}) ? qq[;charset=$charset] : q[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$charset and not exists $ENV{"REDIRECT_STATUS"}
MC/DC0%0/2
$charset and not exists $ENV{"REDIRECT_STATUS"}
$charset
not exists $ENV{"REDIRECT_STATUS"}
Truth table33%1/3
A and not(B)
A= $charsetB= not exists $ENV{"REDIRECT_STATUS"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 16 | my $content_type = sprintf q[%s%s], $viewobject->content_type(), $charset; | |||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||
| 517 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # update the content-type/charset with whatever the view determined was right for the response | ||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 16 | $headers->header('Content-Type', $content_type); | |||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 16 | ▶ | if($decor) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # if($content_type =~ /text/smx && $charset =~ /utf-?8/smix) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # binmode STDOUT, q[:encoding(UTF-8)]; # is this useful? If so, should it be less conditional? | ||||||||||||||||||||||||||||||||||||||||||||||
| 525 | # } | ||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||
| 527 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # decorated header | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 7 | $viewobject->output_buffer($decorator->header()); | |||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 16 | my $errstr; | |||||||||||||||||||||||||||||||||||||||||||||
| 534 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # view->render() may be streamed | ||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 16 | ▶ | if($viewobject->streamed) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # ->render is responsible for all (decorated/undecorated) output | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 1 | $viewobject->render(); | |||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # output returned content | ||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 15 | $viewobject->output_buffer($viewobject->render()); | |||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 552 | 16 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 553 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # 1. reset pending output_buffer (different view object) | ||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # 2. set up error response w/headers | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # 3. emit headers | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | # 4. hand off to error response handler | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 2 | $EVAL_ERROR =~ s{[\r\n]+}{ }smxg; | |||||||||||||||||||||||||||||||||||||||||||||
| 560 | #carp qq[controller::handler: view->render failed: $EVAL_ERROR]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 2 | $viewobject->output_reset(); # reset headers on the original view | |||||||||||||||||||||||||||||||||||||||||||||
| 562 | 2 | $self->errstr($EVAL_ERROR); | |||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 2 | my $code = $headers->header('Status'); | |||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 2 | ▶ | if(!$code || $code == HTTP_OK) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $code or $code == 200
MC/DC0%0/2
not $code or $code == 200
not $code
$code == 200
Truth table33%1/3
not(A) or B
A= not $codeB= $code == 200
| |||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 2 | $headers->header('Status', HTTP_INTERNAL_SERVER_ERROR); | |||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # my $content_type = $headers->header('Content-Type'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 2 | $content_type =~ s{;.*$}{}smx; | |||||||||||||||||||||||||||||||||||||||||||||
| 572 | 2 | $headers->header('Content-Type', $content_type); # ErrorDocuments seem to have a bit of trouble with content-encoding errors so strip the charset | |||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 2 | return $self->handle_error(undef, $headers); # hand off | |||||||||||||||||||||||||||||||||||||||||||||
| 575 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||
| 577 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 578 | # prepend all response headers (and header block termination) | ||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 14 | $viewobject->output_prepend($headers->as_string, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||
| 582 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | # re-test decor in case it's changed by render() | ||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 14 | ▶ | if($viewobject->decor()) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 5 | $viewobject->output_buffer($decorator->footer()); | |||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||
| 589 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 590 | # flush everything left to client socket (via stdout) | ||||||||||||||||||||||||||||||||||||||||||||||
| 591 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 14 | $viewobject->output_end(); | |||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||
| 594 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 595 | # save the session after the request has processed | ||||||||||||||||||||||||||||||||||||||||||||||
| 596 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 14 | $decorator->save_session(); | |||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||
| 599 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 600 | # clean up any shared state so it's not carried over (e.g. incomplete transactions) | ||||||||||||||||||||||||||||||||||||||||||||||
| 601 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 14 | $util->cleanup(); | |||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 14 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 2 | ▶ | sub handle_error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_error: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 2 | my ($self, $errstr, $headers) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 609 | 2 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||||||
| 610 | 2 | my $decorator = $self->decorator(); | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | 2 | my $namespace = $self->namespace(); | |||||||||||||||||||||||||||||||||||||||||||||
| 612 | 2 | my ($action, $entity, $aspect, $id) = $self->process_request($headers); | |||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||
| 614 | # if running in mod_perl, main request serves a bad status header and errordocument is handled by a subrequest | ||||||||||||||||||||||||||||||||||||||||||||||
| 615 | # if running in CGI, main request serves a bad status header and follows with errordocument content | ||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 618 | # force reconstruction of CGI object from subrequest QUERY_STRING | ||||||||||||||||||||||||||||||||||||||||||||||
| 619 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 2 | delete $util->{cgi}; | |||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||
| 622 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | # but pass-through the errstr | ||||||||||||||||||||||||||||||||||||||||||||||
| 624 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 2 | ▶ | $util->cgi->param('errstr', CGI::escape($errstr || $self->errstr)); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$errstr || $self->errstr
MC/DC50%1/2
$errstr || $self->errstr
$errstr
$self->errstr
Truth table66%2/3
A || B
A= $errstrB= $self->errstr
| |||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||
| 627 | ######### | ||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # non-mod-perl errordocument handled by application internals | ||||||||||||||||||||||||||||||||||||||||||||||
| 629 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 2 | my $error_ns = sprintf q[%s::view::error], $namespace; | |||||||||||||||||||||||||||||||||||||||||||||
| 631 | 2 | my $params = { | |||||||||||||||||||||||||||||||||||||||||||||
| 632 | util => $util, | ||||||||||||||||||||||||||||||||||||||||||||||
| 633 | action => $action, | ||||||||||||||||||||||||||||||||||||||||||||||
| 634 | aspect => $aspect, | ||||||||||||||||||||||||||||||||||||||||||||||
| 635 | headers => $headers, # same header block as original response? hmm. | ||||||||||||||||||||||||||||||||||||||||||||||
| 636 | decorator => $decorator, | ||||||||||||||||||||||||||||||||||||||||||||||
| 637 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 2 | my $viewobject; | |||||||||||||||||||||||||||||||||||||||||||||
| 640 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 2 | $viewobject = $error_ns->new($params); | |||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 643 | 2 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 2 | $viewobject = ClearPress::view::error->new($params); | |||||||||||||||||||||||||||||||||||||||||||||
| 645 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 2 | my $decor = $viewobject->decor(); | |||||||||||||||||||||||||||||||||||||||||||||
| 648 | 2 | my $header = q[]; | |||||||||||||||||||||||||||||||||||||||||||||
| 649 | 2 | my $footer = q[]; | |||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 2 | $viewobject->output_reset(); | |||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 2 | my $body = $viewobject->render; | |||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 2 | ▶ | if($viewobject->decor) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 2 | $header = $decorator->header; | |||||||||||||||||||||||||||||||||||||||||||||
| 657 | 2 | $footer = $decorator->footer; | |||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 2 | my $str = $header . $body . $footer; | |||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 2 | $viewobject->output_prepend($headers->as_string, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 663 | 2 | $viewobject->output_buffer($str); | |||||||||||||||||||||||||||||||||||||||||||||
| 664 | 2 | $viewobject->output_end(); | |||||||||||||||||||||||||||||||||||||||||||||
| 665 | 2 | $decorator->save_session(); | |||||||||||||||||||||||||||||||||||||||||||||
| 666 | 2 | $util->cleanup(); | |||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 199 | ▶ | sub namespace { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
namespace: called CC=8 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 199 | my ($self, $util) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 673 | 199 | my $ns = q[]; | |||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 199 | ▶ | if((ref $self && !$self->{namespace}) || !ref $self) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $self and not $self->{"namespace"} or not ref $self
ref $self and not $self->{"namespace"}
MC/DC33%1/3
ref $self and not $self->{"namespace"} or not ref $self
ref $self
not $self->{"namespace"}
not ref $self
Truth table40%2/5
A and not(B) or not(C)
A= ref $selfB= not $self->{"namespace"}C= not ref $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 131 | ▶ | $util ||= $self->util(); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$util ||= $self->util
MC/DC0%0/2
$util ||= $self->util
$util
$self->util
Truth table66%2/3
A ||= B
A= $utilB= $self->util
| |||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 131 | ▶ | $ns = $util->config->val('application', 'namespace') || | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$util->config->val('application', 'namespace') || $util->config->val('application', 'name') || 'ClearPress'
$util->config->val("application", "namespace") or $util->config->val("application", "name")
MC/DC0%0/2
$util->config->val('application', 'namespace') || $util->config->val('application', 'name') || 'ClearPress'
$util->config->val("application", "namespace")
$util->config->val("application", "name")
Truth table33%1/3
A or B
A= $util->config->val("application", "namespace")B= $util->config->val("application", "name")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 678 | $util->config->val('application', 'name') || | ||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 'ClearPress'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 131 | ▶ | if(ref $self) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 131 | $self->{namespace} = $ns; | |||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 68 | $ns = $self->{namespace}; | |||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 199 | return $ns; | |||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 16 | ▶ | sub is_valid_view { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_valid_view: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 16 | my ($self, $ref, $viewname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 692 | 16 | my $util = $ref->{util}; | |||||||||||||||||||||||||||||||||||||||||||||
| 693 | 16 | my @entities = split /[,\s]+/smx, $util->config->val('application','views'); | |||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 16 | for my $ent (@entities) { | |||||||||||||||||||||||||||||||||||||||||||||
| 696 | 61 | ▶ | if($ent eq $viewname) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 16 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 4 | ▶ | sub errstr { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errstr: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 4 | my ($self, $str) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 4 | ▶ | if($str) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 1 | $self->{errstr} = $str; | |||||||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 4 | return $self->{errstr}; | |||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 16 | ▶ | sub dispatch { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dispatch: called CC=10 SCAR=30.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 16 | my ($self, $ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 716 | 16 | my $util = $ref->{util}; | |||||||||||||||||||||||||||||||||||||||||||||
| 717 | 16 | my $entity = $ref->{entity}; | |||||||||||||||||||||||||||||||||||||||||||||
| 718 | 16 | my $aspect = $ref->{aspect}; | |||||||||||||||||||||||||||||||||||||||||||||
| 719 | 16 | my $action = $ref->{action}; | |||||||||||||||||||||||||||||||||||||||||||||
| 720 | 16 | my $id = $ref->{id}; | |||||||||||||||||||||||||||||||||||||||||||||
| 721 | 16 | my $headers = $ref->{headers}; | |||||||||||||||||||||||||||||||||||||||||||||
| 722 | 16 | my $viewobject; | |||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 16 | my $state = $self->is_valid_view($ref, $entity); | |||||||||||||||||||||||||||||||||||||||||||||
| 725 | 16 | ▶ | if(!$state) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | $headers->header('Status', HTTP_NOT_FOUND); | |||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | croak qq[No such view ($entity). Is it in your config.ini?]; | |||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 16 | my $entity_name = $entity; | |||||||||||||||||||||||||||||||||||||||||||||
| 731 | 16 | my $viewclass = $self->packagespace('view', $entity, $util); | |||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 16 | my $modelobject; | |||||||||||||||||||||||||||||||||||||||||||||
| 734 | 16 | ▶ | if($entity ne 'error') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 16 | my $modelclass = $self->packagespace('model', $entity, $util); | |||||||||||||||||||||||||||||||||||||||||||||
| 736 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 16 | my $modelpk = $modelclass->primary_key(); | |||||||||||||||||||||||||||||||||||||||||||||
| 738 | 16 | ▶ | $modelobject = $modelclass->new({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 739 | util => $util, | ||||||||||||||||||||||||||||||||||||||||||||||
| 740 | $modelpk?($modelpk => $id):(), | ||||||||||||||||||||||||||||||||||||||||||||||
| 741 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 743 | 16 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # bail out | ||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | my $code = $headers->header('Status'); | |||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | if(!$code || $code == HTTP_OK) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $code or $code == 200
MC/DC0%0/2
not $code or $code == 200
not $code
$code == 200
Truth table0%0/3
not(A) or B
A= not $codeB= $code == 200
| |||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | $headers->header('Status', HTTP_INTERNAL_SERVER_ERROR); | |||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | croak qq[Failed to instantiate $entity model: $EVAL_ERROR]; | |||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | croak $EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||
| 754 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||||||
| 757 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 16 | $viewobject = $viewclass->new({ | |||||||||||||||||||||||||||||||||||||||||||||
| 759 | util => $util, | ||||||||||||||||||||||||||||||||||||||||||||||
| 760 | model => $modelobject, | ||||||||||||||||||||||||||||||||||||||||||||||
| 761 | action => $action, | ||||||||||||||||||||||||||||||||||||||||||||||
| 762 | aspect => $aspect, | ||||||||||||||||||||||||||||||||||||||||||||||
| 763 | entity_name => $entity_name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 764 | decorator => $self->decorator, | ||||||||||||||||||||||||||||||||||||||||||||||
| 765 | headers => $headers, | ||||||||||||||||||||||||||||||||||||||||||||||
| 766 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 768 | 16 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | my $code = $headers->header('Status'); | |||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | if(!$code || $code == HTTP_OK) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $code or $code == 200
MC/DC0%0/2
not $code or $code == 200
not $code
$code == 200
Truth table0%0/3
not(A) or B
A= not $codeB= $code == 200
| |||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | $headers->header('Status', HTTP_INTERNAL_SERVER_ERROR); | |||||||||||||||||||||||||||||||||||||||||||||
| 773 | 0 | croak qq[Failed to instantiate $entity view: $EVAL_ERROR]; | |||||||||||||||||||||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | croak $EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||
| 777 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 16 | return $viewobject; | |||||||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 783 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||