RenderView.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 75.5% 34 / 45 CC 7 SCAR 18.7
CC
7
Cov
79%
try_forwarding_to_view
8.8
BEGIN
1.0
BEGIN
1.0
CRAP 6.5
↑ Summary RenderView/Utils/NoView.pm »
1 package Catalyst::ActionRole::RenderView;
2  
3 1 our $VERSION = '0.002';
4  
5 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Catalyst::ActionRole::RenderView::Utils::NoView;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 requires 'execute';
9  
10 1 ▶around 'execute', sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
11 1 my ($orig, $self, $controller, $c, @args) = @_;
12 1 my @return = $self->$orig($controller, $c, @args);
13 1 $self->try_forwarding_to_view($c);
14 1 return @return;
15 1 };
16  
17 1 ▶sub try_forwarding_to_view {
Subroutine try_forwarding_to_view: called CC=7 SCAR=21.8
Pod undocumented
18 1 my ($self, $c) = @_;
19  
20 1 ▶ return 0 if $c->req->method eq 'HEAD'; # Don't need a response for a HEAD request
Branch: 1 branch
BranchTrueFalseTotal
if $c->req->method eq "HEAD" 0 1 1
21 1 ▶ return 0 if defined $c->response->body; # Don't need a response if we have one
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->response->body 0 1 1
22 1 ▶ return 0 if scalar @{ $c->error }; # Don't try to make a response if there's an unhandled error
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$c->error;} 0 1 1
23 1 ▶ return 0 if $c->response->status =~ /^(?:204|3\d\d)$/; # Don't response if its a redirect or 'No Content' response
Branch: 1 branch
BranchTrueFalseTotal
if $c->response->status =~ /^(?:204|3\d\d)$/ 0 1 1
24
25 # This will either be the default_view (from config) or the 'current' view, as set by
26 # stash flags 'current_view' or 'current_view_instance'.
27  
28 1 ▶ my $view = $c->view() || Catalyst::ActionRole::RenderView::Utils::NoView->throw;
Condition33%1/3
$c->view || 'Catalyst::ActionRole::RenderView::Utils::NoView'->throw
l!l&&r!l&&!r
100
MC/DC0%0/2
$c->view || 'Catalyst::ActionRole::RenderView::Utils::NoView'->throw
$c->view 'Catalyst::ActionRole::RenderView::Utils::NoView'->throw
Truth table33%1/3
A || B
A= $c->viewB= 'Catalyst::ActionRole::RenderView::Utils::NoView'->throw
ABresult
1X1
011
000
29 0 ▶ $c->log->debug("Forwarding to view: @{[ $view->catalyst_component_name ]}") if $c->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 1 1
30 1 $c->forward($view);
31 1 return 1;
32 }
33  
34 1 1;
35  
36 =head1 NAME
37  
38 Catalyst::ActionRole::RenderView - Call the default view
39  
40 =head1 SYNOPSIS
41  
42 package Example::Controller::Root;
43  
44 use Moose;
45 use MooseX::MethodAttributes;
46  
47 extends 'Catalyst::Controller';
48  
49 sub end : Action Does(RenderView) {}
50  
51 =head1 DESCRIPTION
52  
53 This is basically L<Catalyst::Action::RenderView> done as an action role (basically a L<Moose>
54 role) rather than as a base class. This is a bit more flexible if you plan to do fancy
55 stuff with your end action.
56  
57 Two things it doesn't do that the classic L<Catalyst::Action::RenderView> does is it doesn't
58 set a default content type if none is found (old one just set C<text/html> which was probably
59 ok back in the 'Aughts but not always true now) and we don't support the C<dump_info> when in
60 debug mode since I really think something like that belongs in another part of the stack.
61  
62 I'm willing to be proven wrong, just send me your use cases and patches.
63  
64 =head1 EXCEPTIONS
65  
66 This class can throw the following exceptions which are compatible with L<CatalystX::Errors>
67  
68 =head2 No View found
69  
70 If there's no view found when calling '$c->view()' we throw L<Catalyst::ActionRole::RenderView::Utils::NoView>.
71 You can use L<CatalystX::Errors> to catch and handle that or roll your own error handling.
72  
73 =head1 AUTHOR
74  
75 John Napiorkowski <jnapiork@cpan.org>
76
77 =head1 COPYRIGHT
78
79 Copyright (c) 2023 the above named AUTHOR
80
81 =head1 LICENSE
82
83 You may distribute this code under the same terms as Perl itself.
84
85 =cut
↑ Summary RenderView/Utils/NoView.pm »