blib/lib/OpenFrame/AppKit/Segment/TT2.pm untested

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 82 CC 6 SCAR 20.6
CC
6
Cov
0%
dispatch
20.0
directory
6.0
tt2
6.0
CRAP 7.9
1 package OpenFrame::AppKit::Segment::TT2;
2  
3 use strict;
4 use warnings::register;
5  
6 use Template;
7 use File::Spec;
8 use Pipeline::Segment;
9 use OpenFrame::Response;
10  
11 our $VERSION=3.03;
12  
13 use base qw ( Pipeline::Segment );
14  
15 my $TT2 = Template->new();
16  
17 sub directory {
18 my $self = shift;
19 my $dir = shift;
20 if (defined($dir)) {
21 $self->{template_directory} = $dir;
22 return $self;
23 } else {
24 return $self->{template_directory};
25 }
26 }
27  
28 sub dispatch {
29 my $self = shift;
30 my $pipe = shift;
31  
32 ## get the path from the request, via the store.
33 my $path = $pipe->store->get('OpenFrame::Request')->uri->path();
34  
35 ## split it up so we know where we are
36 my ($volume, $dirs, $file) = File::Spec->splitpath( $path );
37  
38 ## make sure we have a file
39 if (!$file) {
40 $file = "index.html";
41 }
42  
43 ## get the reconstituted path, with index.html tagged on if there was no file.
44 my $reconstituted = File::Spec->catfile( $self->directory, $dirs, $file );
45 my $response = OpenFrame::Response->new();
46  
47 if (!-e $reconstituted) {
48 $self->emit("file $reconstituted not found");
49 $response->code(ofERROR);
50 my $date = localtime(time());
51 $response->message(
52 qq{
53 <html>
54 <head>
55 <title>File Not Found</title>
56 </head>
57 <body>
58 <h1>File Not Found</h1>
59 <p>
60 The file $path was not found.
61 </p>
62 <hr>
63 <i>$date, OpenFrame $OpenFrame::VERSION=3.03;
64 </body>
65 </html>
66 }
67 );
68 return $response;
69 } else {
70 my $output;
71 $self->tt2->process(
72 $reconstituted,
73 $pipe->store->get('OpenFrame::AppKit::Session'),
74 \$output
75 );
76  
77 if (!$output) {
78 ## another class of error, it didn't process it properly
79 my $date = localtime(time());
80 $self->emit("access forbidden to file $reconstituted");
81 $response->code( ofERROR );
82 $response->message(
83 qq{
84 <html>
85 <head>
86 <title>Access Forbidden</title>
87 </head>
88 <body>
89 <h1>Access Forbidden</h1>
90 <p>
91 You aren't allowed to access the file $path
92 </p>
93 <hr>
94 <i>$date, OpenFrame $OpenFrame::VERSION=3.03;
95 </body>
96 </html>
97 } #'}
98 );
99 return $response;
100 }
101  
102 ## create the response
103 $response->code( ofOK );
104 $response->message( $output );
105 ## return it
106 return $response;
107 }
108 }
109  
110 ##
111 ## the tt2 method simply returns a Template object.
112 ##
113 sub tt2 {
114 my $self = shift;
115 my $tt2 = shift;
116 if (defined($tt2)) {
117 $TT2 = $tt2;
118 } else {
119 return $TT2;
120 }
121 }
122  
123 1;
124  
125 =head1 NAME
126  
127 OpenFrame::AppKit::Segment::TT2 - a pipeline segment to manage sessions
128  
129 =head1 SYNOPSIS
130  
131 use OpenFrame::AppKit;
132 my $template_engine = OpenFrame::Segment::TT2->new();
133  
134 =head1 DESCRIPTION
135  
136 The C<OpenFrame::AppKit::Segment::TT2> class is a pipeline segment and inherits its
137 interface from there. It provides additional interface in the form of the director()
138 method, which gets and sets the root template directory that the template engine will
139 examine.
140  
141 =head1 AUTHOR
142  
143 James A. Duncan <jduncan@fotango.com>
144  
145 =head1 COPYRIGHT
146  
147 Copyright 2002 Fotango Ltd. All Rights Reserved
148  
149 This program is released under the same license as Perl itself.
150  
151