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
|
|
92
|
use strict; |
|
17
|
|
|
|
|
34
|
|
|
17
|
|
|
|
|
631
|
|
26
|
17
|
|
|
17
|
|
84
|
use base 'MDOM::Element'; |
|
17
|
|
|
|
|
36
|
|
|
17
|
|
|
|
|
1694
|
|
27
|
17
|
|
|
17
|
|
101
|
use Params::Util '_INSTANCE'; |
|
17
|
|
|
|
|
39
|
|
|
17
|
|
|
|
|
853
|
|
28
|
|
|
|
|
|
|
|
29
|
17
|
|
|
17
|
|
87
|
use vars qw{$VERSION}; |
|
17
|
|
|
|
|
33
|
|
|
17
|
|
|
|
|
805
|
|
30
|
|
|
|
|
|
|
BEGIN { |
31
|
17
|
|
|
17
|
|
340
|
$VERSION = '0.006'; |
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
|
|
9506
|
use MDOM::Token::Whitespace (); |
|
17
|
|
|
|
|
47
|
|
|
17
|
|
|
|
|
336
|
|
39
|
17
|
|
|
17
|
|
9661
|
use MDOM::Token::Comment (); |
|
17
|
|
|
|
|
39
|
|
|
17
|
|
|
|
|
334
|
|
40
|
17
|
|
|
17
|
|
9149
|
use MDOM::Token::Separator (); |
|
17
|
|
|
|
|
48
|
|
|
17
|
|
|
|
|
369
|
|
41
|
17
|
|
|
17
|
|
9146
|
use MDOM::Token::Continuation (); |
|
17
|
|
|
|
|
58
|
|
|
17
|
|
|
|
|
352
|
|
42
|
17
|
|
|
17
|
|
10071
|
use MDOM::Token::Bare (); |
|
17
|
|
|
|
|
46
|
|
|
17
|
|
|
|
|
363
|
|
43
|
17
|
|
|
17
|
|
8869
|
use MDOM::Token::Interpolation (); |
|
17
|
|
|
|
|
44
|
|
|
17
|
|
|
|
|
384
|
|
44
|
17
|
|
|
17
|
|
8680
|
use MDOM::Token::Modifier (); |
|
17
|
|
|
|
|
45
|
|
|
17
|
|
|
|
|
13509
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
##################################################################### |
47
|
|
|
|
|
|
|
# Constructor and Related |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
858
|
100
|
|
858
|
0
|
1732
|
if ( @_ == 2 ) { |
|
|
50
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# MDOM::Token->new( $content ); |
52
|
852
|
|
|
|
|
869
|
my $class; |
53
|
852
|
100
|
|
|
|
1458
|
if ($_[0] eq __PACKAGE__) { |
54
|
4
|
|
|
|
|
8
|
$class = 'MDOM::Token::Bare'; |
55
|
4
|
|
|
|
|
7
|
shift; |
56
|
|
|
|
|
|
|
} else { |
57
|
848
|
|
|
|
|
1118
|
$class = shift; |
58
|
|
|
|
|
|
|
} |
59
|
852
|
50
|
|
|
|
6381
|
return bless { |
60
|
|
|
|
|
|
|
content => (defined $_[0] ? "$_[0]" : ''), |
61
|
|
|
|
|
|
|
lineno => $., |
62
|
|
|
|
|
|
|
}, $class; |
63
|
|
|
|
|
|
|
} elsif ( @_ == 3 ) { |
64
|
|
|
|
|
|
|
# MDOM::Token->new( $class, $content ); |
65
|
6
|
50
|
|
|
|
32
|
my $class = substr( $_[0], 0, 12 ) eq 'MDOM::Token::' ? $_[1] : "MDOM::Token::$_[1]"; |
66
|
6
|
50
|
|
|
|
53
|
return bless { |
67
|
|
|
|
|
|
|
content => (defined $_[2] ? "$_[2]" : ''), |
68
|
|
|
|
|
|
|
lineno => $., |
69
|
|
|
|
|
|
|
}, $class; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Invalid argument count |
73
|
0
|
|
|
|
|
0
|
undef; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub set_class { |
77
|
0
|
0
|
|
0
|
0
|
0
|
my $self = shift; @_ or return undef; |
|
0
|
|
|
|
|
0
|
|
78
|
0
|
0
|
|
|
|
0
|
my $class = substr( $_[0], 0, 12 ) eq 'MDOM::Token::' ? shift : 'MDOM::Token::' . shift; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Find out if the current and new classes are complex |
81
|
0
|
0
|
|
|
|
0
|
my $old_quote = (ref($self) =~ /\b(?:Quote|Regex)\b/o) ? 1 : 0; |
82
|
0
|
0
|
|
|
|
0
|
my $new_quote = ($class =~ /\b(?:Quote|Regex)\b/o) ? 1 : 0; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# No matter what happens, we will have to rebless |
85
|
0
|
|
|
|
|
0
|
bless $self, $class; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# If we are changing to or from a Quote style token, we |
88
|
|
|
|
|
|
|
# can't just rebless and need to do some extra thing |
89
|
|
|
|
|
|
|
# Otherwise, we have done enough |
90
|
0
|
0
|
|
|
|
0
|
return 1 if ($old_quote - $new_quote) == 0; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Make a new token from the old content, and overwrite the current |
93
|
|
|
|
|
|
|
# token's attributes with the new token's attributes. |
94
|
0
|
0
|
|
|
|
0
|
my $token = $class->new( $self->{content} ) or return undef; |
95
|
0
|
|
|
|
|
0
|
delete $self->{$_} foreach keys %$self; |
96
|
0
|
|
|
|
|
0
|
$self->{$_} = $token->{$_} foreach keys %$token; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
##################################################################### |
104
|
|
|
|
|
|
|
# MDOM::Token Methods |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 set_content $string |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The C method allows to set/change the string that the |
111
|
|
|
|
|
|
|
C object represents. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Returns the string you set the Token to |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub set_content { |
118
|
3
|
|
|
3
|
1
|
12
|
$_[0]->{content} = $_[1]; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=pod |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 add_content $string |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
The C method allows you to add additional bytes of code |
126
|
|
|
|
|
|
|
to the end of the Token. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns the new full string after the bytes have been added. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
31
|
|
|
31
|
1
|
197
|
sub add_content { $_[0]->{content} .= $_[1] } |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=pod |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 length |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
The C method returns the length of the string in a Token. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
0
|
1
|
0
|
sub length { &CORE::length($_[0]->{content}) } |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
##################################################################### |
149
|
|
|
|
|
|
|
# Overloaded MDOM::Element methods |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub content { |
152
|
2054
|
|
|
2054
|
1
|
10938
|
$_[0]->{content}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# You can insert either a statement, or a non-significant token. |
156
|
|
|
|
|
|
|
sub insert_before { |
157
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
158
|
0
|
0
|
|
|
|
|
my $Element = _INSTANCE(shift, 'MDOM::Element') or return undef; |
159
|
0
|
0
|
|
|
|
|
if ( $Element->isa('MDOM::Structure') ) { |
|
|
0
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return $self->__insert_before($Element); |
161
|
|
|
|
|
|
|
} elsif ( $Element->isa('MDOM::Token') ) { |
162
|
0
|
|
|
|
|
|
return $self->__insert_before($Element); |
163
|
|
|
|
|
|
|
} |
164
|
0
|
|
|
|
|
|
''; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# As above, you can insert a statement, or a non-significant token |
168
|
|
|
|
|
|
|
sub insert_after { |
169
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
170
|
0
|
0
|
|
|
|
|
my $Element = _INSTANCE(shift, 'MDOM::Element') or return undef; |
171
|
0
|
0
|
|
|
|
|
if ( $Element->isa('MDOM::Structure') ) { |
|
|
0
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
return $self->__insert_after($Element); |
173
|
|
|
|
|
|
|
} elsif ( $Element->isa('MDOM::Token') ) { |
174
|
0
|
|
|
|
|
|
return $self->__insert_after($Element); |
175
|
|
|
|
|
|
|
} |
176
|
0
|
|
|
|
|
|
''; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=pod |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 source |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Returns the makefile source for the current token |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub source { |
188
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
189
|
0
|
|
|
|
|
|
return $self->content; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
1; |