File: 07_formatter.t

package info (click to toggle)
libhtml-template-compiled-perl 0.97-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 756 kB
  • sloc: perl: 4,504; makefile: 5
file content (50 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t'
# $Id: 07_formatter.t 751 2006-10-11 21:52:50Z tinita $

use lib 'blib/lib';
use Test::More tests => 2;
BEGIN { use_ok('HTML::Template::Compiled::Formatter') };

my $formatter = {
	'HTC::Class1' => {
		fullname => sub {
			$_[0]->first . ' ' . $_[0]->last
		},
		first => HTC::Class1->can('first'),
		last => HTC::Class1->can('last'),
	},
};
my $htc = HTML::Template::Compiled::Formatter->new(
	path => 't/templates',
	filename => 'formatter.htc',
	debug => 0,
);
my $obj = bless ({ first => 'Abi', last => 'Gail'}, 'HTC::Class1');

$htc->param(
	test => 23,
	obj => $obj,
);
local $HTML::Template::Compiled::Formatter::formatter = $formatter;
my $out = $htc->output;
my $exp = <<EOM;
23
Abi plus Gail
Abi Gail
EOM
for ($exp, $out) {
	tr/\r\n//d;
}
ok($exp eq $out, "formatter");
sub HTC::Class1::first {
	$_[0]->{first}
}
sub HTC::Class1::last {
	$_[0]->{last}
}

__END__
<%= test%>
<%= obj/first %> plus <%= obj/last%>
<%= obj/fullname%>