]> Dogcows Code - chaz/p5-CGI-Ex/blob - lib/CGI/Ex/Template.pm
76cae387f68d0f7a8501bbadfe1336ff8fb4a784
[chaz/p5-CGI-Ex] / lib / CGI / Ex / Template.pm
1 package CGI::Ex::Template;
2
3 use strict;
4 use vars qw(@INCLUDE_PATH $CONTENT_SUBDIR);
5 use base qw(Template);
6
7 use CGI::Ex;
8 use CGI::Ex::Fill;
9
10 $CONTENT_SUBDIR ||= 'content';
11
12 ###----------------------------------------------------------------###
13
14 sub new {
15 my $class = shift;
16 my $args = ref($_[0]) ? shift : {@_};
17
18 $args->{INCLUDE_PATH} ||= \@INCLUDE_PATH;
19
20 return $class->SUPER::new($args);
21 }
22
23 sub process {
24 my $self = ref($_[0]) ? shift : shift->new;
25 my $in = shift;
26
27 ### force the content to have a .html prefix
28 if (! ref $in) {
29 $in .= '.html' if $in !~ /\.\w+$/;
30 }
31
32 ### prepend "content" dir as needed
33 if (! ref($in) # not a scalar ref or a file glob
34 && $in =~ m|^\w+(\.\w+)?(/\w+(\.\w+)?)*$| # not an absolute filename
35 && index($in, $CONTENT_SUBDIR) == -1) {
36 $in = $CONTENT_SUBDIR .'/'. $in;
37 }
38
39 return $self->SUPER::process($in, @_);
40 }
41
42 ###----------------------------------------------------------------###
43
44 sub out {
45 my $self = ref($_[0]) ? shift : shift->new;
46 # dex $self;
47 my $in = shift;
48 my $form = shift;
49 my $fill = shift;
50 my $out = '';
51
52 ### run the template
53 my $status = $self->process($in, $form, \$out) || die $Template::ERROR;
54
55 ### fill in any forms
56 &CGI::Ex::Fill::form_fill(\$out, $fill) if $fill && ! $self->{no_fill};
57
58 return $out;
59 }
60
61 sub print {
62 my $self = ref($_[0]) ? shift : shift->new;
63 my $in = shift;
64 my $form = shift;
65 my $fill = shift || $form;
66
67 &CGI::Ex::content_type();
68 print $self->out($in, $form, $fill);
69 }
70
71 ###----------------------------------------------------------------###
72
73 1;
74
75 __END__
76
77 =head1 NAME
78
79 CGI::Ex::Template - Beginning interface to Templating systems - for they are many
80
81 =head1 SYNOPSIS
82
83 None yet.
84
85 =head1 DESCRIPTION
86
87 =head1 AUTHORS
88
89 Paul Seamons <perlspam at seamons dot com>
90
91 =cut
92
This page took 0.034832 seconds and 3 git commands to generate.