line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
CGI::Application::Plugin::PageBuilder - Simplifies building pages with multiple templates. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
This module simplifies building complex web pages with many small piecemeal templates. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Instead of |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub run_mode { |
12
|
|
|
|
|
|
|
my $self = shift; |
13
|
|
|
|
|
|
|
my $header = $self->load_tmpl( 'header.tmpl' )->output(); |
14
|
|
|
|
|
|
|
my $html; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $start = $self->load_tmpl( 'view_start.tmpl' ); |
17
|
|
|
|
|
|
|
$start->param( view_name => 'This View' ); |
18
|
|
|
|
|
|
|
$html .= $start->output(); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $db = MyApp::DB::Views->retrieve_all(); # Class::DBI |
21
|
|
|
|
|
|
|
while ( my $line = $db->next() ) { |
22
|
|
|
|
|
|
|
my $template = $self->load_tmpl( 'view_element.tmpl' ); |
23
|
|
|
|
|
|
|
$template->param( name => $line->name() ); |
24
|
|
|
|
|
|
|
$template->param( info => $line->info() ); |
25
|
|
|
|
|
|
|
$html .= $template->output(); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
$html .= $self->load_tmpl( 'view_end.tmpl' )->output(); |
28
|
|
|
|
|
|
|
$html .= $self->load_tmpl( 'footer.tmpl' )->output(); |
29
|
|
|
|
|
|
|
return $html; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
You can do this: |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
CGI:App subclass: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub run_mode { |
37
|
|
|
|
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$self->pb_template( 'header.tmpl' ); |
40
|
|
|
|
|
|
|
$self->pb_template( 'view_start.tmpl' ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $db = MyApp::DB::Views->retrieve_all(); |
43
|
|
|
|
|
|
|
while( my $line = $db->next() ) { |
44
|
|
|
|
|
|
|
$self->pb_template( 'view_row.tmpl' ); |
45
|
|
|
|
|
|
|
$self->pb_param( name, $line->name() ); |
46
|
|
|
|
|
|
|
$self->pb_param( info, $line->info() ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
$self->pb_template( 'view_end.tmpl' ); |
49
|
|
|
|
|
|
|
$self->pb_template( 'footer.tmpl' ); |
50
|
|
|
|
|
|
|
return $self->pb_build(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 METHODS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 pb_template |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->pb_template( 'the_template_to_use.tmpl', ... ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Adds the template to the page. Any arguments past the template name are passed on to HTML::Template. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 pb_param |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->pb_param( name, value ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Sets the value for the param in the template. This applies to the last template loaded by B. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 pb_build |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$self->pb_build(); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Returns the combined page. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 AUTHOR |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Clint Moore Ecmoore@cpan.orgE |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Copyright (c) 2005, Clint Moore C<< >>. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
package CGI::Application::Plugin::PageBuilder; |
86
|
2
|
|
|
2
|
|
48442
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
2
|
|
8
|
use base 'Exporter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
174
|
|
89
|
2
|
|
|
2
|
|
8
|
use vars qw/ @EXPORT $VERSION /; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
732
|
|
90
|
|
|
|
|
|
|
$VERSION='1.01'; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
@EXPORT = qw( pb_template pb_param pb_build ); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub pb_template { |
95
|
9
|
|
|
9
|
1
|
1071169
|
my( $self, $template, %options ) = @_; |
96
|
|
|
|
|
|
|
|
97
|
9
|
|
|
|
|
40
|
my $t_template = $self->load_tmpl( $template, %options ); |
98
|
9
|
50
|
|
|
|
23115
|
return unless $t_template; |
99
|
|
|
|
|
|
|
|
100
|
9
|
|
|
|
|
16
|
push( @{ $self->{__PB_TEMPLATE_LIST} }, $t_template ); |
|
9
|
|
|
|
|
24
|
|
101
|
9
|
|
|
|
|
16
|
$self->{__PB__TEMPLATE_COUNT}++; |
102
|
9
|
|
|
|
|
30
|
return $self->pb_build(); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub pb_build { |
106
|
22
|
|
|
22
|
1
|
26
|
my $self = shift; |
107
|
|
|
|
|
|
|
|
108
|
22
|
|
|
|
|
38
|
$self->{__PB_BUFFER} = ''; |
109
|
22
|
|
|
|
|
25
|
foreach my $template ( @{ $self->{__PB_TEMPLATE_LIST} } ) { |
|
22
|
|
|
|
|
45
|
|
110
|
120
|
|
|
|
|
3633
|
$self->{__PB_BUFFER} .= $template->output(); |
111
|
|
|
|
|
|
|
} |
112
|
22
|
|
|
|
|
927
|
return $self->{__PB_BUFFER}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub pb_param { |
116
|
11
|
|
|
11
|
1
|
21
|
my( $self, $param, $value ) = @_; |
117
|
|
|
|
|
|
|
|
118
|
11
|
50
|
|
|
|
27
|
return unless $value; |
119
|
11
|
|
|
|
|
14
|
${$self->{__PB_TEMPLATE_LIST}}[-1]->param( $param, $value ); |
|
11
|
|
|
|
|
44
|
|
120
|
11
|
|
|
|
|
295
|
return $self->pb_build(); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |