]> mj.ucw.cz Git - temple.git/blob - UCW/Temple/CGI.pm
UCW::Temple::CGI: Added html_template().
[temple.git] / UCW / Temple / CGI.pm
1 #!/usr/bin/perl
2 # Building blocks of CGI's using the UCW::Temple template engine
3 # (c) 2010 Martin Mares <mj@ucw.cz>
4
5 package UCW::Temple::CGI;
6
7 use strict;
8 use warnings;
9
10 use UCW::Temple;
11 use UCW::CGI;
12
13 require Exporter;
14 our $VERSION = 1.0;
15 our @ISA = qw(Exporter);
16 our @EXPORT = qw(out template html_template shipout);
17 our @EXPORT_OK = qw();
18
19 our @out_buffer = ();
20 $T::out_func = sub {
21         push @out_buffer, @_;
22 };
23
24 sub template($;$) {
25         my ($string, $args) = @_;
26         UCW::Temple::process_string($string, $args);
27 }
28
29 sub html_template($$) {
30         my ($string, $args) = @_;
31         my %hargs = map { $_ => html_escape($args->{$_}) } keys %$args;
32         UCW::Temple::process_string($string, \%hargs);
33 }
34
35 sub shipout() {
36         print @out_buffer;
37         @out_buffer = ();
38 }
39
40 42;