| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Sledge::Template::ClearSilver; |
|
2
|
1
|
|
|
1
|
|
38601
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
44
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw(Sledge::Template); |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
1194
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
729
|
use ClearSilver; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Sledge::Exceptions; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
|
12
|
|
|
|
|
|
|
my $class = shift; |
|
13
|
|
|
|
|
|
|
my $pkg = caller(0); |
|
14
|
|
|
|
|
|
|
no strict 'refs'; |
|
15
|
|
|
|
|
|
|
*{"$pkg\::create_template"} = sub { |
|
16
|
|
|
|
|
|
|
my ($self, $file) = @_; |
|
17
|
|
|
|
|
|
|
return $class->new($file, $self); |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
|
22
|
|
|
|
|
|
|
my ($class, $file, $page) = @_; |
|
23
|
|
|
|
|
|
|
bless { |
|
24
|
|
|
|
|
|
|
_options => { |
|
25
|
|
|
|
|
|
|
filename => $file, |
|
26
|
|
|
|
|
|
|
associate => [ $page->r ], |
|
27
|
|
|
|
|
|
|
loadpaths => [ $page->create_config->tmpl_path, '.' ], |
|
28
|
|
|
|
|
|
|
hdfpaths => [], |
|
29
|
|
|
|
|
|
|
}, |
|
30
|
|
|
|
|
|
|
_params => {}, |
|
31
|
|
|
|
|
|
|
_assoc => {}, |
|
32
|
|
|
|
|
|
|
}, $class; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub output { |
|
36
|
|
|
|
|
|
|
my $self = shift; |
|
37
|
|
|
|
|
|
|
my $input = $self->{_options}->{filename}; |
|
38
|
|
|
|
|
|
|
unless (-e $input) { |
|
39
|
|
|
|
|
|
|
Sledge::Exception::TemplateNotFound->throw( |
|
40
|
|
|
|
|
|
|
"$input: No template file detected. Check your template path.", |
|
41
|
|
|
|
|
|
|
); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
my $hdf = $self->_create_hdf; |
|
44
|
|
|
|
|
|
|
my $cs = ClearSilver::CS->new($hdf); |
|
45
|
|
|
|
|
|
|
unless ($cs->parseFile($input)) { |
|
46
|
|
|
|
|
|
|
Sledge::Exception::TemplateParseError->throw( |
|
47
|
|
|
|
|
|
|
"$input: Parse Error." |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
my $output = $cs->render; |
|
51
|
|
|
|
|
|
|
return $output; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _create_hdf { |
|
55
|
|
|
|
|
|
|
my $self = shift; |
|
56
|
|
|
|
|
|
|
local $Sledge::Template::NSSepChar = '.'; |
|
57
|
|
|
|
|
|
|
$self->_associate_dump; |
|
58
|
|
|
|
|
|
|
my $hdf = ClearSilver::HDF->new; |
|
59
|
|
|
|
|
|
|
# set loadpath |
|
60
|
|
|
|
|
|
|
_hdf_setValue($hdf, 'hdf.loadpaths', $self->{_loadpaths}); |
|
61
|
|
|
|
|
|
|
# read HDF Dataset files |
|
62
|
|
|
|
|
|
|
for my $path (@{$self->{_options}->{hdfpaths}}) { |
|
63
|
|
|
|
|
|
|
my $ret = $hdf->readFile($path); |
|
64
|
|
|
|
|
|
|
unless ($ret) { |
|
65
|
|
|
|
|
|
|
Sledge::Exception::TemplateParseError->throw( |
|
66
|
|
|
|
|
|
|
"$path: Parse Error. Couldn't create HDF Dataset." |
|
67
|
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
# set params |
|
71
|
|
|
|
|
|
|
while (my ($key, $val) = each %{$self->{_params}}) { |
|
72
|
|
|
|
|
|
|
_hdf_setValue($hdf, $key, $val); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
# set associate |
|
75
|
|
|
|
|
|
|
for my $assoc (@{$self->{_options}->{associate}}) { |
|
76
|
|
|
|
|
|
|
_hdf_setValue($hdf, $_, $assoc->param($_)) for $assoc->param; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
$hdf; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _hdf_setValue { |
|
82
|
|
|
|
|
|
|
my ($hdf, $key, $val) = @_; |
|
83
|
|
|
|
|
|
|
if (ref $val eq 'ARRAY') { |
|
84
|
|
|
|
|
|
|
my $index = 0; |
|
85
|
|
|
|
|
|
|
for my $v (@$val) { |
|
86
|
|
|
|
|
|
|
_hdf_setValue($hdf, "$key.$index", $v); |
|
87
|
|
|
|
|
|
|
$index++; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} elsif (ref $val eq 'HASH') { |
|
90
|
|
|
|
|
|
|
while (my ($k, $v) = each %$val) { |
|
91
|
|
|
|
|
|
|
_hdf_setValue($hdf, "$key.$k", $v); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
} elsif (ref $val eq 'SCALAR') { |
|
94
|
|
|
|
|
|
|
_hdf_setValue($hdf, $key, $$val); |
|
95
|
|
|
|
|
|
|
} elsif (ref $val eq '') { |
|
96
|
|
|
|
|
|
|
$hdf->setValue($key, $val); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
|
101
|
|
|
|
|
|
|
__END__ |