-
Notifications
You must be signed in to change notification settings - Fork 257
/
TmplToken.pm
164 lines (130 loc) · 3.44 KB
/
TmplToken.pm
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package C4::TmplToken;
# Copyright Tamil 2011
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use strict;
use warnings;
use C4::TmplTokenType;
=head1 NAME
TmplToken.pm - Object representing a scanner token for .tmpl files
=head1 DESCRIPTION
This is a class representing a token scanned from an HTML::Template .tmpl file.
=cut
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self = {};
bless $self, $class;
($self->{'_string'}, $self->{'_type'}, $self->{'_lc'}, $self->{'_path'}) = @_;
return $self;
}
sub string {
my $this = shift;
return $this->{'_string'}
}
sub type {
my $this = shift;
return $this->{'_type'}
}
sub pathname {
my $this = shift;
return $this->{'_path'}
}
sub line_number {
my $this = shift;
return $this->{'_lc'}
}
sub attributes {
my $this = shift;
return $this->{'_attr'};
}
sub set_attributes {
my $this = shift;
$this->{'_attr'} = ref $_[0] eq 'HASH'? $_[0]: \@_;
return $this;
}
# only meaningful for TEXT_PARAMETRIZED tokens
sub children {
my $this = shift;
return $this->{'_kids'};
}
# only meaningful for TEXT_PARAMETRIZED tokens
sub set_children {
my $this = shift;
$this->{'_kids'} = ref $_[0] eq 'ARRAY'? $_[0]: \@_;
return $this;
}
# only meaningful for TEXT_PARAMETRIZED tokens
# FIXME: DIRECTIVE is not necessarily TMPL_VAR !!
sub parameters_and_fields {
my $this = shift;
return map { $_->type == C4::TmplTokenType::DIRECTIVE() ? $_:
($_->type == C4::TmplTokenType::TAG
&& $_->string =~ /^<input\b/is)? $_: ()}
@{$this->{'_kids'}};
}
# only meaningful for TEXT_PARAMETRIZED tokens
sub anchors {
my $this = shift;
return map { $_->type == C4::TmplTokenType::TAG && $_->string =~ /^<a\b/is? $_: ()} @{$this->{'_kids'}};
}
# only meaningful for TEXT_PARAMETRIZED tokens
sub form {
my $this = shift;
return $this->{'_form'};
}
# only meaningful for TEXT_PARAMETRIZED tokens
sub set_form {
my $this = shift;
$this->{'_form'} = $_[0];
return $this;
}
sub has_js_data {
my $this = shift;
return defined $this->{'_js_data'} && ref($this->{'_js_data'}) eq 'ARRAY';
}
sub js_data {
my $this = shift;
return $this->{'_js_data'};
}
sub set_js_data {
my $this = shift;
$this->{'_js_data'} = $_[0];
return $this;
}
# predefined tests
sub tag_p {
my $this = shift;
return $this->type == C4::TmplTokenType::TAG;
}
sub cdata_p {
my $this = shift;
return $this->type == C4::TmplTokenType::CDATA;
}
sub text_p {
my $this = shift;
return $this->type == C4::TmplTokenType::TEXT;
}
sub text_parametrized_p {
my $this = shift;
return $this->type == C4::TmplTokenType::TEXT_PARAMETRIZED;
}
sub directive_p {
my $this = shift;
return $this->type == C4::TmplTokenType::DIRECTIVE;
}
###############################################################################
1;