File Coverage

blib/lib/Catalyst/View/BasePerRequest/Factory.pm
Criterion Covered Total %
statement 32 37 86.4
branch 5 8 62.5
condition 6 14 42.8
subroutine 8 10 80.0
pod 0 6 0.0
total 51 75 68.0


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