Hector/Response/Raw.pm

filter: Statementstmt 62.1% 23 / 37 Branchbran 25.0% 3 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod 66.6% 2 / 3 totaltotal 53.1% 34 / 64 CC 8 SCAR 29.4
CC
8
Cov
50%
display
42.0
setContent
2.1
_getContent
2.0
CRAP 18.9
↑ Summary Hector/Request.pm »
1 #response object
2 package PSGI::Hector::Response::Raw;
3  
4 =pod
5  
6 =head1 NAME
7  
8 Response Raw - Raw text view plugin
9  
10 =head1 SYNOPSIS
11  
12 my $response = $hector->getResponse();
13 $response->setContent("Hello World");
14  
15 =head1 DESCRIPTION
16  
17 This view plugin allows you to simply append content to the resulting web page.
18  
19 Content is displayed at the end of the page request.
20  
21 =head1 METHODS
22  
23 =cut
24  
25 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use parent ("PSGI::Hector::Response::Base");
Subroutine BEGIN: called CC=1 SCAR=0.0
28 #########################################################
29 7 ▶sub new{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
30 7 my($class, $hector) = @_;
31 7 my $self = $class->SUPER::new($hector);
32 7 $self->{'_outputContent'} = "";
33 7 bless $self, $class;
34 7 return $self;
35 }
36 #########################################################
37  
38 =head2 setContent()
39  
40 $response->setContent("Hello World");
41  
42 Append a scalar string to the current web page content. If an undefined value is passed any
43 currently defined content will be removed.
44  
45 =cut
46  
47 #########################################################
48 2 ▶sub setContent{
Subroutine setContent: called CC=2 SCAR=7.4
Pod documented
49 2 my($self, $content) = @_;
50 2 ▶ if($content){
Branch: 1 branch
BranchTrueFalseTotal
if ($content) { } 2 0 2
51 2 $self->{'_outputContent'} .= $content;
52 }
53 else{ #clear the current content
54 0 $self->{'_outputContent'} = "";
55 }
56 2 return 1;
57 }
58 #########################################################
59 0 ▶sub display{ #this sub will display the page headers if needed
Subroutine display: not called CC=6 SCAR=37.4
Pod undocumented
60 0 my $self = shift;
61 0 ▶ if($self->_getDisplayedHeader()){ #just display more content
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_getDisplayedHeader) { } 0 0 0
62 0 return $self->_getContent(); #get the contents of the template
63 }
64 else{ #first output so display any headers
65 0 ▶ if(!$self->header("Content-Type")){ #set default content type
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->header("Content-Type")) 0 0 0
66 0 $self->header("Content-Type" => "text/html");
67 }
68 0 ▶ if(!$self->header("Location")){ #if we dont have a redirect
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->header("Location")) 0 0 0
69 0 my $content = $self->_getContent(); #get the contents of the template
70 0 $self->content($content);
71 }
72 0 ▶ if($self->getError() && $self->code() =~ m/^[123]/){ #set the error code when needed
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getError and $self->code =~ /^[123]/) 0 0 0
Condition0%0/3
$self->getError and $self->code =~ /^[123]/
!ll&&!rl&&r
000
MC/DC0%0/2
$self->getError and $self->code =~ /^[123]/
$self->getError $self->code =~ /^[123]/
Truth table0%0/3
A and B
A= $self->getErrorB= $self->code =~ /^[123]/
ABresult
0X0
100
111
73 0 $self->code(500);
74 0 $self->message('Internal Server Error');
75 }
76 }
77 0 $self->_setDisplayedHeader(); #we wont display the header again
78 0 return $self->SUPER::display();
79 }
80 #########################################################
81 # private methods
82 ########################################################
83 3 ▶sub _getContent{
Subroutine _getContent: called CC=2 SCAR=6.9
84 3 my $self = shift;
85 3 ▶ if($self->getError()){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getError) { } 1 2 3
86 1 return "Error: " . $self->getError();
87 }
88 else{
89 2 return $self->{'_outputContent'};
90 }
91 }
92 ###########################################################
93  
94 =pod
95  
96 =head1 Notes
97  
98 =head1 Author
99  
100 MacGyveR <dumb@cpan.org>
101  
102 Development questions, bug reports, and patches are welcome to the above address.
103  
104 =head1 See Also
105  
106 =head1 Copyright
107  
108 Copyright (c) 2017 MacGyveR. All rights reserved.
109  
110 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
111  
112 =cut
113  
114 ##################################################################################
115 4 return 1;
↑ Summary Hector/Request.pm »