line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eidolon::Driver::Template; |
2
|
|
|
|
|
|
|
# ============================================================================== |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Eidolon |
5
|
|
|
|
|
|
|
# Copyright (c) 2009, Atma 7 |
6
|
|
|
|
|
|
|
# --- |
7
|
|
|
|
|
|
|
# Eidolon/Driver/Template.pm - generic template driver |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# ============================================================================== |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
1436
|
use base qw/Eidolon::Driver/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
470
|
|
12
|
1
|
|
|
1
|
|
475
|
use Eidolon::Driver::Template::Exceptions; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
13
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
14
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
259
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.02"; # 2009-05-14 05:31:44 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
19
|
|
|
|
|
|
|
# \% new() |
20
|
|
|
|
|
|
|
# constructor |
21
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
22
|
|
|
|
|
|
|
sub new |
23
|
|
|
|
|
|
|
{ |
24
|
0
|
|
|
0
|
1
|
|
my ($class, $templates_dir, $self); |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
($class, $templates_dir) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# class attributes |
29
|
0
|
|
0
|
|
|
|
$self = |
30
|
|
|
|
|
|
|
{ |
31
|
|
|
|
|
|
|
"templates_dir" => $templates_dir || "./templates/", |
32
|
|
|
|
|
|
|
"object" => undef, |
33
|
|
|
|
|
|
|
"result" => undef, |
34
|
|
|
|
|
|
|
"vars" => {} |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
bless $self, $class; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# check if template directory exists |
40
|
0
|
0
|
|
|
|
|
throw DriverError::Template::Directory($self->{"templates_dir"}) if (!-d $self->{"templates_dir"}); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
46
|
|
|
|
|
|
|
# set(%vars) |
47
|
|
|
|
|
|
|
# set template variables |
48
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
49
|
|
|
|
|
|
|
sub set |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
0
|
1
|
|
my ($self, %vars) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
foreach (keys %vars) |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
0
|
|
|
|
|
undef $self->{"vars"}->{$_} if (exists $self->{"vars"}->{$_}); |
56
|
0
|
|
|
|
|
|
$self->{"vars"}->{$_} = $vars{$_}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
61
|
|
|
|
|
|
|
# parse($tpl) |
62
|
|
|
|
|
|
|
# parse template |
63
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
64
|
|
|
|
|
|
|
sub parse |
65
|
|
|
|
|
|
|
{ |
66
|
0
|
|
|
0
|
1
|
|
throw CoreError::AbstractMethod; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
70
|
|
|
|
|
|
|
# render() |
71
|
|
|
|
|
|
|
# render template |
72
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------ |
73
|
|
|
|
|
|
|
sub render |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
0
|
1
|
|
throw CoreError::AbstractMethod; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |