BasePerRequest/Lifecycle/Factory.pm

filter: Statementstmt 80.0% 32 / 40 Branchbran 37.5% 3 / 8 Conditioncond 30.0% 3 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 6 totaltotal 56.9% 45 / 79 CC 9 SCAR 14.2
CC
9
Cov
66%
do_handle_build_view_exception
12.0
prepare_args
3.8
build
3.2
CRAP 4.1
« BasePerRequest/Lifecycle/Request.pm ↑ Summary BasePerRequest/Exception/BuildViewError.pm »
1 package Catalyst::View::BasePerRequest::Lifecycle::Factory;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 has 'class' => (is=>'ro', required=>1);
8 1 has 'app' => (is=>'ro', required=>1);
9 1 has 'merged_args' => (is=>'ro', required=>1);
10  
11 12 ▶sub ACCEPT_CONTEXT {
Subroutine ACCEPT_CONTEXT: called CC=2 SCAR=7.1
Pod undocumented
12 12 my ($factory, $c, @args) = @_;
13 12 ▶ return $factory unless ref($c); # Return the factory if called in application context
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c 0 12 12
14 12 $factory->build($c, @args);
15 }
16  
17 12 ▶sub build {
Subroutine build: called CC=3 SCAR=11.7
Pod undocumented
18 12 my ($factory, $c, @args) = @_;
19 12 my $class = $factory->class;
20 12 ▶ @args = $class->prepare_build_args($c, @args) if $class->can('prepare_build_args');
Branch: 1 branch
BranchTrueFalseTotal
if $class->can("prepare_build_args") 12 0 12
21 12 my %build_args = $factory->prepare_build_args($c, @args);
22 my $view = eval {
23 12 $class->build(%build_args);
24 12 ▶ } || do {
Condition33%1/3
eval { do { $class->build(%build_args) } } || do { $factory->do_handle_build_view_exception($class, $@) }
l!l&&r!l&&!r
1200
MC/DC0%0/2
eval { do { $class->build(%build_args) } } || do { $factory->do_handle_build_view_exception($class, $@) }
eval { do { $class->build(%build_args) } } do { $factory->do_handle_build_view_exception($class, $@) }
Truth table33%1/3
A || B
A= eval { do { $class->build(%build_args) } }B= do { $factory->do_handle_build_view_exception($class, $@) }
ABresult
1X1
011
000
25 0 $factory->do_handle_build_view_exception($class, $@);
26 };
27 12 $c->stash(current_view_instance=>$view);
28 12 return $view;
29 }
30  
31 0 ▶sub build_view_error_class { return 'Catalyst::View::BasePerRequest::Exception::BuildViewError' }
Subroutine build_view_error_class: not called CC=1 SCAR=6.9
Pod undocumented
32  
33 0 ▶sub do_handle_build_view_exception {
Subroutine do_handle_build_view_exception: not called CC=3 SCAR=24.8
Pod undocumented
34 0 my ($factory, $class, $err) = @_;
35 0 ▶ return $err->rethrow if Scalar::Util::blessed($err) && $err->can('rethrow');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($err) and $err->can("rethrow") 0 0 0
Condition0%0/3
builtin::blessed($err) and $err->can("rethrow")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($err) and $err->can("rethrow")
builtin::blessed($err) $err->can("rethrow")
Truth table0%0/3
A and B
A= builtin::blessed($err)B= $err->can("rethrow")
ABresult
0X0
100
111
36 0 my $exception = Module::Runtime::use_module($factory->build_view_error_class);
37 0 $exception->throw(class=>$class, build_error=>$err);
38 }
39  
40 12 ▶sub prepare_build_args {
Subroutine prepare_build_args: called CC=2 SCAR=7.0
Pod undocumented
41 12 my ($factory, $c, @args) = @_;
42 12 my %args = $factory->prepare_args(@args);
43 12 ▶ my %merged_args = %{$factory->merged_args||+{}};
Condition50%1/2
$factory->merged_args || {}
l!l
120
MC/DC0%0/1
$factory->merged_args || {}
$factory->merged_args
Truth table50%1/2
A
A= $factory->merged_args
Aresult
11
00
44 12 return (%merged_args, %args, app=>$factory->app, ctx=>$c);
45 }
46  
47 12 ▶sub prepare_args {
Subroutine prepare_args: called CC=3 SCAR=13.3
Pod undocumented
48 12 my ($factory, @args) = @_;
49 12 ▶ if( (ref($args[-1])||'') eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((ref $args[-1] || "") eq "CODE") 0 12 12
Condition50%1/2
ref $args[-1] || ''
l!l
012
MC/DC0%0/1
ref $args[-1] || ''
ref $args[-1]
Truth table50%1/2
A
A= ref $args[-1]
Aresult
11
00
50 0 my $code = pop @args;
51 0 push @args, (code=>$code);
52 }
53 12 return @args;
54 }
55  
56 1 __PACKAGE__->meta->make_immutable;
57  
58 =head1 NAME
59
60 Catalyst::View::BasePerRequest::Lifecycle::Factory - Build a view for each invocation
61  
62 =head1 SYNOPSIS
63  
64 Not intended for standalone enduser use.
65  
66 =head1 DESCRIPTION
67  
68 This module is used by L<Catalyst::View::BasePerRequest> to encapsulate building the actual
69 view object on a per request basis. Code here might be of interest to people building their
70 own view frameworks. for example you might wish to override the exception handler or change
71 how the initialization arguments are made.
72  
73 =head1 ALSO SEE
74
75 L<Catalyst::View::BasePerRequest>
76  
77 =head1 AUTHORS & COPYRIGHT
78
79 See L<Catalyst::View::BasePerRequest>
80  
81 =head1 LICENSE
82
83 See L<Catalyst::View::BasePerRequest>
84
85 =cut
« BasePerRequest/Lifecycle/Request.pm ↑ Summary BasePerRequest/Exception/BuildViewError.pm »