Merge remote-tracking branch 'origin/new/bug_929'
[koha.git] / C4 / TmplTokenType.pm
1 package C4::TmplTokenType;
2
3 use strict;
4 #use warnings; FIXME - Bug 2505
5 require Exporter;
6
7 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
8
9 ###############################################################################
10
11 =head1 NAME
12
13 C4::TmplTokenType.pm - Types of TmplToken objects
14
15 =head1 DESCRIPTION
16
17 This is a Java-style "safe enum" singleton class for types of TmplToken objects.
18 The predefined constants are
19
20 =cut
21
22 ###############################################################################
23
24 $VERSION = 0.01;
25
26 @ISA = qw(Exporter);
27 @EXPORT_OK = qw(
28     &TEXT
29     &TEXT_PARAMETRIZED
30     &CDATA
31     &TAG
32     &DECL
33     &PI
34     &DIRECTIVE
35     &COMMENT
36     &UNKNOWN
37 );
38
39 ###############################################################################
40
41 use vars qw( $_text $_text_parametrized $_cdata
42     $_tag $_decl $_pi $_directive $_comment $_null $_unknown );
43
44 BEGIN {
45     my $new = sub {
46         my $this = 'C4::TmplTokenType';#shift;
47         my $class = ref($this) || $this;
48         my $self = {};
49         bless $self, $class;
50         ($self->{'id'}, $self->{'name'}, $self->{'desc'}) = @_;
51         return $self;
52     };
53     $_text              = &$new(0, 'TEXT');
54     $_text_parametrized = &$new(8, 'TEXT-PARAMETRIZED');
55     $_cdata             = &$new(1, 'CDATA');
56     $_tag               = &$new(2, 'TAG');
57     $_decl              = &$new(3, 'DECL');
58     $_pi                = &$new(4, 'PI');
59     $_directive         = &$new(5, 'DIRECTIVE');
60     $_comment           = &$new(6, 'COMMENT');
61     $_unknown           = &$new(7, 'UNKNOWN');
62 }
63
64 sub to_string {
65     my $this = shift;
66     return $this->{'name'}
67 }
68
69 sub TEXT                () { $_text }
70 sub TEXT_PARAMETRIZED   () { $_text_parametrized }
71 sub CDATA               () { $_cdata }
72 sub TAG                 () { $_tag }
73 sub DECL                () { $_decl }
74 sub PI                  () { $_pi }
75 sub DIRECTIVE           () { $_directive }
76 sub COMMENT             () { $_comment }
77 sub UNKNOWN             () { $_unknown }
78
79 ###############################################################################
80
81 =over
82
83 =item TEXT
84
85 normal text (#text in the DTD)
86
87 =item TEXT_PARAMETRIZED
88
89 parametrized normal text
90 (result of simple recognition of text interspersed with <TMPL_VAR> directives;
91 this has to be explicitly enabled in the scanner)
92
93 =item CDATA
94
95 normal text (CDATA in the DTD)
96
97 =item TAG
98
99 something that has the form of an HTML tag
100
101 =item DECL
102
103 something that has the form of an SGML declaration
104
105 =item PI
106
107 something that has the form of an SGML processing instruction
108
109 =item DIRECTIVE
110
111 a Template Toolkit directive
112
113 =item COMMENT
114
115 something that has the form of an HTML comment
116 (and is not recognized as an HTML::Template directive)
117
118 =item UNKNOWN
119
120 something that is not recognized at all by the scanner
121
122 =back
123
124 Note that end of file is currently represented by undef,
125 instead of a constant predefined by this module.
126
127 =cut
128
129 1;