line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#response base object for plugins |
2
|
|
|
|
|
|
|
package CGI::Mungo::Response::Base; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=pod |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Response Base - Base object for view plugins |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use myResponse; |
13
|
|
|
|
|
|
|
my $response = myResponse->new($mungo); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package myResponse; |
16
|
|
|
|
|
|
|
use base ("CGI::Mungo::Response::Base"); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This object should not be used directly, a new class should be created which inherits this one instead. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
All response plugins should override at least the display() method and they all a sub class of L. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
The module L will load the specified response plugin on script startup. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 METHODS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
92
|
|
31
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
63
|
|
32
|
3
|
|
|
3
|
|
16
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
227
|
|
33
|
3
|
|
|
3
|
|
15
|
use base qw(HTTP::Response CGI::Mungo::Base CGI::Mungo::Log); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3432
|
|
34
|
|
|
|
|
|
|
######################################################### |
35
|
|
|
|
|
|
|
sub new{ |
36
|
2
|
|
|
2
|
1
|
5
|
my($class, $mungo) = @_; |
37
|
2
|
50
|
|
|
|
10
|
if(!defined($mungo)){ |
38
|
0
|
|
|
|
|
0
|
confess("No mungo object given"); |
39
|
|
|
|
|
|
|
} |
40
|
2
|
|
|
|
|
21
|
my $self = $class->SUPER::new(200, "OK"); #we dont care about the code or msg as they get removed later |
41
|
2
|
|
|
|
|
183
|
$self->{'_mungo'} = $mungo; #so we can access the mungo object FIXME |
42
|
2
|
|
|
|
|
8
|
$self->{'_displayedHeader'} = 0; #flag set on first output |
43
|
2
|
|
|
|
|
7
|
bless $self, $class; |
44
|
2
|
|
|
|
|
6
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
######################################################### |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 setCacheable($seconds) |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$response->setCacheable($seconds) |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Sets the page to be cached for the specified amount of seconds. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
######################################################### |
59
|
|
|
|
|
|
|
sub setCacheable{ |
60
|
0
|
|
|
0
|
1
|
|
my($self, $seconds) = @_; |
61
|
0
|
|
|
|
|
|
$self->header("Cache-Control" => "max-age=$seconds, public"); |
62
|
0
|
|
|
|
|
|
return 1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
######################################################### |
65
|
|
|
|
|
|
|
sub getMungo{ |
66
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
return $self->{'_mungo'}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
######################################################### |
70
|
|
|
|
|
|
|
sub display{ |
71
|
0
|
|
|
0
|
0
|
|
confess("display() not overridden"); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
######################################################### |
74
|
|
|
|
|
|
|
# private methods |
75
|
|
|
|
|
|
|
######################################################### |
76
|
|
|
|
|
|
|
sub _setDisplayedHeader{ |
77
|
0
|
|
|
0
|
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
$self->{'_displayedHeader'} = 1; |
79
|
0
|
|
|
|
|
|
return 1; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
######################################################### |
82
|
|
|
|
|
|
|
sub _getDisplayedHeader{ |
83
|
0
|
|
|
0
|
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
return $self->{'_displayedHeader'}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
########################################################### |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=pod |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 Provided classes |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
In this package there are some responses already available for use: |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=over 4 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item Raw |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
See L for details. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item SimpleTemplate |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
See L for details. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
######################################################### |
109
|
|
|
|
|
|
|
return 1; |