line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
###
|
3
|
|
|
|
|
|
|
# CSS::SAC::Selector - base class for SAC selectors
|
4
|
|
|
|
|
|
|
# Robin Berjon
|
5
|
|
|
|
|
|
|
# 24/02/2001
|
6
|
|
|
|
|
|
|
###
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package CSS::SAC::Selector;
|
9
|
2
|
|
|
2
|
|
11
|
use strict;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
118
|
|
10
|
2
|
|
|
2
|
|
12
|
use vars qw($VERSION);
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
125
|
|
11
|
|
|
|
|
|
|
$VERSION = $CSS::SAC::VERSION || '0.03';
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
14
|
|
|
|
|
|
|
# build the fields for an array based object
|
15
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
16
|
2
|
|
|
|
|
19
|
use Class::ArrayObjects define => {
|
17
|
|
|
|
|
|
|
fields => [qw(_type_)],
|
18
|
2
|
|
|
2
|
|
12
|
};
|
|
2
|
|
|
|
|
4
|
|
19
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
### Constants #########################################################
|
23
|
|
|
|
|
|
|
# #
|
24
|
|
|
|
|
|
|
# #
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub UNKNOWN_SELECTOR () { 1 }
|
27
|
|
|
|
|
|
|
sub ANY_NODE_SELECTOR () { 2 }
|
28
|
|
|
|
|
|
|
sub CDATA_SECTION_NODE_SELECTOR () { 3 }
|
29
|
|
|
|
|
|
|
sub CHILD_SELECTOR () { 4 }
|
30
|
|
|
|
|
|
|
sub COMMENT_NODE_SELECTOR () { 5 }
|
31
|
|
|
|
|
|
|
sub CONDITIONAL_SELECTOR () { 6 }
|
32
|
|
|
|
|
|
|
sub DESCENDANT_SELECTOR () { 7 }
|
33
|
|
|
|
|
|
|
sub DIRECT_ADJACENT_SELECTOR () { 8 }
|
34
|
|
|
|
|
|
|
sub ELEMENT_NODE_SELECTOR () { 9 }
|
35
|
|
|
|
|
|
|
sub NEGATIVE_SELECTOR () { 10 }
|
36
|
|
|
|
|
|
|
sub PROCESSING_INSTRUCTION_NODE_SELECTOR () { 11 }
|
37
|
|
|
|
|
|
|
sub PSEUDO_ELEMENT_SELECTOR () { 12 }
|
38
|
|
|
|
|
|
|
sub ROOT_NODE_SELECTOR () { 13 }
|
39
|
|
|
|
|
|
|
sub TEXT_NODE_SELECTOR () { 14 }
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# EXPERIMENTAL SELECTOR
|
42
|
|
|
|
|
|
|
sub INDIRECT_ADJACENT_SELECTOR () { 15 }
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
46
|
|
|
|
|
|
|
# import()
|
47
|
|
|
|
|
|
|
# all import can do is export the constants
|
48
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
49
|
|
|
|
|
|
|
sub import {
|
50
|
4
|
|
|
4
|
|
219
|
my $class = shift;
|
51
|
4
|
|
50
|
|
|
16
|
my $tag = shift || '';
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# check that we have the right tag
|
54
|
4
|
50
|
|
|
|
15
|
return unless $tag eq ':constants';
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# define some useful vars
|
57
|
4
|
|
|
|
|
13
|
my $pkg = caller;
|
58
|
4
|
|
|
|
|
20
|
my @constants = qw(
|
59
|
|
|
|
|
|
|
UNKNOWN_SELECTOR
|
60
|
|
|
|
|
|
|
ANY_NODE_SELECTOR
|
61
|
|
|
|
|
|
|
CDATA_SECTION_NODE_SELECTOR
|
62
|
|
|
|
|
|
|
CHILD_SELECTOR
|
63
|
|
|
|
|
|
|
COMMENT_NODE_SELECTOR
|
64
|
|
|
|
|
|
|
CONDITIONAL_SELECTOR
|
65
|
|
|
|
|
|
|
DESCENDANT_SELECTOR
|
66
|
|
|
|
|
|
|
DIRECT_ADJACENT_SELECTOR
|
67
|
|
|
|
|
|
|
ELEMENT_NODE_SELECTOR
|
68
|
|
|
|
|
|
|
NEGATIVE_SELECTOR
|
69
|
|
|
|
|
|
|
PROCESSING_INSTRUCTION_NODE_SELECTOR
|
70
|
|
|
|
|
|
|
PSEUDO_ELEMENT_SELECTOR
|
71
|
|
|
|
|
|
|
ROOT_NODE_SELECTOR
|
72
|
|
|
|
|
|
|
TEXT_NODE_SELECTOR
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
INDIRECT_ADJACENT_SELECTOR
|
75
|
|
|
|
|
|
|
);
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# now lets create the constants in the caller's package
|
78
|
2
|
|
|
2
|
|
832
|
no strict 'refs';
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
776
|
|
79
|
4
|
|
|
|
|
10
|
for my $c (@constants) {
|
80
|
60
|
|
|
|
|
104
|
my $qname = "${pkg}::$c";
|
81
|
60
|
|
|
|
|
199
|
*$qname = \&{$c};
|
|
60
|
|
|
|
|
456
|
|
82
|
|
|
|
|
|
|
}
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# #
|
88
|
|
|
|
|
|
|
# #
|
89
|
|
|
|
|
|
|
### Constants #########################################################
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
### Constructor #######################################################
|
93
|
|
|
|
|
|
|
# #
|
94
|
|
|
|
|
|
|
# #
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
98
|
|
|
|
|
|
|
# CSS::SAC::Selector->new($type)
|
99
|
|
|
|
|
|
|
# creates a new sac selector object
|
100
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
101
|
|
|
|
|
|
|
sub new {
|
102
|
88
|
50
|
|
88
|
1
|
179
|
my $class = ref($_[0])?ref(shift):shift;
|
103
|
88
|
|
|
|
|
111
|
my $type = shift;
|
104
|
88
|
|
|
|
|
389
|
return bless [$type], $class;
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# #
|
110
|
|
|
|
|
|
|
# #
|
111
|
|
|
|
|
|
|
### Constructor #######################################################
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
### Accessors #########################################################
|
116
|
|
|
|
|
|
|
# #
|
117
|
|
|
|
|
|
|
# #
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
121
|
|
|
|
|
|
|
# my $type = $sel->SelectorType()
|
122
|
|
|
|
|
|
|
# $sel->SelectorType($type)
|
123
|
|
|
|
|
|
|
# get/set the selector type
|
124
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
125
|
|
|
|
|
|
|
sub SelectorType {
|
126
|
67
|
50
|
|
67
|
1
|
226
|
(@_==2) ? $_[0]->[_type_] = $_[1] :
|
127
|
|
|
|
|
|
|
$_[0]->[_type_];
|
128
|
|
|
|
|
|
|
}
|
129
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
130
|
|
|
|
|
|
|
*CSS::SAC::Selector::getSelectorType = \&SelectorType;
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
133
|
|
|
|
|
|
|
# $sel->is_type($selector_constant)
|
134
|
|
|
|
|
|
|
# returns true is this selector is of type $selector_constant
|
135
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
136
|
|
|
|
|
|
|
sub is_type {
|
137
|
54
|
|
|
54
|
1
|
1016
|
return $_[0]->[_type_] == $_[1];
|
138
|
|
|
|
|
|
|
}
|
139
|
|
|
|
|
|
|
#---------------------------------------------------------------------#
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# #
|
143
|
|
|
|
|
|
|
# #
|
144
|
|
|
|
|
|
|
### Accessors #########################################################
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1;
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=pod
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 NAME
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
CSS::SAC::Selector - base class for SAC selectors
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
use CSS::SAC::Selector qw(:constants);
|
159
|
|
|
|
|
|
|
foo if $sel->is_type(SELECTOR_TYPE_CONSTANT);
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
SAC Selectors describe selectors that can be expressed in CSS such
|
164
|
|
|
|
|
|
|
as ElementSelector or SiblingSelector. This class provides everything
|
165
|
|
|
|
|
|
|
that is needed to implement simple selectors (methods, constants) as
|
166
|
|
|
|
|
|
|
well as what is needed by subclasses defining more complex selectors.
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
The constants are those defined in the SAC spec, with the leading SAC_
|
169
|
|
|
|
|
|
|
removed. What the constants map to is to be considered an opaque token
|
170
|
|
|
|
|
|
|
that can be tested for equality. If there is demand for it, I will add
|
171
|
|
|
|
|
|
|
a way to add new constants (for people wishing to define new condition
|
172
|
|
|
|
|
|
|
types).
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
I have also added the UNKNOWN_SELECTOR constant. It shouldn't occur
|
175
|
|
|
|
|
|
|
in normal processing but it's always useful to have such fallback
|
176
|
|
|
|
|
|
|
values.
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The Selector interface adds $sel->is_type($selector_type) to the
|
179
|
|
|
|
|
|
|
interface defined in the SAC spec. This allows for more flexible type
|
180
|
|
|
|
|
|
|
checking. The advantages are the same as those described for the same
|
181
|
|
|
|
|
|
|
extension in the CSS::SAC::Condition class.
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 CONSTANTS
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=over
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * UNKNOWN_SELECTOR
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * ANY_NODE_SELECTOR
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * CDATA_SECTION_NODE_SELECTOR
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * CHILD_SELECTOR
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * COMMENT_NODE_SELECTOR
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item * CONDITIONAL_SELECTOR
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * DESCENDANT_SELECTOR
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item * DIRECT_ADJACENT_SELECTOR
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item * ELEMENT_NODE_SELECTOR
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item * NEGATIVE_SELECTOR
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * PROCESSING_INSTRUCTION_NODE_SELECTOR
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item * PSEUDO_ELEMENT_SELECTOR
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * ROOT_NODE_SELECTOR
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * TEXT_NODE_SELECTOR
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=back
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 METHODS
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=over
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * CSS::SAC::Selector->new($type) or $sel->new($type)
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Creates a new selector. The $type must be one of the type constants.
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * $sel->SelectorType() or $sel->getSelectorType
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Returns the constant corresponding to the type of this selector.
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item * $sel->is_type($selector_type)
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Returns a boolean indicating whether this selector is of type
|
232
|
|
|
|
|
|
|
$selector_type (a selector constant).
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=back
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 AUTHOR
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Robin Berjon
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This module is licensed under the same terms as Perl itself.
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=cut
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|