| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MDOM::Token; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
MDOM::Token - A single token of Makefile source code |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 INHERITANCE |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
MDOM::Token |
|
12
|
|
|
|
|
|
|
isa MDOM::Element |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
C is the abstract base class for all Tokens. In MDOM terms, a "Token" is |
|
17
|
|
|
|
|
|
|
a L that directly represents bytes of source code. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
The implementation and POD are borrowed directly from L. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
17
|
|
|
17
|
|
946
|
use strict; |
|
|
17
|
|
|
|
|
23
|
|
|
|
17
|
|
|
|
|
552
|
|
|
26
|
17
|
|
|
17
|
|
62
|
use base 'MDOM::Element'; |
|
|
17
|
|
|
|
|
21
|
|
|
|
17
|
|
|
|
|
921
|
|
|
27
|
17
|
|
|
17
|
|
80
|
use Params::Util '_INSTANCE'; |
|
|
17
|
|
|
|
|
21
|
|
|
|
17
|
|
|
|
|
664
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
17
|
|
|
17
|
|
68
|
use vars qw{$VERSION}; |
|
|
17
|
|
|
|
|
20
|
|
|
|
17
|
|
|
|
|
635
|
|
|
30
|
|
|
|
|
|
|
BEGIN { |
|
31
|
17
|
|
|
17
|
|
243
|
$VERSION = '0.007'; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# We don't load the abstracts, they are loaded |
|
35
|
|
|
|
|
|
|
# as part of the 'use base' statements. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Load the token classes |
|
38
|
17
|
|
|
17
|
|
5984
|
use MDOM::Token::Whitespace (); |
|
|
17
|
|
|
|
|
32
|
|
|
|
17
|
|
|
|
|
330
|
|
|
39
|
17
|
|
|
17
|
|
5617
|
use MDOM::Token::Comment (); |
|
|
17
|
|
|
|
|
33
|
|
|
|
17
|
|
|
|
|
286
|
|
|
40
|
17
|
|
|
17
|
|
5571
|
use MDOM::Token::Separator (); |
|
|
17
|
|
|
|
|
35
|
|
|
|
17
|
|
|
|
|
289
|
|
|
41
|
17
|
|
|
17
|
|
5885
|
use MDOM::Token::Continuation (); |
|
|
17
|
|
|
|
|
40
|
|
|
|
17
|
|
|
|
|
296
|
|
|
42
|
17
|
|
|
17
|
|
5404
|
use MDOM::Token::Bare (); |
|
|
17
|
|
|
|
|
37
|
|
|
|
17
|
|
|
|
|
303
|
|
|
43
|
17
|
|
|
17
|
|
5312
|
use MDOM::Token::Interpolation (); |
|
|
17
|
|
|
|
|
35
|
|
|
|
17
|
|
|
|
|
322
|
|
|
44
|
17
|
|
|
17
|
|
5262
|
use MDOM::Token::Modifier (); |
|
|
17
|
|
|
|
|
43
|
|
|
|
17
|
|
|
|
|
9800
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
##################################################################### |
|
47
|
|
|
|
|
|
|
# Constructor and Related |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
|
50
|
858
|
100
|
|
858
|
0
|
1257
|
if ( @_ == 2 ) { |
|
|
|
50
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# MDOM::Token->new( $content ); |
|
52
|
852
|
|
|
|
|
625
|
my $class; |
|
53
|
852
|
100
|
|
|
|
1170
|
if ($_[0] eq __PACKAGE__) { |
|
54
|
4
|
|
|
|
|
7
|
$class = 'MDOM::Token::Bare'; |
|
55
|
4
|
|
|
|
|
4
|
shift; |
|
56
|
|
|
|
|
|
|
} else { |
|
57
|
848
|
|
|
|
|
803
|
$class = shift; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
852
|
50
|
|
|
|
3929
|
return bless { |
|
60
|
|
|
|
|
|
|
content => (defined $_[0] ? "$_[0]" : ''), |
|
61
|
|
|
|
|
|
|
lineno => $., |
|
62
|
|
|
|
|
|
|
}, $class; |
|
63
|
|
|
|
|
|
|
} elsif ( @_ == 3 ) { |
|
64
|
|
|
|
|
|
|
# MDOM::Token->new( $class, $content ); |
|
65
|
6
|
50
|
|
|
|
25
|
my $class = substr( $_[0], 0, 12 ) eq 'MDOM::Token::' ? $_[1] : "MDOM::Token::$_[1]"; |
|
66
|
6
|
50
|
|
|
|
44
|
return bless { |
|
67
|
|
|
|
|
|
|
content => (defined $_[2] ? "$_[2]" : ''), |
|
68
|
|
|
|
|
|
|
lineno => $., |
|
69
|
|
|
|
|
|
|
}, $class; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Invalid argument count |
|
73
|
0
|
|
|
|
|
0
|
undef; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 set_class |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Set a specific class for a token. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub set_class { |
|
83
|
0
|
0
|
|
0
|
1
|
0
|
my $self = shift; @_ or return undef; |
|
|
0
|
|
|
|
|
0
|
|
|
84
|
0
|
0
|
|
|
|
0
|
my $class = substr( $_[0], 0, 12 ) eq 'MDOM::Token::' ? shift : 'MDOM::Token::' . shift; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Find out if the current and new classes are complex |
|
87
|
0
|
0
|
|
|
|
0
|
my $old_quote = (ref($self) =~ /\b(?:Quote|Regex)\b/o) ? 1 : 0; |
|
88
|
0
|
0
|
|
|
|
0
|
my $new_quote = ($class =~ /\b(?:Quote|Regex)\b/o) ? 1 : 0; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# No matter what happens, we will have to rebless |
|
91
|
0
|
|
|
|
|
0
|
bless $self, $class; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# If we are changing to or from a Quote style token, we |
|
94
|
|
|
|
|
|
|
# can't just rebless and need to do some extra thing |
|
95
|
|
|
|
|
|
|
# Otherwise, we have done enough |
|
96
|
0
|
0
|
|
|
|
0
|
return 1 if ($old_quote - $new_quote) == 0; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Make a new token from the old content, and overwrite the current |
|
99
|
|
|
|
|
|
|
# token's attributes with the new token's attributes. |
|
100
|
0
|
0
|
|
|
|
0
|
my $token = $class->new( $self->{content} ) or return undef; |
|
101
|
0
|
|
|
|
|
0
|
delete $self->{$_} foreach keys %$self; |
|
102
|
0
|
|
|
|
|
0
|
$self->{$_} = $token->{$_} foreach keys %$token; |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
1; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
##################################################################### |
|
110
|
|
|
|
|
|
|
# MDOM::Token Methods |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=pod |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 set_content $string |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The C method allows to set/change the string that the |
|
117
|
|
|
|
|
|
|
C object represents. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns the string you set the Token to |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub set_content { |
|
124
|
3
|
|
|
3
|
1
|
8
|
$_[0]->{content} = $_[1]; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=pod |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 add_content $string |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The C method allows you to add additional bytes of code |
|
132
|
|
|
|
|
|
|
to the end of the Token. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Returns the new full string after the bytes have been added. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
31
|
|
|
31
|
1
|
148
|
sub add_content { $_[0]->{content} .= $_[1] } |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=pod |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 length |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
The C method returns the length of the string in a Token. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
|
147
|
|
|
|
|
|
|
|
|
148
|
0
|
|
|
0
|
1
|
0
|
sub length { &CORE::length($_[0]->{content}) } |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
##################################################################### |
|
155
|
|
|
|
|
|
|
# Overloaded MDOM::Element methods |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub content { |
|
158
|
2054
|
|
|
2054
|
1
|
5053
|
$_[0]->{content}; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# You can insert either a statement, or a non-significant token. |
|
162
|
|
|
|
|
|
|
sub insert_before { |
|
163
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
164
|
0
|
0
|
|
|
|
|
my $Element = _INSTANCE(shift, 'MDOM::Element') or return undef; |
|
165
|
0
|
0
|
|
|
|
|
if ( $Element->isa('MDOM::Structure') ) { |
|
|
|
0
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
return $self->__insert_before($Element); |
|
167
|
|
|
|
|
|
|
} elsif ( $Element->isa('MDOM::Token') ) { |
|
168
|
0
|
|
|
|
|
|
return $self->__insert_before($Element); |
|
169
|
|
|
|
|
|
|
} |
|
170
|
0
|
|
|
|
|
|
''; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# As above, you can insert a statement, or a non-significant token |
|
174
|
|
|
|
|
|
|
sub insert_after { |
|
175
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
176
|
0
|
0
|
|
|
|
|
my $Element = _INSTANCE(shift, 'MDOM::Element') or return undef; |
|
177
|
0
|
0
|
|
|
|
|
if ( $Element->isa('MDOM::Structure') ) { |
|
|
|
0
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
return $self->__insert_after($Element); |
|
179
|
|
|
|
|
|
|
} elsif ( $Element->isa('MDOM::Token') ) { |
|
180
|
0
|
|
|
|
|
|
return $self->__insert_after($Element); |
|
181
|
|
|
|
|
|
|
} |
|
182
|
0
|
|
|
|
|
|
''; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=pod |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 source |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Returns the makefile source for the current token |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub source { |
|
194
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
195
|
0
|
|
|
|
|
|
return $self->content; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |