File Coverage

blib/lib/DBIx/MyParsePP/Token.pm
Criterion Covered Total %
statement 32 58 55.1
branch 16 28 57.1
condition 3 6 50.0
subroutine 11 17 64.7
pod 0 13 0.0
total 62 122 50.8


line stmt bran cond sub pod time code
1              
2             package DBIx::MyParsePP::Token;
3              
4 6     6   31 use DBIx::MyParsePP::Symbols;
  6         10  
  6         142  
5 6     6   33 use strict;
  6         8  
  6         223  
6              
7             1;
8              
9 6     6   77 use constant TOKEN_TYPE => 0;
  6         8  
  6         515  
10 6     6   29 use constant TOKEN_VALUE => 1;
  6         9  
  6         4434  
11              
12             sub new {
13 723     723 0 1051 my ($class, $type, $value) = @_;
14 723         1647 my $token = bless([], $class);
15 723         1496 $token->[TOKEN_TYPE] = $type;
16 723         1169 $token->[TOKEN_VALUE] = $value;
17 723         1657 return $token;
18             }
19              
20             sub value {
21 55     55 0 101 return $_[0]->[TOKEN_VALUE];
22             }
23              
24             sub type {
25 176     176 0 494 return $_[0]->[TOKEN_TYPE];
26             }
27              
28             sub getValue {
29 0     0 0 0 return $_[0]->[TOKEN_VALUE];
30             }
31              
32             sub getType {
33 0     0 0 0 return $_[0]->[TOKEN_TYPE];
34             }
35              
36             sub setType {
37 0     0 0 0 $_[0]->[TOKEN_TYPE] = $_[1];
38             }
39              
40             sub setValue {
41 0     0 0 0 $_[0]->[TOKEN_VALUE] = $_[1];
42             }
43              
44             sub extract {
45 58     58 0 81 my $token = shift;
46              
47 58         82 foreach my $match (@_) {
48 118 100       191 return $token if $token->type() eq $match;
49             }
50              
51 54         119 return undef;
52             }
53              
54             sub extractInner {
55 0     0 0 0 my $token = shift;
56 0         0 return $token->extract(@_);
57             }
58              
59             sub children {
60 1     1 0 3 return ();
61             }
62              
63             # Shrinking has no effect on tokens, just return original token
64              
65             sub shrink {
66 30     30 0 98 return $_[0];
67             }
68              
69             sub toString {
70 54     54 0 59 my $token = shift;
71 54         83 my $type = $token->type();
72 54         81 my $value = $token->value();
73 54         56 my $result;
74              
75 54 50 66     405 if ($type eq 'NCHAR_STRING') {
    50 33        
    50          
    50          
    50          
    50          
    50          
    50          
    50          
    100          
    50          
    50          
    50          
76 0         0 $result = $value;
77 0         0 $result =~ s{\\}{\\\\}sgio;
78 0         0 $result =~ s{'}{\\'}sgio;
79 0         0 $result = "N'".$result."'";
80             } elsif ($type eq 'IDENT_QUOTED') {
81 0         0 return '`'.$value.'` ';
82             } elsif ($type eq 'GLOBAL_SYM') {
83 0         0 return $value; # No spaces
84             } elsif ($type eq 'SET_VAR') {
85 0         0 $result = ':=';
86             } elsif ($type eq 'BIN_NUM') {
87 0         0 $result = "b'".$value."'";
88             } elsif ($type eq 'HEX_NUM') {
89 0         0 $result = ' 0x'.$value.' ';
90             } elsif ($type eq 'TEXT_STRING') {
91 0         0 $result = $value;
92 0         0 $result =~ s{\\}{\\\\}sgio;
93 0         0 $result =~ s{'}{\\'}sgio;
94 0         0 $result = "'".$result."'";
95             } elsif ($type eq 'UNDERSCORE_CHARSET') {
96 0         0 $result = '_'.$value;
97             } elsif ($type eq '@') {
98 0         0 return '@'; # No leading space
99             } elsif (($type eq 'IDENT') || ($type eq 'LEX_HOSTNAME')) {
100 43         226 return $value.' '; # No leading space
101             } elsif ($DBIx::MyParsePP::Symbols::functions->{uc($value)} eq $type) {
102 0         0 return ' '.$value; # No trailing space
103             } elsif ($type eq '(') {
104 0         0 return $value.' '; # No leading space;
105             } elsif (($type eq '.') || ($type eq '*')) {
106 11         27 return $value; # No spaces around table.field, etc.
107             } else {
108 0           $result = ' '.$value.' ';
109             }
110 0           return $result;
111             }
112              
113             sub print {
114 0     0 0   return $_[0]->toString();
115             }
116              
117             1;
118              
119             __END__