Hector/Response/Base.pm

filter: Statementstmt 81.8% 27 / 33 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 50.0% 2 / 4 totaltotal 77.0% 37 / 48 CC 3 SCAR 4.4
CC
3
Cov
80%
new
2.0
setCacheable
2.0
getHector
2.0
CRAP 1.6
« Hector/Response.pm ↑ Summary Hector/Base.pm »
1 #response base object for plugins
2 package PSGI::Hector::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($hector);
14
15 package myResponse;
16 use parent ("PSGI::Hector::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<HTTP::Response>.
23  
24 The module L<PSGI::Hector::Response> will load the specified response plugin on script startup.
25  
26 =head1 METHODS
27  
28 =cut
29  
30 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use parent qw(HTTP::Response PSGI::Hector::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 #########################################################
34 8 ▶sub new{
Subroutine new: called CC=2 SCAR=7.1
Pod documented
35 8 my($class, $hector) = @_;
36 8 ▶ if(!defined($hector)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hector) 0 8 8
37 0 die("No hector object given");
38 }
39 8 my $self = $class->SUPER::new(200, "OK"); #we dont care about the code or msg as they get removed later
40 8 $self->{'_hector'} = $hector; #so we can access the hector object FIXME
41 8 $self->{'_displayedHeader'} = 0; #flag set on first output
42 8 bless $self, $class;
43 8 return $self;
44 }
45 #########################################################
46  
47 =pod
48  
49 =head2 setCacheable($seconds)
50  
51 $response->setCacheable($seconds)
52  
53 Sets the page to be cached for the specified amount of seconds.
54  
55 =cut
56  
57 #########################################################
58 0 ▶sub setCacheable{
Subroutine setCacheable: not called CC=1 SCAR=6.9
Pod documented
59 0 my($self, $seconds) = @_;
60 0 $self->header("Cache-Control" => "max-age=$seconds, public");
61 0 return 1;
62 }
63 #########################################################
64 0 ▶sub getHector{
Subroutine getHector: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my $self = shift;
66 0 return $self->{'_hector'};
67 }
68 #########################################################
69 2 ▶sub display{
Subroutine display: called CC=2 SCAR=6.9
Pod undocumented
70 2 my $self = shift;
71 2 my @headers;
72 2 foreach my $field ($self->header_field_names){
73 2 push(@headers, $field => $self->header($field));
74 }
75 2 return [$self->code(), \@headers, [$self->content()]];
76 }
77 #########################################################
78 # private methods
79 #########################################################
80 1 ▶sub _setDisplayedHeader{
Subroutine _setDisplayedHeader: called CC=1 SCAR=0.0
81 1 my $self = shift;
82 1 $self->{'_displayedHeader'} = 1;
83 1 return 1;
84 }
85 #########################################################
86 2 ▶sub _getDisplayedHeader{
Subroutine _getDisplayedHeader: called CC=1 SCAR=0.0
87 2 my $self = shift;
88 2 return $self->{'_displayedHeader'};
89 }
90 ###########################################################
91  
92 =pod
93  
94 =head1 Provided classes
95  
96 In this package there are some responses already available for use:
97  
98 =over 4
99  
100 =item Raw
101  
102 See L<PSGI::Hector::Response::Raw> for details.
103  
104 =item TemplateToolkit
105  
106 See L<PSGI::Hector::Response::TemplateToolkit> for details.
107  
108 =back
109  
110 =head1 Notes
111  
112 =head1 Author
113  
114 MacGyveR <dumb@cpan.org>
115  
116 Development questions, bug reports, and patches are welcome to the above address.
117  
118 =head1 See Also
119  
120 =head1 Copyright
121  
122 Copyright (c) 2017 MacGyveR. All rights reserved.
123  
124 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
125  
126 =cut
127  
128 #########################################################
129 5 return 1;
« Hector/Response.pm ↑ Summary Hector/Base.pm »