SAC/SelectorFactory.pm

filter: Statementstmt 80.5% 83 / 103 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 74.0% 20 / 27 Podpod 93.3% 14 / 15 totaltotal 79.3% 119 / 150 CC 2 SCAR 2.8
CC
2
Cov
79%
new
2.1
create_any_node_selector
2.0
create_cdata_section_selector
2.0
CRAP 1.3
« SAC/Selector/Simple.pm ↑ Summary SAC/ConditionFactory.pm »
1
2 ###
3 # CSS::SAC::SelectorFactory - the default SelectorFactory
4 # Robin Berjon <robin@knowscape.com>
5 # 24/02/2001
6 ###
7
8 package CSS::SAC::SelectorFactory;
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶$VERSION = $CSS::SAC::VERSION || '0.03';
Condition50%1/2
$CSS::SAC::VERSION || '0.03'
l!l
02
MC/DC0%0/1
$CSS::SAC::VERSION || '0.03'
$CSS::SAC::VERSION
Truth table50%1/2
A
A= $CSS::SAC::VERSION
Aresult
11
00
12
13 2 ▶use CSS::SAC::Selector qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use CSS::SAC::Selector::Descendant qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use CSS::SAC::Selector::Sibling qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use CSS::SAC::Selector::Simple qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use CSS::SAC::Selector::CharacterData qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use CSS::SAC::Selector::Conditional qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use CSS::SAC::Selector::Element qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use CSS::SAC::Selector::Negative qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use CSS::SAC::Selector::ProcessingInstruction qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
22
23 #---------------------------------------------------------------------#
24 # build the fields for an array based object
25 #---------------------------------------------------------------------#
26 2 ▶use Class::ArrayObjects define => { fields => [] };
Subroutine BEGIN: called CC=1 SCAR=0.0
27 #---------------------------------------------------------------------#
28
29
30
31 ### Constructor #######################################################
32 # #
33 # #
34
35
36 #---------------------------------------------------------------------#
37 # CSS::SAC::SelectorFactory->new
38 # creates a new sac selector factory
39 #---------------------------------------------------------------------#
40 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
41 2 ▶ my $class = ref($_[0])?ref(shift):shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 2 2
42 2 return bless [], $class;
43 }
44 #---------------------------------------------------------------------#
45
46
47 # #
48 # #
49 ### Constructor #######################################################
50
51
52
53 ### Factory Methods ###################################################
54 # #
55 # #
56
57
58 # defined aliases
59 2 *CSS::SAC::SelectorFactory::createAnyNodeSelector = \&create_any_node_selector;
60 2 *CSS::SAC::SelectorFactory::createCdataSectionSelector = \&create_cdata_section_selector;
61 2 *CSS::SAC::SelectorFactory::createChildSelector = \&create_child_selector;
62 2 *CSS::SAC::SelectorFactory::createCommentSelector = \&create_comment_selector;
63 2 *CSS::SAC::SelectorFactory::createConditionalSelector = \&create_conditional_selector;
64 2 *CSS::SAC::SelectorFactory::createDescendantSelector = \&create_descendant_selector;
65 2 *CSS::SAC::SelectorFactory::createDirectAdjacentSelector = \&create_direct_adjacent_selector;
66 2 *CSS::SAC::SelectorFactory::createElementSelector = \&create_element_selector;
67 2 *CSS::SAC::SelectorFactory::createNegativeSelector = \&create_negative_selector;
68 2 *CSS::SAC::SelectorFactory::createProcessingInstructionSelector = \&create_processing_instruction_selector;
69 2 *CSS::SAC::SelectorFactory::createPseudoElementSelector = \&create_pseudo_element_selector;
70 2 *CSS::SAC::SelectorFactory::createRootNodeSelector = \&create_root_node_selector;
71 2 *CSS::SAC::SelectorFactory::createTextNodeSelector = \&create_text_node_selector;
72
73
74 #---------------------------------------------------------------------#
75 # my $sel = $sf->create_any_node_selector
76 # creates a any-node selector
77 #---------------------------------------------------------------------#
78 0 ▶sub create_any_node_selector {
Subroutine create_any_node_selector: not called CC=1 SCAR=6.9
Pod documented
79 0 my $cf = shift;
80 0 return CSS::SAC::Selector::Simple->new(ANY_NODE_SELECTOR);
81 }
82 #---------------------------------------------------------------------#
83
84
85 #---------------------------------------------------------------------#
86 # my $sel = $sf->create_cdata_section_selector($data)
87 # creates a cdata selector
88 #---------------------------------------------------------------------#
89 0 ▶sub create_cdata_section_selector {
Subroutine create_cdata_section_selector: not called CC=1 SCAR=6.9
Pod documented
90 0 my $cf = shift;
91 0 my $data = shift;
92
93 0 return CSS::SAC::Selector::CharacterData->new(
94 CDATA_SECTION_NODE_SELECTOR,
95 $data
96 );
97 }
98 #---------------------------------------------------------------------#
99
100
101 #---------------------------------------------------------------------#
102 # my $sel = $sf->create_child_selector($parent_sel,$child_sel)
103 # creates a child selector
104 #---------------------------------------------------------------------#
105 1 ▶sub create_child_selector {
Subroutine create_child_selector: called CC=1 SCAR=0.0
Pod documented
106 1 my $cf = shift;
107 1 my $parent_sel = shift;
108 1 my $child_sel = shift;
109
110 1 return CSS::SAC::Selector::Descendant->new(
111 CHILD_SELECTOR,
112 $parent_sel,
113 $child_sel
114 );
115 }
116 #---------------------------------------------------------------------#
117
118
119 #---------------------------------------------------------------------#
120 # my $sel = $sf->create_comment_selector($data)
121 # creates a comment selector
122 #---------------------------------------------------------------------#
123 0 ▶sub create_comment_selector {
Subroutine create_comment_selector: not called CC=1 SCAR=6.9
Pod documented
124 0 my $cf = shift;
125 0 my $data = shift;
126
127 0 return CSS::SAC::Selector::CharacterData->new(
128 COMMENT_NODE_SELECTOR,
129 $data
130 );
131 }
132 #---------------------------------------------------------------------#
133
134
135 #---------------------------------------------------------------------#
136 # my $sel = $sf->create_conditional_selector($sel,$cond)
137 # creates a conditional selector
138 #---------------------------------------------------------------------#
139 34 ▶sub create_conditional_selector {
Subroutine create_conditional_selector: called CC=1 SCAR=0.0
Pod documented
140 34 my $cf = shift;
141 34 my $sel = shift;
142 34 my $cond = shift;
143
144 34 return CSS::SAC::Selector::Conditional->new(
145 CONDITIONAL_SELECTOR,
146 $sel,
147 $cond
148 );
149 }
150 #---------------------------------------------------------------------#
151
152
153 #---------------------------------------------------------------------#
154 # my $sel = $sf->create_descendant_selector($parent_sel,$desc_sel)
155 # creates a descendant selector
156 #---------------------------------------------------------------------#
157 1 ▶sub create_descendant_selector {
Subroutine create_descendant_selector: called CC=1 SCAR=0.0
Pod documented
158 1 my $cf = shift;
159 1 my $parent_sel = shift;
160 1 my $desc_sel = shift;
161
162 1 return CSS::SAC::Selector::Descendant->new(
163 DESCENDANT_SELECTOR,
164 $parent_sel,
165 $desc_sel
166 );
167 }
168 #---------------------------------------------------------------------#
169
170
171 #---------------------------------------------------------------------#
172 # my $sel = $sf->create_direct_adjacent_selector($node_type,$child,$adjacent)
173 # creates a direct adjacent selector
174 #---------------------------------------------------------------------#
175 1 ▶sub create_direct_adjacent_selector {
Subroutine create_direct_adjacent_selector: called CC=1 SCAR=0.0
Pod documented
176 1 my $cf = shift;
177 1 my $node_type = shift;
178 1 my $child = shift;
179 1 my $adjacent = shift;
180
181 1 return CSS::SAC::Selector::Sibling->new(
182 DIRECT_ADJACENT_SELECTOR,
183 $node_type,
184 $child,
185 $adjacent
186 );
187 }
188 #---------------------------------------------------------------------#
189
190
191 #---------------------------------------------------------------------#
192 # my $sel = $sf->create_element_selector($ns,$lname)
193 # creates a element selector
194 #---------------------------------------------------------------------#
195 48 ▶sub create_element_selector {
Subroutine create_element_selector: called CC=1 SCAR=0.0
Pod documented
196 48 my $cf = shift;
197 48 my $ns = shift;
198 48 my $lname = shift;
199
200 48 return CSS::SAC::Selector::Element->new(
201 ELEMENT_NODE_SELECTOR,
202 $ns,
203 $lname
204 );
205 }
206 #---------------------------------------------------------------------#
207
208
209 #---------------------------------------------------------------------#
210 # my $sel = $sf->create_negative_selector($sel)
211 # creates a negative selector
212 #---------------------------------------------------------------------#
213 0 ▶sub create_negative_selector {
Subroutine create_negative_selector: not called CC=1 SCAR=6.9
Pod documented
214 0 my $cf = shift;
215 0 my $sel = shift;
216
217 0 return CSS::SAC::Selector::Negative->new(
218 NEGATIVE_SELECTOR,
219 $sel
220 );
221 }
222 #---------------------------------------------------------------------#
223
224
225 #---------------------------------------------------------------------#
226 # my $sel = $sf->create_processing_instruction_selector($target,$data)
227 # creates a pi selector
228 #---------------------------------------------------------------------#
229 0 ▶sub create_processing_instruction_selector {
Subroutine create_processing_instruction_selector: not called CC=1 SCAR=6.9
Pod documented
230 0 my $cf = shift;
231 0 my $target = shift;
232 0 my $data = shift;
233
234 0 return CSS::SAC::Selector::ProcessingInstruction->new(
235 PROCESSING_INSTRUCTION_NODE_SELECTOR,
236 $target,
237 $data
238 );
239 }
240 #---------------------------------------------------------------------#
241
242
243 #---------------------------------------------------------------------#
244 # my $sel = $sf->create_pseudo_element_selector($ns,$lname)
245 # creates a pseudo-e selector
246 #---------------------------------------------------------------------#
247 2 ▶sub create_pseudo_element_selector {
Subroutine create_pseudo_element_selector: called CC=1 SCAR=0.0
Pod documented
248 2 my $cf = shift;
249 2 my $ns = shift;
250 2 my $lname = shift;
251
252 2 return CSS::SAC::Selector::Element->new(
253 PSEUDO_ELEMENT_SELECTOR,
254 $ns,
255 $lname
256 );
257 }
258 #---------------------------------------------------------------------#
259
260
261 #---------------------------------------------------------------------#
262 # my $sel = $sf->create_root_node_selector
263 # creates a root selector
264 #---------------------------------------------------------------------#
265 0 ▶sub create_root_node_selector {
Subroutine create_root_node_selector: not called CC=1 SCAR=6.9
Pod documented
266 0 my $cf = shift;
267 0 return CSS::SAC::Selector::Simple->new(ROOT_NODE_SELECTOR);
268 }
269 #---------------------------------------------------------------------#
270
271
272 #---------------------------------------------------------------------#
273 # my $sel = $sf->create_text_node_selector($data)
274 # creates a text selector
275 #---------------------------------------------------------------------#
276 0 ▶sub create_text_node_selector {
Subroutine create_text_node_selector: not called CC=1 SCAR=6.9
Pod documented
277 0 my $cf = shift;
278 0 my $data = shift;
279
280 0 return CSS::SAC::Selector::CharacterData->new(
281 TEXT_NODE_SELECTOR,
282 $data
283 );
284 }
285 #---------------------------------------------------------------------#
286
287
288 # #
289 # #
290 ### Factory Methods ###################################################
291
292
293
294
295 ### EXPERIMENTAL Factory Methods ######################################
296 # #
297 # #
298
299
300 #---------------------------------------------------------------------#
301 # my $sel = $sf->create_indirect_adjacent_selector($node_type,$child,$adjacent)
302 # creates an indirect adjacent selector
303 #---------------------------------------------------------------------#
304 1 ▶sub create_indirect_adjacent_selector {
Subroutine create_indirect_adjacent_selector: called CC=1 SCAR=0.0
Pod undocumented
305 1 my $cf = shift;
306 1 my $node_type = shift;
307 1 my $child = shift;
308 1 my $adjacent = shift;
309
310 1 return CSS::SAC::Selector::Sibling->new(
311 INDIRECT_ADJACENT_SELECTOR,
312 $node_type,
313 $child,
314 $adjacent
315 );
316 }
317 #---------------------------------------------------------------------#
318
319
320 # #
321 # #
322 ### EXPERIMENTAL Factory Methods ######################################
323
324 2 1;
325
326 =pod
327
328 =head1 NAME
329
330 CSS::SAC::SelectorFactory - the default SelectorFactory
331
332 =head1 SYNOPSIS
333
334 fill this in later...
335
336 =head1 DESCRIPTION
337
338 This is the default SelectorFactory for CSS::SAC. It creates
339 selectors of all types defined in SAC. You may wish to subclass or
340 replace the default SelectorFactory in order to get your own
341 selector objects.
342
343 I plan on adding more flexibility to this factory so that one could
344 tell it the classes to use for various selectors, that would avoid
345 enforcing subclassing/recoding for people that only want to replace
346 a family of factory methods.
347
348 I know that some of the method names are quite lengthy, but given the
349 great number of possible selectors it helps to have descriptive
350 names.
351
352 =head1 METHODS
353
354 All the C<create*> methods have a spec-style equivalent. Just remove
355 the _ and capitalize the next letter.
356
357 =over 4
358
359 =item * CSS::SAC::SelectorFactory->new or $cf->new
360
361 Creates a new condition factory object.
362
363 =item * $sf->create_any_node_selector
364
365 creates a any-node selector
366
367 =item * $sf->create_cdata_section_selector($data)
368
369 creates a cdata selector
370
371 =item * $sf->create_child_selector($parent_sel,$child_sel)
372
373 creates a child selector
374
375 =item * $sf->create_comment_selector($data)
376
377 creates a comment selector
378
379 =item * $sf->create_conditional_selector($sel,$cond)
380
381 creates a conditional selector
382
383 =item * $sf->create_descendant_selector($parent_sel,$desc_sel)
384
385 creates a descendant selector
386
387 =item * $sf->create_direct_adjacent_selector($node_type,$child,$adjacent)
388
389 creates a direct adjacent selector
390
391 =item * $sf->create_element_selector($ns,$lname)
392
393 creates a element selector
394
395 =item * $sf->create_negative_selector($sel)
396
397 creates a negative selector
398
399 =item * $sf->create_processing_instruction_selector($target,$data)
400
401 creates a pi selector
402
403 =item * $sf->create_pseudo_element_selector($ns,$lname)
404
405 creates a pseudo-e selector
406
407 =item * $sf->create_root_node_selector
408
409 creates a root selector
410
411 =item * $sf->create_text_node_selector($data)
412
413 creates a text selector
414
415 =back
416
417 =head1 AUTHOR
418
419 Robin Berjon <robin@knowscape.com>
420
421 This module is licensed under the same terms as Perl itself.
422
423 =cut
424
425
« SAC/Selector/Simple.pm ↑ Summary SAC/ConditionFactory.pm »