| 1 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de> | ||||||||||||||||||||||||||||
| 3 | # File: GX/Context.pm | ||||||||||||||||||||||||||||
| 4 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package GX::Context; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use GX::Callback::Hook::Queue; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use GX::Callback::Queue; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use GX::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use GX::HTTP::Body::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 18 | # Class setup | ||||||||||||||||||||||||||||
| 19 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use GX::Class::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 5 | extends 'GX::Component'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | has 'action_queue' => ( | ||||||||||||||||||||||||||||
| 26 | isa => 'Scalar', | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | initializer => sub { GX::Callback::Queue->new } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 5 | ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 5 | has 'dispatch_stack' => ( | |||||||||||||||||||||||||||
| 31 | isa => 'Array', | ||||||||||||||||||||||||||||
| 32 | accessor => { type => 'get_reference' } | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | has 'error' => ( | |||||||||||||||||||||||||||
| 36 | isa => 'Scalar' | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 5 | has 'error_stream' => ( | |||||||||||||||||||||||||||
| 40 | isa => 'Scalar' | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | has 'handler_queue' => ( | ||||||||||||||||||||||||||||
| 44 | isa => 'Scalar', | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | initializer => sub { GX::Callback::Hook::Queue->new } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 46 | 5 | ); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 5 | has 'input_stream' => ( | |||||||||||||||||||||||||||
| 49 | isa => 'Scalar' | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 5 | has 'output_stream' => ( | |||||||||||||||||||||||||||
| 53 | isa => 'Scalar' | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 5 | has 'request' => ( | |||||||||||||||||||||||||||
| 57 | isa => 'Scalar' | ||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 5 | has 'response' => ( | |||||||||||||||||||||||||||
| 61 | isa => 'Scalar' | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 5 | has 'sessions' => ( | |||||||||||||||||||||||||||
| 65 | isa => 'Hash' | ||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5 | has 'stash' => ( | |||||||||||||||||||||||||||
| 69 | isa => 'Hash', | ||||||||||||||||||||||||||||
| 70 | accessor => { type => 'get_reference' } | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | has 'time' => ( | ||||||||||||||||||||||||||||
| 74 | isa => 'Scalar', | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | initializer => sub { time() } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 76 | 5 | ); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 5 | has 'user' => ( | |||||||||||||||||||||||||||
| 79 | isa => 'Scalar' | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 5 | build; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 86 | # Export mechanism | ||||||||||||||||||||||||||||
| 87 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 5 | __PACKAGE__->_install_import_method; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 93 | # Public methods | ||||||||||||||||||||||||||||
| 94 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub abort { | ||||||||||||||||||||||||||
|
Subroutine
abort: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | $self->done; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | $_->[1]->remove_all for @{$self->dispatch_stack}; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | return 1; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub action { | ||||||||||||||||||||||||||
|
Subroutine
action: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | return ( $_[0]->dispatch_stack->[-1] || return undef )->[0]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_[0]->dispatch_stack->[-1] || (return undef)
MC/DC0%0/1
$_[0]->dispatch_stack->[-1] || (return undef)
$_[0]->dispatch_stack->[-1]
Truth table0%0/2
A
A= $_[0]->dispatch_stack->[-1]
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub bail_out { | ||||||||||||||||||||||||||
|
Subroutine
bail_out: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | $self->abort; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ( my $handler_queue = $self->handler_queue ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | $handler_queue->remove_all; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | return 1; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub controller { | ||||||||||||||||||||||||||
|
Subroutine
controller: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return ( $_[0]->action || return undef )->controller; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_[0]->action || (return undef)
MC/DC0%0/1
$_[0]->action || (return undef)
$_[0]->action
Truth table0%0/2
A
A= $_[0]->action
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub dispatch { | ||||||||||||||||||||||||||
|
Subroutine
dispatch: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | my %args = ( @_ == 1 ) ? ( 'action' => $_[0] ) : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | my $action = $self->_get_action( $args{'controller'}, $args{'action'} ); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ( ! $action ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | complain "Unknown action"; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | my $action_queue = $self->action_queue; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ( ! $action_queue ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 0 | complain "Undefined action queue"; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | $action_queue->add( $action ); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | return 1; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub done { | ||||||||||||||||||||||||||
|
Subroutine
done: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ( my $action_queue = $self->action_queue ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | $action_queue->remove_all; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | return 1; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub forward { | ||||||||||||||||||||||||||
|
Subroutine
forward: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | my %args = ( @_ == 1 ) ? ( 'action' => $_[0] ) : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | my $action = $self->_get_action( $args{'controller'}, $args{'action'} ); | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if ( ! $action ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | complain "Unknown action"; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | my $action_queue = $self->action_queue; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ( ! $action_queue ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | complain "Undefined action queue"; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | $action_queue->replace_all( $action ); | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | $_->[1]->remove_all for @{$self->dispatch_stack}; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | return 1; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub handler { | ||||||||||||||||||||||||||
|
Subroutine
handler: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | ▶ | return ( $_[0]->handler_queue || return undef )->current; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_[0]->handler_queue || (return undef)
MC/DC0%0/1
$_[0]->handler_queue || (return undef)
$_[0]->handler_queue
Truth table0%0/2
A
A= $_[0]->handler_queue
| |||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub hook { | ||||||||||||||||||||||||||
|
Subroutine
hook: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | ▶ | return ( $_[0]->handler_queue || return undef )->current_hook; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_[0]->handler_queue || (return undef)
MC/DC0%0/1
$_[0]->handler_queue || (return undef)
$_[0]->handler_queue
Truth table0%0/2
A
A= $_[0]->handler_queue
| |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub path_for_action { | ||||||||||||||||||||||||||
|
Subroutine
path_for_action: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 218 | 0 | ▶ | my %args = ( @_ == 1 ) ? ( 'action' => $_[0] ) : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ( exists $args{'action'} || exists $args{'controller'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $args{"action"} or exists $args{"controller"}
MC/DC0%0/2
exists $args{"action"} or exists $args{"controller"}
exists $args{"action"}
exists $args{"controller"}
Truth table0%0/3
A or B
A= exists $args{"action"}B= exists $args{"controller"}
| |||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | $args{'action'} = $self->_get_action( delete @args{ qw( controller action ) } ); | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ( ! $args{'action'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | complain "Unknown action"; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | else { | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 0 | $args{'action'} = $self->action; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if ( ! $args{'action'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 0 | complain "Unspecified action"; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 0 | my $path = eval { | |||||||||||||||||||||||||||
| 240 | 0 | $self->application->router->path_for_action( %args ); | |||||||||||||||||||||||||||
| 241 | }; | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 0 | complain $@; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | return $path; | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub redirect { | ||||||||||||||||||||||||||
|
Subroutine
redirect: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 254 | 0 | ▶ | my %args = ( @_ == 1 ) ? ( 'location' => $_[0] ) : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | my $handler_queue = $self->handler_queue; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if ( ! $handler_queue ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 0 | complain "Undefined handler queue"; | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if ( ! $handler_queue->skip_to( 'FinalizeResponse' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 0 | complain "Cannot skip to FinalizeResponse hook"; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | $self->abort; | |||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | my $response = $self->response; | |||||||||||||||||||||||||||
| 271 | 0 | $response->clear; | |||||||||||||||||||||||||||
| 272 | 0 | ▶ | $response->status( $args{'status'} // 302 ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"status"} // 302
MC/DC0%0/1
$args{"status"} // 302
$args{"status"}
Truth table0%0/2
A
A= $args{"status"}
| |||||||||||||||||||||||||||||
| 273 | 0 | $response->location( $args{'location'} ); | |||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 0 | return 1; | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub render { | ||||||||||||||||||||||||||
|
Subroutine
render: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 282 | 0 | ▶ | my %args = ( @_ == 1 ) ? ( 'view' => @_ ) : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 0 | my $error; | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if ( exists $args{'view'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | local $@; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 0 | eval { | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | my $view; | |||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ( blessed $args{'view'} && $args{'view'}->isa( 'GX::View' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($args{"view"}) and $args{"view"}->isa("GX::View")
MC/DC0%0/2
builtin::blessed($args{"view"}) and $args{"view"}->isa("GX::View")
builtin::blessed($args{"view"})
$args{"view"}->isa("GX::View")
Truth table0%0/3
A and B
A= builtin::blessed($args{"view"})B= $args{"view"}->isa("GX::View")
| |||||||||||||||||||||||||||||
| 295 | 0 | $view = $args{'view'}; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | else { | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | $view = $self->application->view( $args{'view'} ); | |||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 0 | ▶ | if ( ! $view ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | 0 | throw "Unknown view"; | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 0 | delete $args{'view'}; | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 0 | $view->render( %args, context => $self ); | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | }; | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 0 | $error = $@; | |||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | else { | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 0 | my $action = $self->action; | |||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 0 | ▶ | if ( ! $action ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 0 | complain "render() cannot be called without a \"view\" argument outside the dispatch phase"; | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | my $format = $self->request->format; | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if ( ! defined $format ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 327 | 0 | $format = $action->controller->default_format; | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | { | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 0 | local $@; | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | eval { | |||||||||||||||||||||||||||
| 335 | 0 | $self->_render_action_as( $action, $format ); | |||||||||||||||||||||||||||
| 336 | }; | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 0 | $error = $@; | |||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if ( $error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | 0 | complain $error; | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 0 | return 1; | |||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | sub render_as { | ||||||||||||||||||||||||||
|
Subroutine
render_as: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 357 | 0 | my $format = shift; | |||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if ( ! defined $format ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | 0 | complain "Missing argument"; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | my $action = $self->action; | |||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ( ! $action ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 0 | complain "render_as() cannot be called outside the dispatch phase"; | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 0 | my $error; | |||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||
| 371 | { | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 0 | local $@; | |||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 0 | eval { | |||||||||||||||||||||||||||
| 376 | 0 | $self->_render_action_as( $action, $format ); | |||||||||||||||||||||||||||
| 377 | }; | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 0 | $error = $@; | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if ( $error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 384 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 385 | 0 | complain $error; | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 0 | return 1; | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 0 | ▶ | sub renderer { | ||||||||||||||||||||||||||
|
Subroutine
renderer: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 0 | ▶ | my $action = $self->action or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 0 | return $action->controller->renderer( $action->name ); | |||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 0 | ▶ | sub send_response { | ||||||||||||||||||||||||||
|
Subroutine
send_response: not called CC=27 SCAR=66.3
Pod
documented
| |||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | 0 | my $handler_queue = $self->handler_queue; | |||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if ( ! $handler_queue ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 409 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 410 | 0 | complain "Undefined handler queue"; | |||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if ( ! $handler_queue->skip_to( 'FinalizeResponse' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 0 | ▶ | return if defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 0 | complain "Cannot skip to FinalizeResponse hook"; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 0 | $self->abort; | |||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | 0 | my $response = $self->response; | |||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 0 | $response->clear; | |||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | 0 | eval { | |||||||||||||||||||||||||||
| 429 | 0 | ▶ | $response->status( $args{'status'} // 200 ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"status"} // 200
MC/DC0%0/1
$args{"status"} // 200
$args{"status"}
Truth table0%0/2
A
A= $args{"status"}
| |||||||||||||||||||||||||||||
| 430 | }; | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | 0 | GX::Exception->complain( | |||||||||||||||||||||||||||
| 434 | message => "Cannot set the response status", | ||||||||||||||||||||||||||||
| 435 | subexception => $@ | ||||||||||||||||||||||||||||
| 436 | ); | ||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 0 | ▶ | if ( defined $args{'headers'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 0 | eval { | |||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if ( ref $args{'headers'} eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 0 | my $headers = $response->headers; | |||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | 0 | for my $field ( keys %{$args{'headers'}} ) { | |||||||||||||||||||||||||||
| 448 | 0 | my $value = $args{'headers'}{$field}; | |||||||||||||||||||||||||||
| 449 | 0 | ▶ | $headers->add( $field => ref $value eq 'ARRAY' ? @$value : $value ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||
| 453 | else { | ||||||||||||||||||||||||||||
| 454 | 0 | $response->headers( $args{'headers'} ); | |||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | }; | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 460 | 0 | GX::Exception->complain( | |||||||||||||||||||||||||||
| 461 | message => "Cannot set the response headers", | ||||||||||||||||||||||||||||
| 462 | subexception => $@ | ||||||||||||||||||||||||||||
| 463 | ); | ||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if ( defined $args{'body'} ) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | 0 | eval { | |||||||||||||||||||||||||||
| 471 | 0 | $response->body( $args{'body'} ); | |||||||||||||||||||||||||||
| 472 | }; | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 475 | 0 | GX::Exception->complain( | |||||||||||||||||||||||||||
| 476 | message => "Cannot set the response body", | ||||||||||||||||||||||||||||
| 477 | subexception => $@ | ||||||||||||||||||||||||||||
| 478 | ); | ||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | elsif ( defined $args{'file'} ) { | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | 0 | my $file = $args{'file'}; | |||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 0 | ▶ | if ( ! File::Spec->file_name_is_absolute( $file ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 487 | 0 | $file = File::Spec->rel2abs( $file, $self->application->path( 'public' ) ); | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ( ! -f $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 491 | 0 | complain "File \"$file\" does not exist"; | |||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | $response->body( | ||||||||||||||||||||||||||||
| 495 | 0 | GX::HTTP::Body::File->new( | |||||||||||||||||||||||||||
| 496 | file => $file, | ||||||||||||||||||||||||||||
| 497 | readonly => 1 | ||||||||||||||||||||||||||||
| 498 | ) | ||||||||||||||||||||||||||||
| 499 | ); | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | elsif ( defined $args{'render'} ) { | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 0 | my %render_args; | |||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 0 | ▶ | if ( ref $args{'render'} eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 507 | 0 | %render_args = @{$args{'render'}}; | |||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | elsif ( ref $args{'render'} eq 'HASH' ) { | ||||||||||||||||||||||||||||
| 510 | 0 | %render_args = %{$args{'render'}}; | |||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | else { | ||||||||||||||||||||||||||||
| 513 | 0 | $render_args{'view'} = $args{'render'}; | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | 0 | eval { | |||||||||||||||||||||||||||
| 517 | 0 | $self->render( %render_args ); | |||||||||||||||||||||||||||
| 518 | }; | ||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||
| 520 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 521 | 0 | GX::Exception->complain( | |||||||||||||||||||||||||||
| 522 | message => "Render error", | ||||||||||||||||||||||||||||
| 523 | subexception => $@ | ||||||||||||||||||||||||||||
| 524 | ); | ||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | elsif ( defined $args{'render_hint'} ) { | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | 0 | my %render_args; | |||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | 0 | ▶ | if ( ref $args{'render_hint'} eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 533 | 0 | %render_args = @{$args{'render_hint'}}; | |||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | elsif ( ref $args{'render_hint'} eq 'HASH' ) { | ||||||||||||||||||||||||||||
| 536 | 0 | %render_args = %{$args{'render_hint'}}; | |||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||
| 538 | else { | ||||||||||||||||||||||||||||
| 539 | 0 | $render_args{'view'} = $args{'render_hint'}; | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | 0 | ▶ | if ( my $view = $self->application->view( delete $render_args{'view'} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | 0 | eval { | |||||||||||||||||||||||||||
| 545 | 0 | $self->render( view => $view, %render_args ); | |||||||||||||||||||||||||||
| 546 | }; | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 549 | 0 | GX::Exception->complain( | |||||||||||||||||||||||||||
| 550 | message => "Render error", | ||||||||||||||||||||||||||||
| 551 | subexception => $@ | ||||||||||||||||||||||||||||
| 552 | ); | ||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 0 | return 1; | |||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||
| 565 | 0 | ▶ | sub session { | ||||||||||||||||||||||||||
|
Subroutine
session: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | 0 | ▶ | my $session_class = $self->application->session( @_ ) or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||
| 571 | 0 | ▶ | $self->{'sessions'} ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"sessions"} ||= {}
MC/DC0%0/1
$self->{"sessions"} ||= {}
$self->{"sessions"}
Truth table0%0/2
A
A= $self->{"sessions"}
| |||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | 0 | ▶ | my $session = $self->{'sessions'}{$session_class} ||= $session_class->new( context => $self ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"sessions"}{$session_class} ||= $session_class->new("context", $self)
MC/DC0%0/2
$self->{"sessions"}{$session_class} ||= $session_class->new("context", $self)
$self->{"sessions"}{$session_class}
$session_class->new("context", $self)
Truth table0%0/3
A ||= B
A= $self->{"sessions"}{$session_class}B= $session_class->new("context", $self)
| |||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | 0 | return $session; | |||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | 0 | ▶ | sub sessions { | ||||||||||||||||||||||||||
|
Subroutine
sessions: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 0 | ▶ | $self->{'sessions'} ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"sessions"} ||= {}
MC/DC0%0/1
$self->{"sessions"} ||= {}
$self->{"sessions"}
Truth table0%0/2
A
A= $self->{"sessions"}
| |||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||
| 585 | 0 | my @sessions; | |||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | 0 | for my $session_class ( $self->application->sessions ) { | |||||||||||||||||||||||||||
| 588 | 0 | ▶ | my $session = $self->{'sessions'}{$session_class} ||= $session_class->new( context => $self ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"sessions"}{$session_class} ||= $session_class->new("context", $self)
MC/DC0%0/2
$self->{"sessions"}{$session_class} ||= $session_class->new("context", $self)
$self->{"sessions"}{$session_class}
$session_class->new("context", $self)
Truth table0%0/3
A ||= B
A= $self->{"sessions"}{$session_class}B= $session_class->new("context", $self)
| |||||||||||||||||||||||||||||
| 589 | 0 | push @sessions, $session; | |||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | 0 | return @sessions; | |||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | 0 | ▶ | sub uri_for_action { | ||||||||||||||||||||||||||
|
Subroutine
uri_for_action: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 599 | 0 | ▶ | my %args = ( @_ == 1 ) ? ( 'action' => $_[0] ) : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | 0 | ▶ | if ( exists $args{'action'} || exists $args{'controller'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $args{"action"} or exists $args{"controller"}
MC/DC0%0/2
exists $args{"action"} or exists $args{"controller"}
exists $args{"action"}
exists $args{"controller"}
Truth table0%0/3
A or B
A= exists $args{"action"}B= exists $args{"controller"}
| |||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | 0 | $args{'action'} = $self->_get_action( delete @args{ qw( controller action ) } ); | |||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | 0 | ▶ | if ( ! $args{'action'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 606 | 0 | complain "Unknown action"; | |||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||
| 610 | else { | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | 0 | $args{'action'} = $self->action; | |||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | 0 | ▶ | if ( ! $args{'action'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 615 | 0 | complain "Unspecified action"; | |||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | 0 | ▶ | if ( ! exists $args{'scheme'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | 0 | ▶ | if ( defined( my $scheme = $self->request->scheme ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 623 | 0 | $args{'scheme'} = $scheme; | |||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | 0 | ▶ | if ( ! exists $args{'host'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | 0 | ▶ | if ( defined( my $host = $self->request->host ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 631 | 0 | $args{'host'} = $host; | |||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | 0 | ▶ | if ( ! exists $args{'port'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | 0 | ▶ | if ( defined( my $port = $self->request->port ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 639 | 0 | $args{'port'} = $port; | |||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||
| 644 | 0 | my $uri = eval { | |||||||||||||||||||||||||||
| 645 | 0 | $self->application->router->uri_for_action( %args ); | |||||||||||||||||||||||||||
| 646 | }; | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 649 | 0 | complain $@; | |||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | 0 | return $uri; | |||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 658 | # Internal methods | ||||||||||||||||||||||||||||
| 659 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | 0 | ▶ | sub dispatch_queue { | ||||||||||||||||||||||||||
|
Subroutine
dispatch_queue: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | 0 | ▶ | return ( $_[0]->dispatch_stack->[-1] || return undef )->[1]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_[0]->dispatch_stack->[-1] || (return undef)
MC/DC0%0/1
$_[0]->dispatch_stack->[-1] || (return undef)
$_[0]->dispatch_stack->[-1]
Truth table0%0/2
A
A= $_[0]->dispatch_stack->[-1]
| |||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||
| 667 | 179 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||
| 669 | 179 | my $self = shift; | |||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||
| 671 | # Workaround for a memory leak in Scalar::Util::weaken() under 5.10 | ||||||||||||||||||||||||||||
| 672 | 179 | %$self = (); | |||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | 179 | return; | |||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 680 | # Private methods | ||||||||||||||||||||||||||||
| 681 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | 0 | ▶ | sub _get_action { | ||||||||||||||||||||||||||
|
Subroutine
_get_action: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 686 | 0 | my $controller = shift; | |||||||||||||||||||||||||||
| 687 | 0 | my $action = shift; | |||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | 0 | ▶ | if ( defined $action ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | 0 | ▶ | if ( blessed $action ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | 0 | ▶ | if ( $action->isa( 'GX::Action' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 694 | 0 | return $action; | |||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||
| 698 | else { | ||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||
| 700 | 0 | ▶ | if ( defined $controller ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||
| 702 | 0 | ▶ | if ( blessed $controller ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||
| 704 | 0 | ▶ | if ( ! $controller->isa( 'GX::Controller' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 705 | 0 | return undef; | |||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||
| 709 | else { | ||||||||||||||||||||||||||||
| 710 | 0 | $controller = $self->application->controller( $controller ); | |||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||
| 714 | else { | ||||||||||||||||||||||||||||
| 715 | 0 | $controller = $self->controller; | |||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||
| 718 | 0 | ▶ | if ( $controller ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 719 | 0 | return $controller->action( $action ); | |||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||
| 726 | 0 | return undef; | |||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||
| 730 | 0 | ▶ | sub _render_action_as { | ||||||||||||||||||||||||||
|
Subroutine
_render_action_as: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||
| 732 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 733 | 0 | my $action = shift; | |||||||||||||||||||||||||||
| 734 | 0 | my $format = shift; | |||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||
| 736 | 0 | my $renderer = $action->controller->renderer( $action->name ); | |||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||
| 738 | 0 | ▶ | if ( ! $renderer ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 739 | 0 | throw "No renderer associated with action"; | |||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||
| 742 | 0 | ▶ | if ( ! $renderer->can_render( $format ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||
| 744 | throw sprintf( | ||||||||||||||||||||||||||||
| 745 | "Unsupported render format \"%s\"%s", | ||||||||||||||||||||||||||||
| 746 | $format, | ||||||||||||||||||||||||||||
| 747 | 0 | do { | |||||||||||||||||||||||||||
| 748 | 0 | my @formats = $renderer->formats; | |||||||||||||||||||||||||||
| 749 | 0 | ▶ | @formats ? ' (renderer supports: ' . join( ', ', map { "\"$_\"" } @formats ) . ')' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||
| 751 | ); | ||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||
| 755 | 0 | $renderer->render( $format, context => $self ); | |||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||
| 757 | 0 | return; | |||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||
| 761 | 3 | ▶ | sub _validate_class_name { | ||||||||||||||||||||||||||
|
Subroutine
_validate_class_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||
| 763 | 3 | return $_[1] =~ /^(?:[_a-zA-Z]\w*::)+Context$/; | |||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||
| 768 | 5 | 1; | |||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||
| 770 | __END__ | ||||||||||||||||||||||||||||