Further breaking up of the TmplTokenizer module.
[koha.git] / misc / translator / TmplTokenType.pm
1 package TmplTokenType;
2
3 use strict;
4 require Exporter;
5
6 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
7
8 ###############################################################################
9
10 =head1 NAME
11
12 TmplTokenType.pm - Types of TmplToken objects
13
14 =head1 DESCRIPTION
15
16 This is a Java-style "safe enum" singleton class for types of TmplToken objects.
17
18 =cut
19
20 ###############################################################################
21
22 $VERSION = 0.01;
23
24 @ISA = qw(Exporter);
25 @EXPORT_OK = qw(
26     &TEXT
27     &CDATA
28     &TAG
29     &DECL
30     &PI
31     &DIRECTIVE
32     &COMMENT
33     &UNKNOWN
34 );
35
36 ###############################################################################
37
38 use vars qw( $_text $_cdata $_tag $_decl $_pi $_directive $_comment $_unknown );
39
40 BEGIN {
41     my $new = sub {
42         my $this = shift;
43         my $class = ref($this) || $this;
44         my $self = {};
45         bless $self, $class;
46         ($self->{'id'}, $self->{'name'}, $self->{'desc'}) = @_;
47         return $self;
48     };
49     $_text      = &$new(0, 'TEXT');
50     $_cdata     = &$new(1, 'CDATA');
51     $_tag       = &$new(2, 'TAG');
52     $_decl      = &$new(3, 'DECL');
53     $_pi        = &$new(4, 'PI');
54     $_directive = &$new(5, 'DIRECTIVE');
55     $_comment   = &$new(6, 'COMMENT');
56     $_unknown   = &$new(7, 'UNKNOWN');
57 }
58
59 sub to_string {
60     my $this = shift;
61     return $this->{'name'}
62 }
63
64 sub TEXT        () { $_text }
65 sub CDATA       () { $_cdata }
66 sub TAG         () { $_tag }
67 sub DECL        () { $_decl }
68 sub PI          () { $_pi }
69 sub DIRECTIVE   () { $_directive }
70 sub COMMENT     () { $_comment }
71 sub UNKNOWN     () { $_unknown }
72
73 ###############################################################################
74
75 1;