Embperl/Object.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 79 CC 9 SCAR 36.9
CC
9
Cov
0%
process
72.0
new
6.0
BEGIN
2.0
CRAP 39.9
1 package Catalyst::View::Embperl::Object;
2  
3 use strict;
4  
5 use base qw( Catalyst::View );
6  
7 use NEXT;
8  
9 __PACKAGE__->mk_accessors(qw/ rootdir dumper /);
10  
11 =head1 NAME
12  
13 Catalyst::View::Embperl::Object - Embperl::Object View Class
14  
15 =head1 SYNOPSIS
16  
17 # use the helper XXX TODO
18 create.pl view Embperl::Object Epo
19  
20 # lib/MyApp/View/Epo.pm
21 package MyApp::View::Epo;
22  
23 use base 'Catalyst::View::Embperl::Object';
24  
25 __PACKAGE__->config(
26
27  
28 );
29  
30 1;
31  
32 # Meanwhile, maybe in an 'end' action
33 $c->forward('MyApp::View::Epo');
34  
35  
36 =head1 DESCRIPTION
37  
38 This is the C<Embperl::Object> view class. Your subclass should inherit from this
39 class.
40  
41 =head2 METHODS
42  
43 =over 4
44  
45 =item new
46  
47 The constructor for the Embperl::Object view.
48  
49 =cut
50  
51 sub new {
52 my($class, $c, $arguments) = @_;
53  
54 my $self = $class->NEXT::new($c);
55  
56 for my $field (keys %$arguments) {
57 if ($self->can($field)) {
58 $self->$field($arguments->{$field});
59 } else {
60 $c->log->debug("Unkown config parameter '$field'");
61 }
62 }
63  
64 BEGIN {
65 %Embperl::initparam = (use_env => 1) ;
66  
67 # XXX TODO goes in config...
68
69 $ENV{EMBPERL_SESSION_CLASSES} = "File" ;
70 $ENV{EMBPERL_SESSION_ARGS} = "Directory=/tmp";
71  
72 #$ENV{EMBPERL_OBJECT_APP} = "_app.pl" ;
73  
74 };
75  
76 # Embperl::Req::SetupSession ($req_rec, $uid, $sid, $app_param);
77  
78 use Embperl::Object;
79  
80 return $self;
81 }
82  
83 =item process
84  
85 Renders the template specified in C<< $c->stash->{template} >>
86 Template arguments are C<$c>. Output is stored in C<<
87 $c->response->body >>.
88  
89 =cut
90  
91 sub process {
92 my ( $self, $c ) = @_;
93  
94 my $template = $c->stash->{template};
95  
96 unless ($template) {
97 $c->log->debug('No template specified for rendering') if $c->debug;
98 return 0;
99 }
100  
101 $c->log->debug(qq/Rendering template "$template"/) if $c->debug;
102  
103 my $body;
104 my $errors;
105 my $err;
106  
107 my $rootdir = $self->rootdir;
108  
109 unless ($rootdir) {
110 $c->log->debug('No rootdir specified for rendering') if $c->debug;
111 return 0;
112 }
113  
114 $c->log->debug("Loading '$rootdir/$template'");
115  
116 eval {
117  
118 $err = Embperl::Object::Execute ({
119
120 # Name of the base page to search for
121 #object_app => '_app.pl',
122
123 # Name of the base page to search for
124 #object_base => '_base.epl',
125
126 # Additional directories where to search for pages. Directories are separated by ; (on Unix : works also). This path is always appended to the searchpath.
127 #object_addpath => $rootdir,
128
129 #Directory where to stop searching for the base page
130 object_stopdir => $rootdir,
131
132 #If the requested file is not found the file given by EMBPERL_OBJECT_FALLBACK is displayed instead. If EMBPERL_OBJECT_FALLBACK isn't set a staus 404, NOT_FOUND is returned as usual. If the fileame given in EMBPERL_OBJECT_FALLBACK doesn't contain a path, it is searched thru the same directories as EMBPERL_OBJECT_BASE.
133
134 # object_fallback
135
136 # If you specify this call the template base and the requested page inherit all methods from this class. This class must contain Embperl::Req in his @ISA array.
137 # object_handler_class
138
139 inputfile => "$rootdir/$template",
140 mtime => 1,
141 output => \$body,
142  
143 param => [ $c ],
144  
145 # Segmentation fault !!
146 # errors => \@body_errors,
147  
148 #options => 268432,
149 #escmode => 7,
150
151 #cookie_name => 'sessionid',
152 #cookie_path => '/',
153 #cookie_domain => 1,
154 #cookie_expires => 1,
155
156 }) ;
157 };
158 if ( my $error = $@ ) {
159 chomp $error;
160 $error = "Couldn't render template \"$template\". Error: \"$error\"";
161 $c->log->error($error);
162 $c->error($error);
163  
164 $c->log->error("EPO err $err");
165  
166 return 0;
167 }
168  
169 unless ( $c->response->headers->content_type ) {
170 $c->res->headers->content_type('text/html; charset=utf-8');
171 }
172  
173 $c->response->body( $body );
174  
175 return 1;
176 }
177  
178 =item config
179  
180 This allows your view subclass to pass additional settings to the
181 Embperl config hash.
182  
183 =back
184  
185 =head1 SEE ALSO
186  
187 L<Embperl>, L<Catalyst>, L<Catalyst::Base>.
188  
189 =head1 AUTHOR
190  
191 Christophe Le Bars, C<clb@2fp.net>
192  
193 =head1 COPYRIGHT
194  
195 This program is free software, you can redistribute it and/or modify it
196 under the same terms as Perl itself.
197  
198 =cut
199  
200 1;