| 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 | package ClearPress::view; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use base qw(Class::Accessor); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Template; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Template::Filters; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | ▶ | use HTML::Entities qw(encode_entities_numeric); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | use HTTP::Headers; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use HTTP::Status qw(:constants); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use XML::Simple qw(XMLin); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use ClearPress::Localize; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | ▶ | use MIME::Base64 qw(encode_base64); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | our $VERSION = q[2026.07.25]; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | our $DEBUG_OUTPUT = 0; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | our $DEBUG_L10N = 0; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | our $TEMPLATE_CACHE = {}; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | our $LEXICON_CACHE = {}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | our $TRAP_REDIR_OVERFLOW = 0; # set to non-zero value to cut-off at that many bytes | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | Readonly::Scalar our $DEFAULT_PROTO_PORTS => { | |||||||||||||||||||||||||||||||||||||||||
| 35 | http => 80, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | https => 443, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | __PACKAGE__->mk_accessors(qw(util model action aspect content_type entity_name autoescape charset decorator headers)); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 83 | ▶ | sub new { ## no critic (Complexity) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=26 SCAR=33.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 83 | my ($class, $self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 83 | ▶ | $self ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self ||= {}
MC/DC100%1/1
$self ||= {}
$self
Truth table100%2/2
A
A= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 83 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 83 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 83 | ▶ | my $username = $util ? $util->username : q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 83 | $self->{requestor_username} = $username; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 83 | ▶ | $self->{logged_in} = $username?1:0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 83 | $self->{warnings} = []; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 83 | $self->{output_buffer} = []; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 83 | $self->{output_finished} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 83 | $self->{autoescape} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 83 | ▶ | my $aspect = $self->aspect || q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->aspect || ''
MC/DC100%1/1
$self->aspect || ''
$self->aspect
Truth table100%2/2
A
A= $self->aspect
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 83 | ▶ | $self->{content_type} ||= ($aspect =~ /(?:rss|atom|ajax|xml)$/smx)?'text/xml':q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"content_type"} ||= $aspect =~ /(?:rss|atom|ajax|xml)$/msx ? "text/xml" : ""
MC/DC50%1/2
$self->{"content_type"} ||= $aspect =~ /(?:rss|atom|ajax|xml)$/msx ? "text/xml" : ""
$self->{"content_type"}
$aspect =~ /(?:rss|atom|ajax|xml)$/msx ? "text/xml" : ""
Truth table66%2/3
A ||= B
A= $self->{"content_type"}B= $aspect =~ /(?:rss|atom|ajax|xml)$/msx ? "text/xml" : ""
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 83 | ▶ | $self->{content_type} ||= ($aspect =~ /(?:js|json)$/smx)?'application/json':q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"content_type"} ||= $aspect =~ /(?:js|json)$/msx ? "application/json" : ""
MC/DC100%2/2
$self->{"content_type"} ||= $aspect =~ /(?:js|json)$/msx ? "application/json" : ""
$self->{"content_type"}
$aspect =~ /(?:js|json)$/msx ? "application/json" : ""
Truth table100%3/3
A ||= B
A= $self->{"content_type"}B= $aspect =~ /(?:js|json)$/msx ? "application/json" : ""
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 83 | ▶ | $self->{content_type} ||= ($aspect =~ /_svg$/smx)?'image/svg+xml':q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"content_type"} ||= $aspect =~ /_svg$/msx ? "image/svg+xml" : ""
MC/DC50%1/2
$self->{"content_type"} ||= $aspect =~ /_svg$/msx ? "image/svg+xml" : ""
$self->{"content_type"}
$aspect =~ /_svg$/msx ? "image/svg+xml" : ""
Truth table66%2/3
A ||= B
A= $self->{"content_type"}B= $aspect =~ /_svg$/msx ? "image/svg+xml" : ""
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 83 | ▶ | $self->{content_type} ||= ($aspect =~ /_svgz$/smx)?'image/svg+xml':q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"content_type"} ||= $aspect =~ /_svgz$/msx ? "image/svg+xml" : ""
MC/DC50%1/2
$self->{"content_type"} ||= $aspect =~ /_svgz$/msx ? "image/svg+xml" : ""
$self->{"content_type"}
$aspect =~ /_svgz$/msx ? "image/svg+xml" : ""
Truth table66%2/3
A ||= B
A= $self->{"content_type"}B= $aspect =~ /_svgz$/msx ? "image/svg+xml" : ""
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 83 | ▶ | $self->{content_type} ||= ($aspect =~ /_png$/smx)?'image/png':q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"content_type"} ||= $aspect =~ /_png$/msx ? "image/png" : ""
MC/DC100%2/2
$self->{"content_type"} ||= $aspect =~ /_png$/msx ? "image/png" : ""
$self->{"content_type"}
$aspect =~ /_png$/msx ? "image/png" : ""
Truth table100%3/3
A ||= B
A= $self->{"content_type"}B= $aspect =~ /_png$/msx ? "image/png" : ""
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 83 | ▶ | $self->{content_type} ||= ($aspect =~ /_jpg$/smx)?'image/jpeg':q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"content_type"} ||= $aspect =~ /_jpg$/msx ? "image/jpeg" : ""
MC/DC100%2/2
$self->{"content_type"} ||= $aspect =~ /_jpg$/msx ? "image/jpeg" : ""
$self->{"content_type"}
$aspect =~ /_jpg$/msx ? "image/jpeg" : ""
Truth table100%3/3
A ||= B
A= $self->{"content_type"}B= $aspect =~ /_jpg$/msx ? "image/jpeg" : ""
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 83 | ▶ | $self->{content_type} ||= ($aspect =~ /_txt$/smx)?'text/plain':q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"content_type"} ||= $aspect =~ /_txt$/msx ? "text/plain" : ""
MC/DC50%1/2
$self->{"content_type"} ||= $aspect =~ /_txt$/msx ? "text/plain" : ""
$self->{"content_type"}
$aspect =~ /_txt$/msx ? "text/plain" : ""
Truth table66%2/3
A ||= B
A= $self->{"content_type"}B= $aspect =~ /_txt$/msx ? "text/plain" : ""
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 83 | ▶ | $self->{content_type} ||= ($aspect =~ /_csv$/smx)?'text/csv':q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"content_type"} ||= $aspect =~ /_csv$/msx ? "text/csv" : ""
MC/DC50%1/2
$self->{"content_type"} ||= $aspect =~ /_csv$/msx ? "text/csv" : ""
$self->{"content_type"}
$aspect =~ /_csv$/msx ? "text/csv" : ""
Truth table66%2/3
A ||= B
A= $self->{"content_type"}B= $aspect =~ /_csv$/msx ? "text/csv" : ""
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 83 | ▶ | $self->{content_type} ||= ($aspect =~ /_xls$/smx)?'application/vnd.ms-excel':q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"content_type"} ||= $aspect =~ /_xls$/msx ? "application/vnd.ms-excel" : ""
MC/DC50%1/2
$self->{"content_type"} ||= $aspect =~ /_xls$/msx ? "application/vnd.ms-excel" : ""
$self->{"content_type"}
$aspect =~ /_xls$/msx ? "application/vnd.ms-excel" : ""
Truth table66%2/3
A ||= B
A= $self->{"content_type"}B= $aspect =~ /_xls$/msx ? "application/vnd.ms-excel" : ""
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 83 | $self->setup_filters; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 83 | $self->init; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 83 | ClearPress::Localize->init($self->locales); | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 83 | ▶ | $self->{content_type} ||= 'text/html'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"content_type"} ||= "text/html"
MC/DC100%1/1
$self->{"content_type"} ||= "text/html"
$self->{"content_type"}
Truth table100%2/2
A
A= $self->{"content_type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 83 | ▶ | $self->{charset} ||= 'UTF-8'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"charset"} ||= "UTF-8"
MC/DC100%1/1
$self->{"charset"} ||= "UTF-8"
$self->{"charset"}
Truth table100%2/2
A
A= $self->{"charset"}
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 83 | ▶ | $self->{headers} ||= HTTP::Headers->new; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"headers"} ||= "HTTP::Headers"->new
MC/DC0%0/2
$self->{"headers"} ||= "HTTP::Headers"->new
$self->{"headers"}
"HTTP::Headers"->new
Truth table66%2/3
A ||= B
A= $self->{"headers"}B= "HTTP::Headers"->new
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 83 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 83 | ▶ | sub setup_filters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_filters: called CC=1 SCAR=3.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 83 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $self->add_tt_filter('js_string', sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if(!defined $string) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $string = q[]; | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $string =~ s/\r/\\r/smxg; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $string =~ s/\n/\\n/smxg; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $string =~ s/"/\\"/smxg; | |||||||||||||||||||||||||||||||||||||||||
| 91 | # $string =~ s/'/\\'/smxg; | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 83 | }); | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | ▶ | $self->add_tt_filter('xml_entity', sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | ▶ | if(!defined $string) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | $string = q[]; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 5 | return encode_entities_numeric($string), | |||||||||||||||||||||||||||||||||||||||||
| 101 | 83 | }); | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $self->add_tt_filter('base64', sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if(!defined $string) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $string = q[]; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return encode_base64($string), | |||||||||||||||||||||||||||||||||||||||||
| 109 | 83 | }); | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 83 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $self->add_tt_filter('loc', [sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my ($string) = shift; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # Cache lexicons for | ||||||||||||||||||||||||||||||||||||||||||
| 120 | # speed. However, loading on-demand | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # won't generally use shared memory | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $lang = ClearPress::Localize->lang; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if($lang && !$LEXICON_CACHE->{$lang}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$lang and not $ClearPress::view::LEXICON_CACHE->{$lang}
MC/DC0%0/2
$lang and not $ClearPress::view::LEXICON_CACHE->{$lang}
$lang
not $ClearPress::view::LEXICON_CACHE->{$lang}
Truth table0%0/3
A and not(B)
A= $langB= not $ClearPress::view::LEXICON_CACHE->{$lang}
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $LEXICON_CACHE->{$lang} = ClearPress::Localize->localizer; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $loc = $string; | |||||||||||||||||||||||||||||||||||||||||
| 129 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $loc = $util->{localizers}->{$lang}->maketext($string); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $DEBUG_L10N && carp qq[Could not localize $string to $lang]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 135 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return $loc || $string; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$loc || $string
MC/DC0%0/2
$loc || $string
$loc
$string
Truth table0%0/3
A || B
A= $locB= $string
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 83 | }, 1]); | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 83 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 83 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 83 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 83 | ▶ | sub locales { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
locales: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 83 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 83 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||
| 151 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 83 | ▶ | $util ? (q[*] => [Gettext => sprintf q[%s/po/*.po], $util->data_path] ) : (), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | q[en] => ['Auto'], | ||||||||||||||||||||||||||||||||||||||||||
| 154 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | ▶ | sub add_warning { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_warning: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | my ($self, $warning) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | push @{$self->{warnings}}, $warning; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 12 | ▶ | sub warnings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warnings: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 12 | return $self->{warnings}; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | ▶ | sub _accessor { ## no critic (ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_accessor: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | my ($self, $field, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 2 | carp q[_accessor is deprecated. Use __PACKAGE__->mk_accessors(...) instead]; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | if(defined $val) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | $self->{$field} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | return $self->{$field}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 26 | ▶ | sub authorised { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authorised: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 26 | ▶ | my $action = $self->action || q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->action || ''
MC/DC0%0/1
$self->action || ''
$self->action
Truth table50%1/2
A
A= $self->action
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 26 | ▶ | my $aspect = $self->aspect || q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->aspect || ''
MC/DC100%1/1
$self->aspect || ''
$self->aspect
Truth table100%2/2
A
A= $self->aspect
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 26 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 26 | my $requestor = $util->requestor; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 26 | ▶ | if(!$requestor) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 186 | # If there's no requestor user object then authorisation isn't supported | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 17 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 9 | ▶ | if($action =~ /^list/smx || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$action =~ /^list/msx or $action eq "read" and not $aspect =~ /^(?:add|edit|delete|update|create)/msx
$action eq "read" and not $aspect =~ /^(?:add|edit|delete|update|create)/msx
MC/DC100%3/3
$action =~ /^list/msx or $action eq "read" and not $aspect =~ /^(?:add|edit|delete|update|create)/msx
$action =~ /^list/msx
$action eq "read"
not $aspect =~ /^(?:add|edit|delete|update|create)/msx
Truth table100%4/4
A or B and not(C)
A= $action =~ /^list/msxB= $action eq "read"C= not $aspect =~ /^(?:add|edit|delete|update|create)/msx
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | ($action eq 'read' && | ||||||||||||||||||||||||||||||||||||||||||
| 193 | $aspect !~ /^(?:add|edit|delete|update|create)/smx)) { | ||||||||||||||||||||||||||||||||||||||||||
| 194 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # by default assume public read access for 'read' actions | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # by default allow only 'admin' group for non-read aspects (add, edit, create, update, delete) | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | ▶ | if($requestor->can('is_member_of') && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$requestor->can("is_member_of") and $requestor->is_member_of("admin")
MC/DC50%1/2
$requestor->can("is_member_of") and $requestor->is_member_of("admin")
$requestor->can("is_member_of")
$requestor->is_member_of("admin")
Truth table66%2/3
A and B
A= $requestor->can("is_member_of")B= $requestor->is_member_of("admin")
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | $requestor->is_member_of('admin')) { | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 23 | ▶ | sub template_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
template_name: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 23 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 23 | ▶ | if(scalar @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | $self->{template_override} = $args[0]; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 23 | ▶ | if(exists $self->{template_override}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | return $self->{template_override}; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 21 | my $name = $self->entity_name; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 21 | ▶ | if(!$name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 6 | ($name) = (ref $self) =~ /view::(.*)$/smx; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 21 | ▶ | $name ||= 'view'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$name ||= "view"
MC/DC100%1/1
$name ||= "view"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 21 | my $method = $self->method_name; | |||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 21 | $name =~ s/:+/_/smxg; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 21 | ▶ | if(!$method) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | return $name; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 20 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 20 | my $tmp = "${name}/$method"; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 20 | my $path = sprintf q[%s/templates], $util->data_path; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # I do not like this stat. I'd prefer a global mode switch in config. | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 20 | ▶ | if(-e "$path/$tmp.tt2") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | return $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 19 | return "${name}_$method"; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 39 | ▶ | sub method_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
method_name: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 39 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 39 | my $aspect = $self->aspect; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 39 | my $action = $self->action; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 39 | ▶ | my $method = $aspect || $action; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$aspect || $action
MC/DC100%2/2
$aspect || $action
$aspect
$action
Truth table100%3/3
A || B
A= $aspectB= $action
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 39 | my $model = $self->model; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 39 | my $pk = $model->primary_key; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 39 | ▶ | if(!$method) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | return q[]; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 38 | ▶ | if($pk && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$pk and $method eq "read" and not $model->$pk
$pk and $method eq "read"
MC/DC66%2/3
$pk and $method eq "read" and not $model->$pk
$pk
$method eq "read"
not $model->$pk
Truth table75%3/4
A and B and not(C)
A= $pkB= $method eq "read"C= not $model->$pk
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | $method eq 'read' && | ||||||||||||||||||||||||||||||||||||||||||
| 263 | !$model->$pk()) { | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | $method = 'list'; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 38 | $method =~ s/__/_/smxg; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 38 | return $method; | |||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 32 | ▶ | sub streamed_aspects { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
streamed_aspects: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 32 | return []; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 34 | ▶ | sub streamed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
streamed: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 34 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 34 | my $aspect = $self->aspect; | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 34 | for my $str_aspect (@{$self->streamed_aspects}) { | |||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | if($aspect eq $str_aspect) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 32 | return; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 18 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=15 SCAR=32.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 18 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 18 | ▶ | my $aspect = $self->aspect || q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->aspect || ''
MC/DC100%1/1
$self->aspect || ''
$self->aspect
Truth table100%2/2
A
A= $self->aspect
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 18 | my $action = $self->action; | |||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 18 | ▶ | if(!$util) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | croak q[No util object available]; | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 18 | my $requestor = $util->requestor; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 18 | ▶ | if(!$self->authorised) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # set http forbidden response code | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $self->headers->header('Status', HTTP_FORBIDDEN); | |||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if(!$requestor) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | croak q[Authorisation unavailable for this view.]; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $username = $requestor->username; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if(!$username) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | croak q[You are not authorised for this view. You need to log in.]; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | croak qq[You ($username) are not authorised for this view]; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 318 | # Figure out and call the appropriate action if available | ||||||||||||||||||||||||||||||||||||||||||
| 319 | # | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 18 | my $method = $self->method_name; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 18 | ▶ | if($method !~ /^(?:add|edit|create|read|update|delete|list|options|head)/smx) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | croak qq[Illegal method: $method]; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 18 | ▶ | if($self->can($method)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 18 | ▶ | if($action eq 'options' || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$action eq "options" or $aspect =~ /_(?:jpg|png|gif|svg|svgz)/msx
MC/DC0%0/2
$action eq "options" or $aspect =~ /_(?:jpg|png|gif|svg|svgz)/msx
$action eq "options"
$aspect =~ /_(?:jpg|png|gif|svg|svgz)/msx
Truth table33%1/3
A or B
A= $action eq "options"B= $aspect =~ /_(?:jpg|png|gif|svg|svgz)/msx
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | $aspect =~ /_(?:jpg|png|gif|svg|svgz)/smx) { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | return $self->$method(); | |||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 332 | # handle streamed methods | ||||||||||||||||||||||||||||||||||||||||||
| 333 | # | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 18 | my $streamed = $self->streamed; | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 18 | ▶ | if($streamed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | $self->output_flush; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 18 | $self->$method(); | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 18 | ▶ | if($streamed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | $self->output_end; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | return q[]; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | croak qq[Unsupported method: $method]; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 17 | my $model = $self->model; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 17 | my $actions = my $warnings = q[]; | |||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 17 | ▶ | if($self->decor) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 9 | $actions = $self->actions; | |||||||||||||||||||||||||||||||||||||||||
| 356 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 9 | $self->process_template('warnings.tt2', { | |||||||||||||||||||||||||||||||||||||||||
| 358 | warnings => $self->warnings, | ||||||||||||||||||||||||||||||||||||||||||
| 359 | }, \$warnings); | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 9 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 363 | # non-fatal warning - usually warnings.tt2 missing | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | carp "Warning: $EVAL_ERROR"; | |||||||||||||||||||||||||||||||||||||||||
| 366 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # handle block (non-streamed) methods | ||||||||||||||||||||||||||||||||||||||||||
| 371 | # | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 17 | my $tmpl = $self->template_name; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 17 | my $cfg = $util->config; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 17 | my $content = q[]; | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 17 | $self->process_template("$tmpl.tt2", {}, \$content); | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 15 | ▶ | return $warnings . $actions . $content || q[No data]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$warnings . $actions . $content || 'No data'
MC/DC0%0/1
$warnings . $actions . $content || 'No data'
$warnings . $actions . $content
Truth table50%1/2
A
A= $warnings . $actions . $content
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 39 | ▶ | sub process_template { ## no critic (Complexity) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_template: called CC=25 SCAR=37.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 39 | my ($self, $template, $extra_params, $where_to_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 39 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 39 | my $cfg = $util->config; | |||||||||||||||||||||||||||||||||||||||||
| 385 | 39 | my ($entity) = (ref $self) =~ /([^:]+)$/smx; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 39 | ▶ | $entity ||= q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entity ||= ""
MC/DC0%0/1
$entity ||= ""
$entity
Truth table50%1/2
A
A= $entity
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 39 | ▶ | my $script_name = $ENV{SCRIPT_NAME} || q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'SCRIPT_NAME'} || ''
MC/DC0%0/1
$ENV{'SCRIPT_NAME'} || ''
$ENV{'SCRIPT_NAME'}
Truth table50%1/2
A
A= $ENV{'SCRIPT_NAME'}
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 39 | my ($xfh, $xfp) = ($ENV{HTTP_X_FORWARDED_HOST}, $ENV{HTTP_X_FORWARDED_PORT}); | |||||||||||||||||||||||||||||||||||||||||
| 389 | 39 | ▶ | my $http_host = ($xfh ? $xfh : $ENV{HTTP_HOST}) || q[localhost]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
($xfh ? $xfh : $ENV{'HTTP_HOST'}) || 'localhost'
MC/DC100%1/1
($xfh ? $xfh : $ENV{'HTTP_HOST'}) || 'localhost'
($xfh ? $xfh : $ENV{'HTTP_HOST'})
Truth table100%2/2
A
A= ($xfh ? $xfh : $ENV{'HTTP_HOST'})
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 39 | ▶ | my $http_port = ($xfh ? $xfp : $ENV{HTTP_PORT}) || q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
($xfh ? $xfp : $ENV{'HTTP_PORT'}) || ''
MC/DC0%0/1
($xfh ? $xfp : $ENV{'HTTP_PORT'}) || ''
($xfh ? $xfp : $ENV{'HTTP_PORT'})
Truth table50%1/2
A
A= ($xfh ? $xfp : $ENV{'HTTP_PORT'})
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 39 | ▶ | my $http_proto = $ENV{HTTP_X_FORWARDED_PROTO} || $ENV{HTTPS}?q[https]:q[http]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ENV{"HTTP_X_FORWARDED_PROTO"} or $ENV{"HTTPS"}
MC/DC0%0/2
$ENV{"HTTP_X_FORWARDED_PROTO"} or $ENV{"HTTPS"}
$ENV{"HTTP_X_FORWARDED_PROTO"}
$ENV{"HTTPS"}
Truth table33%1/3
A or B
A= $ENV{"HTTP_X_FORWARDED_PROTO"}B= $ENV{"HTTPS"}
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 394 | # if default port for protocol, skip addition of the port | ||||||||||||||||||||||||||||||||||||||||||
| 395 | # | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 39 | for my $default_proto (keys %{$DEFAULT_PROTO_PORTS}) { | |||||||||||||||||||||||||||||||||||||||||
| 397 | 78 | ▶ | if(($default_proto eq lc $http_proto) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$default_proto eq lc $http_proto and $http_port eq $ClearPress::view::DEFAULT_PROTO_PORTS->{$default_proto}
MC/DC0%0/2
$default_proto eq lc $http_proto and $http_port eq $ClearPress::view::DEFAULT_PROTO_PORTS->{$default_proto}
$default_proto eq lc $http_proto
$http_port eq $ClearPress::view::DEFAULT_PROTO_PORTS->{$default_proto}
Truth table66%2/3
A and B
A= $default_proto eq lc $http_protoB= $http_port eq $ClearPress::view::DEFAULT_PROTO_PORTS->{$default_proto}
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | $http_port eq $DEFAULT_PROTO_PORTS->{$default_proto}) { | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $http_port = q[]; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 39 | ▶ | my $href = sprintf q[%s://%s%s%s%s], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | $http_proto, | ||||||||||||||||||||||||||||||||||||||||||
| 406 | $http_host, | ||||||||||||||||||||||||||||||||||||||||||
| 407 | $http_port?":$http_port":q[], | ||||||||||||||||||||||||||||||||||||||||||
| 408 | $script_name, | ||||||||||||||||||||||||||||||||||||||||||
| 409 | ($script_name eq q[/])?q[]:q[/]; | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | my $cfg_globals = { | ||||||||||||||||||||||||||||||||||||||||||
| 412 | (map { | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | $_ => $cfg->val('globals',$_) | |||||||||||||||||||||||||||||||||||||||||
| 414 | } $cfg->Parameters('globals')) | ||||||||||||||||||||||||||||||||||||||||||
| 415 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | my $params = { | ||||||||||||||||||||||||||||||||||||||||||
| 418 | requestor => $util->requestor || undef, | ||||||||||||||||||||||||||||||||||||||||||
| 419 | model => $self->model, | ||||||||||||||||||||||||||||||||||||||||||
| 420 | view => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 421 | entity => $entity, | ||||||||||||||||||||||||||||||||||||||||||
| 422 | SCRIPT_NAME => $script_name, | ||||||||||||||||||||||||||||||||||||||||||
| 423 | HTTP_HOST => $http_host, | ||||||||||||||||||||||||||||||||||||||||||
| 424 | HTTP_PORT => $http_port, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | HTTPS => $http_proto, | ||||||||||||||||||||||||||||||||||||||||||
| 426 | SCRIPT_HREF => $href, | ||||||||||||||||||||||||||||||||||||||||||
| 427 | ENTITY_HREF => "$href$entity", | ||||||||||||||||||||||||||||||||||||||||||
| 428 | now => (strftime '%Y-%m-%dT%H:%M:%S', localtime), | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 39 | %{$cfg_globals}, | |||||||||||||||||||||||||||||||||||||||||
| 430 | 39 | ▶ | %{$extra_params||{}}, | ||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$util->requestor || undef
$extra_params || {}
MC/DC100%1/1
$util->requestor || undef
$util->requestor
MC/DC0%0/1
$extra_params || {}
$extra_params
Truth table100%2/2
A
A= $util->requestor
Truth table50%1/2
A
A= $extra_params
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | my $appname = $util->config->val('application', 'name') || | ||||||||||||||||||||||||||||||||||||||||||
| 435 | $util->config->val('application', 'namespace') || | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 39 | ▶ | $ENV{SCRIPT_NAME}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$util->config->val('application', 'name') || $util->config->val('application', 'namespace') || $ENV{'SCRIPT_NAME'}
$util->config->val("application", "name") or $util->config->val("application", "namespace")
MC/DC0%0/3
$util->config->val('application', 'name') || $util->config->val('application', 'namespace') || $ENV{'SCRIPT_NAME'}
$util->config->val("application", "name")
$util->config->val("application", "namespace")
$ENV{'SCRIPT_NAME'}
Truth table25%1/4
A or B || C
A= $util->config->val("application", "name")B= $util->config->val("application", "namespace")C= $ENV{'SCRIPT_NAME'}
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 39 | ▶ | $TEMPLATE_CACHE->{$appname} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ClearPress::view::TEMPLATE_CACHE->{$appname} ||= {}
MC/DC100%1/1
$ClearPress::view::TEMPLATE_CACHE->{$appname} ||= {}
$ClearPress::view::TEMPLATE_CACHE->{$appname}
Truth table100%2/2
A
A= $ClearPress::view::TEMPLATE_CACHE->{$appname}
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 39 | my $template_cache = $TEMPLATE_CACHE->{$appname}; | |||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 39 | ▶ | if(!$template_cache->{$template}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 25 | my $path = sprintf q[%s/templates], $util->data_path; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 25 | ▶ | open my $fh, q[<], "$path/$template" or croak qq[Error opening $template]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 23 | local $RS = undef; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 23 | $template_cache->{$template} = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 23 | ▶ | close $fh or croak qq[Error closing $template]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | 37 | $template = \$template_cache->{$template}; | |||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 37 | ▶ | if($where_to_ref) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 37 | ▶ | $self->tt->process($template, $params, $where_to_ref, {binmode => ':utf8'}) or croak $self->tt->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | $self->tt->process($template, $params, $where_to_ref, {binmode => ':utf8'}) or croak $self->tt->error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 37 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 14 | ▶ | sub _populate_from_cgi { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_populate_from_cgi: called CC=19 SCAR=31.2
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 14 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 14 | my $model = $self->model; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 14 | my $cgi = $util->cgi; | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 468 | # Populate model object with parameters posted into CGI | ||||||||||||||||||||||||||||||||||||||||||
| 469 | # by default (in controller.pm) model will only have util & its primary_key. | ||||||||||||||||||||||||||||||||||||||||||
| 470 | # | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 14 | $model->read; | |||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 14 | my $pk = $model->primary_key; | |||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 14 | my @fields = $model->fields; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 14 | ▶ | if($pk) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 478 | # don't leave primary key in field list | ||||||||||||||||||||||||||||||||||||||||||
| 479 | # | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 14 | @fields = grep { $_ ne $pk } @fields; | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | my $params = { | ||||||||||||||||||||||||||||||||||||||||||
| 484 | map { ## no critic (ProhibitComplexMappings) | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 14 | my $p = $cgi->param($_); | |||||||||||||||||||||||||||||||||||||||||
| 486 | 17 | utf8::decode($p); | |||||||||||||||||||||||||||||||||||||||||
| 487 | 17 | $_ => $p; | |||||||||||||||||||||||||||||||||||||||||
| 488 | } $cgi->param | ||||||||||||||||||||||||||||||||||||||||||
| 489 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 492 | # parse new-style POST payload | ||||||||||||||||||||||||||||||||||||||||||
| 493 | # todo: look at PUTDATA as well | ||||||||||||||||||||||||||||||||||||||||||
| 494 | # | ||||||||||||||||||||||||||||||||||||||||||
| 495 | 14 | my ($method) = $ENV{REQUEST_METHOD} =~ /(PUT|POST)/smix; | |||||||||||||||||||||||||||||||||||||||||
| 496 | 14 | ▶ | $method ||= q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$method ||= ""
MC/DC100%1/1
$method ||= ""
$method
Truth table100%2/2
A
A= $method
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 14 | ▶ | my $PDATA = sprintf q[%sDATA], (uc $method || 'POST'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
uc $method || 'POST'
MC/DC100%1/1
uc $method || 'POST'
uc $method
Truth table100%2/2
A
A= uc $method
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 14 | my $reqdata = $cgi->param($PDATA); | |||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 14 | ▶ | if($reqdata) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 6 | utf8::decode($reqdata); | |||||||||||||||||||||||||||||||||||||||||
| 502 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 6 | my $json = JSON->new->utf8; | |||||||||||||||||||||||||||||||||||||||||
| 504 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 6 | $params = $json->decode($reqdata); | |||||||||||||||||||||||||||||||||||||||||
| 506 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 6 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 1 | $params = XMLin($reqdata); | |||||||||||||||||||||||||||||||||||||||||
| 510 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 6 | for my $k (keys %{$params}) { | |||||||||||||||||||||||||||||||||||||||||
| 513 | 10 | ▶ | if(ref $params->{$k} && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $params->{$k} and ref $params->{$k} eq "HASH" and not scalar keys %{$$params{$k};}
ref $params->{$k} and ref $params->{$k} eq "HASH"
MC/DC0%0/3
ref $params->{$k} and ref $params->{$k} eq "HASH" and not scalar keys %{$$params{$k};}
ref $params->{$k}
ref $params->{$k} eq "HASH"
not scalar keys %{$$params{$k};}
Truth table25%1/4
A and B and not(C)
A= ref $params->{$k}B= ref $params->{$k} eq "HASH"C= not scalar keys %{$$params{$k};}
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | ref $params->{$k} eq 'HASH' && | ||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | !scalar keys %{$params->{$k}}) { | |||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | delete $params->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | 6 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 523 | # Not an XML-formatted POST body. Ignore for now. | ||||||||||||||||||||||||||||||||||||||||||
| 524 | # | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | carp qq[Got error while parsing $PDATA: ].$EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 526 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 530 | # parse old-style XML POST payload | ||||||||||||||||||||||||||||||||||||||||||
| 531 | # | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 14 | my $xml = $cgi->param('XForms:Model'); | |||||||||||||||||||||||||||||||||||||||||
| 533 | 14 | ▶ | if($xml) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 1 | utf8::decode($xml); | |||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | $params = XMLin($xml); | |||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | for my $k (%{$params}) { | |||||||||||||||||||||||||||||||||||||||||
| 537 | 4 | ▶ | if(ref $params->{$k} && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $params->{$k} and ref $params->{$k} eq "HASH" and not scalar keys %{$$params{$k};}
ref $params->{$k} and ref $params->{$k} eq "HASH"
MC/DC0%0/3
ref $params->{$k} and ref $params->{$k} eq "HASH" and not scalar keys %{$$params{$k};}
ref $params->{$k}
ref $params->{$k} eq "HASH"
not scalar keys %{$$params{$k};}
Truth table25%1/4
A and B and not(C)
A= ref $params->{$k}B= ref $params->{$k} eq "HASH"C= not scalar keys %{$$params{$k};}
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | ref $params->{$k} eq 'HASH' && | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | !scalar keys %{$params->{$k}}) { | |||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | delete $params->{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 14 | for my $field (@fields) { | |||||||||||||||||||||||||||||||||||||||||
| 546 | 41 | ▶ | if(!exists $params->{$field}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 28 | next; | |||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 549 | 13 | my $v = $params->{$field}; | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 552 | # $v here will always be defined | ||||||||||||||||||||||||||||||||||||||||||
| 553 | # but may be false, e.g. $v=q[] or $v=q[0] | ||||||||||||||||||||||||||||||||||||||||||
| 554 | # | ||||||||||||||||||||||||||||||||||||||||||
| 555 | 13 | ▶ | if($self->autoescape) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 13 | $v = $cgi->escapeHTML($v); | |||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 13 | $model->$field($v); | |||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | 14 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 1 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 567 | 1 | return $self->_populate_from_cgi; | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | sub edit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | return $self->_populate_from_cgi; | |||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | sub options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 577 | # streamed response | ||||||||||||||||||||||||||||||||||||||||||
| 578 | # | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | return q[]; | |||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | 5 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 583 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | 3 | ▶ | sub read { ## no critic (homonym) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 2 | ▶ | sub delete { ## no critic (homonym) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 592 | 2 | my $model = $self->model; | |||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | 2 | ▶ | $model->delete or croak qq[Failed to delete entity: $EVAL_ERROR]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | 7 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 601 | 7 | my $model = $self->model; | |||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 604 | # Populate model object with parameters posted into CGI | ||||||||||||||||||||||||||||||||||||||||||
| 605 | # by default (in controller.pm) model will only have util & its primary_key. | ||||||||||||||||||||||||||||||||||||||||||
| 606 | # | ||||||||||||||||||||||||||||||||||||||||||
| 607 | 7 | $self->_populate_from_cgi; | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 7 | ▶ | $model->update or croak qq[Failed to update entity: $EVAL_ERROR]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 7 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 6 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 615 | 6 | my $model = $self->model; | |||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 618 | # Populate model object with parameters posted into CGI | ||||||||||||||||||||||||||||||||||||||||||
| 619 | # by default (in controller.pm) model will only have util & its primary_key. | ||||||||||||||||||||||||||||||||||||||||||
| 620 | # | ||||||||||||||||||||||||||||||||||||||||||
| 621 | 6 | $self->_populate_from_cgi; | |||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | 6 | ▶ | $model->create or croak qq[Failed to create entity: $EVAL_ERROR]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 332 | ▶ | sub add_tt_filter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_tt_filter: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | 332 | my ($self, $name, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 332 | ▶ | if(!$name || !$code) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$name and $code
MC/DC0%0/2
$name and $code
$name
$code
Truth table33%1/3
A and B
A= $nameB= $code
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 332 | $self->tt_filters->{$name} = $code; | |||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | 332 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | 346 | ▶ | sub tt_filters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt_filters: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | 346 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | 346 | ▶ | if(!$self->{tt_filters}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 644 | 83 | $self->{tt_filters} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | 346 | return $self->{tt_filters}; | |||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 11 | ▶ | sub tt_opts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt_opts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 11 | return {}; | |||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | 40 | ▶ | sub tt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tt: called CC=8 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 40 | my ($self, $tt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 656 | 40 | my $util = $self->util; | |||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | 40 | ▶ | if($tt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | $util->{tt} = $tt; | |||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | 40 | ▶ | if(!$util->{tt}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | 11 | my $filters = Template::Filters->new({ | |||||||||||||||||||||||||||||||||||||||||
| 664 | FILTERS => $self->tt_filters, | ||||||||||||||||||||||||||||||||||||||||||
| 665 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 666 | 11 | my $opts = $self->tt_opts; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 11 | ▶ | my $ns = $util->config->val('application', 'namespace') || | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$util->config->val('application', 'namespace') || $util->config->val('application', 'name')
MC/DC0%0/2
$util->config->val('application', 'namespace') || $util->config->val('application', 'name')
$util->config->val('application', 'namespace')
$util->config->val('application', 'name')
Truth table33%1/3
A || B
A= $util->config->val('application', 'namespace')B= $util->config->val('application', 'name')
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | $util->config->val('application', 'name'); | ||||||||||||||||||||||||||||||||||||||||||
| 669 | 11 | ▶ | my $plugin_base = $ns ? q[ClearPress::Template::Plugin] : sprintf q[%s::plugin], $ns; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 670 | 11 | my $defaults = { | |||||||||||||||||||||||||||||||||||||||||
| 671 | PLUGIN_BASE => $plugin_base, | ||||||||||||||||||||||||||||||||||||||||||
| 672 | RECURSION => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 673 | INCLUDE_PATH => (sprintf q[%s/templates], $util->data_path), | ||||||||||||||||||||||||||||||||||||||||||
| 674 | EVAL_PERL => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 675 | ENCODING => 'utf8', | ||||||||||||||||||||||||||||||||||||||||||
| 676 | LOAD_FILTERS => [ $filters ], | ||||||||||||||||||||||||||||||||||||||||||
| 677 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | 11 | ▶ | while (my ($k, $v) = each %{$defaults}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 66 | ▶ | if(!exists $opts->{$k}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | 66 | $opts->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 11 | ▶ | $util->{tt} = Template->new($opts) or croak $Template::ERROR; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||
| 687 | 40 | return $util->{tt}; | |||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||
| 690 | 53 | ▶ | sub decor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decor: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | 53 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 692 | 53 | ▶ | my $aspect = $self->aspect || q[]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->aspect || ''
MC/DC100%1/1
$self->aspect || ''
$self->aspect
Truth table100%2/2
A
A= $self->aspect
| |||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 53 | ▶ | if($self->action eq 'options') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | 53 | for my $ending (qw(rss atom ajax xml | |||||||||||||||||||||||||||||||||||||||||
| 699 | json js _png _jpg _svg _svgz | ||||||||||||||||||||||||||||||||||||||||||
| 700 | _txt _csv _xls)) { | ||||||||||||||||||||||||||||||||||||||||||
| 701 | 453 | ▶ | if((substr $aspect, -length $ending, length $ending) eq $ending) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 26 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | 27 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||
| 708 | 20 | ▶ | sub output_flush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output_flush: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | 20 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 710 | 20 | ▶ | $DEBUG_OUTPUT and carp "output_flush: @{[scalar @{$self->{output_buffer}}]} blobs in queue"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||
| 712 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 20 | ▶ | print grep { $_ } @{$self->{output_buffer}} or croak $ERRNO; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | 20 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 718 | # client stopped receiving (e.g. disconnect from lengthy streamed response) | ||||||||||||||||||||||||||||||||||||||||||
| 719 | # | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | carp qq[Error flushing output_buffer: $EVAL_ERROR]; | |||||||||||||||||||||||||||||||||||||||||
| 721 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||
| 723 | 20 | $self->output_reset; | |||||||||||||||||||||||||||||||||||||||||
| 724 | 20 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | 16 | ▶ | sub output_prepend { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output_prepend: called CC=6 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | 16 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 729 | 16 | ▶ | if(!$self->output_finished) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | 15 | ▶ | if(scalar @args == 2 && $args[1] eq "\n" && !$args[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
scalar @args == 2 and $args[1] eq "\n" and not $args[0]
scalar @args == 2 and $args[1] eq "\n"
MC/DC0%0/3
scalar @args == 2 and $args[1] eq "\n" and not $args[0]
scalar @args == 2
$args[1] eq "\n"
not $args[0]
Truth table25%1/4
A and B and not(C)
A= scalar @args == 2B= $args[1] eq "\n"C= not $args[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||
| 733 | 15 | unshift @{$self->{output_buffer}}, grep { $_ } @args; # don't push undef or "" | |||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | $DEBUG_OUTPUT and carp "output_prepend prepended (@{[scalar @args]} blobs)"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | 16 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||
| 739 | 35 | ▶ | sub output_buffer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output_buffer: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | 35 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 741 | 35 | ▶ | if(!$self->output_finished) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | 33 | ▶ | if(scalar @args == 2 && $args[1] eq "\n" && !$args[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
scalar @args == 2 and $args[1] eq "\n" and not $args[0]
scalar @args == 2 and $args[1] eq "\n"
MC/DC0%0/3
scalar @args == 2 and $args[1] eq "\n" and not $args[0]
scalar @args == 2
$args[1] eq "\n"
not $args[0]
Truth table50%2/4
A and B and not(C)
A= scalar @args == 2B= $args[1] eq "\n"C= not $args[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||
| 746 | 33 | push @{$self->{output_buffer}}, grep { $_ } @args; # don't push undef or "" | |||||||||||||||||||||||||||||||||||||||||
| 747 | 33 | ▶ | $DEBUG_OUTPUT and carp "output_buffer added (@{[scalar @args]} blobs)"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | 35 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | 70 | ▶ | sub output_finished { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output_finished: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | 70 | my ($self, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 754 | 70 | ▶ | if(defined $val) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 755 | 19 | $self->{output_finished} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 756 | 19 | ▶ | $DEBUG_OUTPUT and carp "output_finished = $val"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||
| 758 | 70 | return $self->{output_finished}; | |||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | 19 | ▶ | sub output_end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output_end: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 762 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 763 | 19 | ▶ | $DEBUG_OUTPUT and carp "output_end: $self"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | 19 | $self->output_finished(1); | |||||||||||||||||||||||||||||||||||||||||
| 765 | 19 | return $self->output_flush; | |||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | 26 | ▶ | sub output_reset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output_reset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 770 | 26 | $self->{output_buffer} = []; | |||||||||||||||||||||||||||||||||||||||||
| 771 | 26 | ▶ | $DEBUG_OUTPUT and carp 'output_reset'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | 26 | return; | |||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | 11 | ▶ | sub actions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
actions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 777 | 11 | my $content = q[]; | |||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 11 | $self->process_template('actions.tt2', {}, \$content); | |||||||||||||||||||||||||||||||||||||||||
| 780 | 11 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | ▶ | sub redirect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redirect: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | my ($self, $url, $status) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | $self->headers->header('Status', HTTP_FOUND); | |||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | $self->headers->header('Location', $url); | |||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 790 | # - reset all previously output but unflushed content | ||||||||||||||||||||||||||||||||||||||||||
| 791 | # - push headers down the pipe, and html redirects | ||||||||||||||||||||||||||||||||||||||||||
| 792 | # - finish up | ||||||||||||||||||||||||||||||||||||||||||
| 793 | # | ||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | $self->output_reset(); | |||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | if($TRAP_REDIR_OVERFLOW) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | ▶ | if(length $self->headers->as_string > $TRAP_REDIR_OVERFLOW) { # fudge for apparent buffer overflow with apache+mod_perl (ParseHeaders related?) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | carp q[warning: header block looks long]; | |||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | $self->headers->remove_header('Location'); | |||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | $self->headers->header('Status', HTTP_OK); | |||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||
| 802 | } | ||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | $self->output_buffer($self->headers->as_string, "\n"); | |||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | $self->decorator->meta_refresh(qq[0;URL='$url']); | |||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||
| 807 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 808 | # clean everything up and terminate | ||||||||||||||||||||||||||||||||||||||||||
| 809 | # | ||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | $self->output_flush(); | |||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | $self->headers->clear(); | |||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | ######## | ||||||||||||||||||||||||||||||||||||||||||
| 814 | # Warning: This ought to correspond to content-type, but doesn't! | ||||||||||||||||||||||||||||||||||||||||||
| 815 | # | ||||||||||||||||||||||||||||||||||||||||||
| 816 | return <<"EOT" | ||||||||||||||||||||||||||||||||||||||||||
| 817 | <p>This document has moved <a href="$url">here</a>.</p> | ||||||||||||||||||||||||||||||||||||||||||
| 818 | <script>document.location.href="$url";</script> | ||||||||||||||||||||||||||||||||||||||||||
| 819 | EOT | ||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | ######### | ||||||||||||||||||||||||||||||||||||||||||
| 823 | # automated method generation for core CRUD+ view methods | ||||||||||||||||||||||||||||||||||||||||||
| 824 | # | ||||||||||||||||||||||||||||||||||||||||||
| 825 | 7 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 826 | 7 | ▶ | no strict 'refs'; ## no critic (ProhibitNoStrict) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 827 | 7 | for my $ext (qw(xml ajax json csv)) { | |||||||||||||||||||||||||||||||||||||||||
| 828 | 28 | for my $method (qw(create list read update delete options)) { | |||||||||||||||||||||||||||||||||||||||||
| 829 | 168 | my $ns = sprintf q[%s_%s], $method, $ext; | |||||||||||||||||||||||||||||||||||||||||
| 830 | 168 | ▶ | *{$ns} = sub { my $self = shift; return $self->$method; }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||
| 835 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 836 | __END__ | ||||||||||||||||||||||||||||||||||||||||||