line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
4
|
|
1068
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
95
|
|
26
|
4
|
|
|
4
|
|
16
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
96
|
|
27
|
4
|
|
|
4
|
|
17
|
use parent ("PSGI::Hector::Response::Base"); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
16
|
|
28
|
|
|
|
|
|
|
######################################################### |
29
|
|
|
|
|
|
|
sub new{ |
30
|
7
|
|
|
7
|
1
|
17
|
my($class, $hector) = @_; |
31
|
7
|
|
|
|
|
26
|
my $self = $class->SUPER::new($hector); |
32
|
7
|
|
|
|
|
32
|
$self->{'_outputContent'} = ""; |
33
|
7
|
|
|
|
|
10
|
bless $self, $class; |
34
|
7
|
|
|
|
|
33
|
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
|
|
|
|
|
|
|
sub setContent{ |
49
|
2
|
|
|
2
|
1
|
472
|
my($self, $content) = @_; |
50
|
2
|
50
|
|
|
|
4
|
if($content){ |
51
|
2
|
|
|
|
|
4
|
$self->{'_outputContent'} .= $content; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else{ #clear the current content |
54
|
0
|
|
|
|
|
0
|
$self->{'_outputContent'} = ""; |
55
|
|
|
|
|
|
|
} |
56
|
2
|
|
|
|
|
6
|
return 1; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
######################################################### |
59
|
|
|
|
|
|
|
sub display{ #this sub will display the page headers if needed |
60
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
61
|
0
|
0
|
|
|
|
0
|
if($self->_getDisplayedHeader()){ #just display more content |
62
|
0
|
|
|
|
|
0
|
return $self->_getContent(); #get the contents of the template |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else{ #first output so display any headers |
65
|
0
|
0
|
|
|
|
0
|
if(!$self->header("Content-Type")){ #set default content type |
66
|
0
|
|
|
|
|
0
|
$self->header("Content-Type" => "text/html"); |
67
|
|
|
|
|
|
|
} |
68
|
0
|
0
|
|
|
|
0
|
if(!$self->header("Location")){ #if we dont have a redirect |
69
|
0
|
|
|
|
|
0
|
my $content = $self->_getContent(); #get the contents of the template |
70
|
0
|
|
|
|
|
0
|
$self->content($content); |
71
|
|
|
|
|
|
|
} |
72
|
0
|
0
|
0
|
|
|
0
|
if($self->getError() && $self->code() =~ m/^[123]/){ #set the error code when needed |
73
|
0
|
|
|
|
|
0
|
$self->code(500); |
74
|
0
|
|
|
|
|
0
|
$self->message('Internal Server Error'); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
0
|
$self->_setDisplayedHeader(); #we wont display the header again |
78
|
0
|
|
|
|
|
0
|
return $self->SUPER::display(); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
######################################################### |
81
|
|
|
|
|
|
|
# private methods |
82
|
|
|
|
|
|
|
######################################################## |
83
|
|
|
|
|
|
|
sub _getContent{ |
84
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
85
|
3
|
100
|
|
|
|
10
|
if($self->getError()){ |
86
|
1
|
|
|
|
|
3
|
return "Error: " . $self->getError(); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else{ |
89
|
2
|
|
|
|
|
4
|
return $self->{'_outputContent'}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
########################################################### |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 Notes |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 Author |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
MacGyveR |
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
|
|
|
|
|
|
|
return 1; |