Bug 7753: serials-home displays library name instead of code
[koha.git] / C4 / TmplToken.pm
bloba9cccd1105cfbf5add969a0dc8412d24588bc326
1 package C4::TmplToken;
3 use strict;
4 #use warnings; FIXME - Bug 2505
5 use C4::TmplTokenType;
6 require Exporter;
8 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
10 ###############################################################################
12 =head1 NAME
14 TmplToken.pm - Object representing a scanner token for .tmpl files
16 =head1 DESCRIPTION
18 This is a class representing a token scanned from an HTML::Template .tmpl file.
20 =cut
22 ###############################################################################
24 $VERSION = 0.01;
26 @ISA = qw(Exporter);
27 @EXPORT_OK = qw();
29 ###############################################################################
31 sub new {
32 my $this = shift;
33 my $class = ref($this) || $this;
34 my $self = {};
35 bless $self, $class;
36 ($self->{'_string'}, $self->{'_type'}, $self->{'_lc'}, $self->{'_path'}) = @_;
37 return $self;
40 sub string {
41 my $this = shift;
42 return $this->{'_string'}
45 sub type {
46 my $this = shift;
47 return $this->{'_type'}
50 sub pathname {
51 my $this = shift;
52 return $this->{'_path'}
55 sub line_number {
56 my $this = shift;
57 return $this->{'_lc'}
60 sub attributes {
61 my $this = shift;
62 return $this->{'_attr'};
65 sub set_attributes {
66 my $this = shift;
67 $this->{'_attr'} = ref $_[0] eq 'HASH'? $_[0]: \@_;
68 return $this;
71 # only meaningful for TEXT_PARAMETRIZED tokens
72 sub children {
73 my $this = shift;
74 return $this->{'_kids'};
77 # only meaningful for TEXT_PARAMETRIZED tokens
78 sub set_children {
79 my $this = shift;
80 $this->{'_kids'} = ref $_[0] eq 'ARRAY'? $_[0]: \@_;
81 return $this;
84 # only meaningful for TEXT_PARAMETRIZED tokens
85 # FIXME: DIRECTIVE is not necessarily TMPL_VAR !!
86 sub parameters_and_fields {
87 my $this = shift;
88 return map { $_->type == C4::TmplTokenType::DIRECTIVE? $_:
89 ($_->type == C4::TmplTokenType::TAG
90 && $_->string =~ /^<input\b/is)? $_: ()}
91 @{$this->{'_kids'}};
94 # only meaningful for TEXT_PARAMETRIZED tokens
95 sub anchors {
96 my $this = shift;
97 return map { $_->type == C4::TmplTokenType::TAG && $_->string =~ /^<a\b/is? $_: ()} @{$this->{'_kids'}};
100 # only meaningful for TEXT_PARAMETRIZED tokens
101 sub form {
102 my $this = shift;
103 return $this->{'_form'};
106 # only meaningful for TEXT_PARAMETRIZED tokens
107 sub set_form {
108 my $this = shift;
109 $this->{'_form'} = $_[0];
110 return $this;
113 sub has_js_data {
114 my $this = shift;
115 return defined $this->{'_js_data'} && ref($this->{'_js_data'}) eq 'ARRAY';
118 sub js_data {
119 my $this = shift;
120 return $this->{'_js_data'};
123 sub set_js_data {
124 my $this = shift;
125 $this->{'_js_data'} = $_[0];
126 return $this;
129 # predefined tests
131 sub tag_p {
132 my $this = shift;
133 return $this->type == C4::TmplTokenType::TAG;
136 sub cdata_p {
137 my $this = shift;
138 return $this->type == C4::TmplTokenType::CDATA;
141 sub text_p {
142 my $this = shift;
143 return $this->type == C4::TmplTokenType::TEXT;
146 sub text_parametrized_p {
147 my $this = shift;
148 return $this->type == C4::TmplTokenType::TEXT_PARAMETRIZED;
151 sub directive_p {
152 my $this = shift;
153 return $this->type == C4::TmplTokenType::DIRECTIVE;
156 ###############################################################################