line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::BasePerRequest::Lifecycle::Factory; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
551
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
5
|
use Scalar::Util (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
6
|
1
|
|
|
1
|
|
5
|
use Module::Runtime (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
422
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub ACCEPT_CONTEXT { |
9
|
12
|
|
|
12
|
0
|
703
|
my ($factory, $c, @args) = @_; |
10
|
12
|
|
|
|
|
35
|
$factory->build($c, @args); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub build { |
14
|
12
|
|
|
12
|
0
|
27
|
my ($factory, $c, @args) = @_; |
15
|
12
|
|
|
|
|
28
|
my $class = $factory->{class}; |
16
|
12
|
50
|
|
|
|
98
|
@args = $class->prepare_build_args($c, @args) if $class->can('prepare_build_args'); |
17
|
12
|
|
|
|
|
136
|
my %build_args = $factory->prepare_build_args($c, @args); |
18
|
|
|
|
|
|
|
my $view = eval { |
19
|
|
|
|
|
|
|
$class->build(%build_args); |
20
|
12
|
|
33
|
|
|
28
|
} || do { |
21
|
|
|
|
|
|
|
$factory->do_handle_build_view_exception($class, $@); |
22
|
|
|
|
|
|
|
}; |
23
|
12
|
|
|
|
|
1136
|
$c->stash(current_view_instance=>$view); |
24
|
12
|
|
|
|
|
961
|
return $view; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
0
|
0
|
sub build_view_error_class { return 'Catalyst::View::BasePerRequest::Exception::BuildViewError' } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub do_handle_build_view_exception { |
30
|
0
|
|
|
0
|
0
|
0
|
my ($factory, $class, $err) = @_; |
31
|
0
|
0
|
0
|
|
|
0
|
return $err->rethrow if Scalar::Util::blessed($err) && $err->can('rethrow'); |
32
|
0
|
|
|
|
|
0
|
my $exception = Module::Runtime::use_module($factory->build_view_error_class); |
33
|
0
|
|
|
|
|
0
|
$exception->throw(class=>$class, build_error=>$err); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub prepare_build_args { |
37
|
12
|
|
|
12
|
0
|
31
|
my ($factory, $c, @args) = @_; |
38
|
12
|
|
|
|
|
38
|
my %args = $factory->prepare_args(@args); |
39
|
12
|
50
|
|
|
|
19
|
my %merged_args = %{$factory->{merged_args}||+{}}; |
|
12
|
|
|
|
|
63
|
|
40
|
12
|
|
|
|
|
70
|
return (%merged_args, %args, app=>$factory->{app}, ctx=>$c); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub prepare_args { |
44
|
12
|
|
|
12
|
0
|
36
|
my ($factory, @args) = @_; |
45
|
12
|
50
|
50
|
|
|
66
|
if( (ref($args[-1])||'') eq 'CODE' ) { |
46
|
0
|
|
|
|
|
0
|
my $code = pop @args; |
47
|
0
|
|
|
|
|
0
|
push @args, (code=>$code); |
48
|
|
|
|
|
|
|
} |
49
|
12
|
|
|
|
|
36
|
return @args; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Catalyst::View::BasePerRequest::Lifecycle::Factory - Build a view for each invocation |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Not intended for standalone enduser use. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 DESCRIPTION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This module is used by L<Catalyst::View::BasePerRequest> to encapsulate building the actual |
65
|
|
|
|
|
|
|
view object on a per request basis. Code here might be of interest to people building their |
66
|
|
|
|
|
|
|
own view frameworks. for example you might wish to override the exception handler or change |
67
|
|
|
|
|
|
|
how the initialization arguments are made. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 ALSO SEE |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L<Catalyst::View::BasePerRequest> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 AUTHORS & COPYRIGHT |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
See L<Catalyst::View::BasePerRequest> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 LICENSE |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
See L<Catalyst::View::BasePerRequest> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |