line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# File: sequencer.pm |
4
|
|
|
|
|
|
|
# Version: 0.2 |
5
|
|
|
|
|
|
|
# Author: Jeremy Wall |
6
|
|
|
|
|
|
|
# Definition: This is the templating engine for template files. It uses the |
7
|
|
|
|
|
|
|
# parser engine to parse a file or string into tokens and then |
8
|
|
|
|
|
|
|
# uses object methods to look at the tokens or return a parsed file |
9
|
|
|
|
|
|
|
# file using the handlers in the handle library and based on the |
10
|
|
|
|
|
|
|
# current environment the object is running in. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
13
|
|
|
|
|
|
|
package Bricklayer::Templater::Sequencer; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
61
|
|
16
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
249
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
612
|
use Bricklayer::Templater::Parser; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
649
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Bricklayer::Templater::Sequencer - Internal Module used by L; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 Description |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Handles parsing the template and replacing the tags with returned text for Bricklayer::Templater |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 new_sequencer |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Creates a new sequencer object. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my %handlerCache; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new_sequencer { |
39
|
2
|
|
|
2
|
1
|
4
|
my $Proto = shift; |
40
|
2
|
50
|
|
|
|
14
|
my $TemplateText = shift or confess("No template specified"); |
41
|
2
|
|
|
|
|
5
|
my $tagID = shift; |
42
|
2
|
|
|
|
|
3
|
my $start = shift; |
43
|
2
|
|
|
|
|
3
|
my $end =shift; |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
33
|
|
|
10
|
my $Class = ref($Proto) || $Proto; |
46
|
2
|
|
|
|
|
11
|
my @TokenList = Bricklayer::Templater::Parser::parse_text($TemplateText, $tagID, $start, $end); |
47
|
|
|
|
|
|
|
#die "this many tokens found ".scalar(@TokenList); |
48
|
2
|
|
|
|
|
8
|
return bless(\@TokenList, $Class); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 return_parsed |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
returns a string with the replacement text for a parsed token |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# returns a string with the replacement text for the parsed token |
60
|
|
|
|
|
|
|
sub return_parsed($$$$) { |
61
|
2
|
|
|
2
|
1
|
3
|
my $Self = shift; |
62
|
2
|
|
|
|
|
3
|
my $Env = shift; |
63
|
2
|
|
|
|
|
4
|
my $Parameters = shift; |
64
|
2
|
|
|
|
|
18
|
my $handler_loc = shift; |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
6
|
parse_tokens($Self, $Env, $Parameters, $handler_loc); |
67
|
2
|
|
|
|
|
5
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 parse_tokens |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
actually runs through the list of tokens and loades the handler or retrieves it from the handler cache to run. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub parse_tokens($$$$) { |
77
|
2
|
|
|
2
|
1
|
3
|
my $TokenList = shift; |
78
|
2
|
|
|
|
|
3
|
my $App = shift; |
79
|
2
|
|
|
|
|
3
|
my $Parameters = shift; |
80
|
2
|
|
|
|
|
3
|
my $handler_loc = shift; |
81
|
2
|
|
|
|
|
3
|
my $ParsedText; |
82
|
2
|
|
|
|
|
11
|
my $tokenCount = scalar(@$TokenList); |
83
|
2
|
|
|
|
|
3
|
my $loopCount = 0; |
84
|
2
|
|
|
|
|
4
|
foreach my $Token (@$TokenList) { |
85
|
|
|
|
|
|
|
# we are dynamically loading our handlers here |
86
|
|
|
|
|
|
|
# using symbolic references and a little perl magic |
87
|
|
|
|
|
|
|
# Seperate handlers with :: to denote directories |
88
|
|
|
|
|
|
|
# in the handler directory. |
89
|
4
|
|
|
|
|
11
|
my $handler; |
90
|
4
|
|
|
|
|
9
|
my $tagname = 'Bricklayer::Templater::Handler::'.$Token->{tagname}; |
91
|
4
|
|
|
|
|
5
|
my $Seperator = "/"; |
92
|
4
|
|
|
|
|
4
|
my $SymbolicRef = $tagname; |
93
|
|
|
|
|
|
|
# $tagname =~ s/::/$Seperator/g; |
94
|
4
|
100
|
|
|
|
10
|
if (exists($handlerCache{$Token->{tagname}})) { |
95
|
2
|
|
|
|
|
12
|
$handler = $handlerCache{$Token->{tagname}}->load($Token, $App); |
96
|
2
|
|
|
|
|
7
|
$handler->run_handler($Parameters); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} else { |
99
|
1
|
|
|
1
|
|
903
|
eval "use $tagname"; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
|
1
|
|
|
|
|
620
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
161
|
|
100
|
2
|
50
|
|
|
|
9
|
if (!$@) { |
101
|
2
|
|
|
|
|
12
|
$handler = $SymbolicRef->load($Token, $App); |
102
|
|
|
|
|
|
|
} else { |
103
|
0
|
|
|
|
|
0
|
carp("grrr no such handler: $Token->{tagname} at $tagname.pm"); |
104
|
0
|
|
|
|
|
0
|
next; |
105
|
|
|
|
|
|
|
} |
106
|
2
|
|
|
|
|
22
|
$handlerCache{$Token->{tagname}} = $SymbolicRef; |
107
|
2
|
|
|
|
|
12
|
$handler->run_handler($Parameters); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
2
|
|
|
|
|
4
|
return; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SEE ALSO |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return 1; |