SAC/ConditionFactory.pm

filter: Statementstmt 88.8% 111 / 125 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 86.6% 26 / 30 Podpod 75.0% 15 / 20 totaltotal 85.5% 154 / 180 CC 2 SCAR 1.8
CC
2
Cov
88%
new
2.1
create_only_child_condition
2.0
create_only_type_condition
2.0
CRAP 1.2
« SAC/SelectorFactory.pm ↑ Summary
1
2 ###
3 # CSS::SAC::ConditionFactory - the default ConditionFactory
4 # Robin Berjon <robin@knowscape.com>
5 # 24/02/2001
6 ###
7
8 package CSS::SAC::ConditionFactory;
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::Condition qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use CSS::SAC::Condition::Attribute qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use CSS::SAC::Condition::Combinator qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use CSS::SAC::Condition::Content qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use CSS::SAC::Condition::Lang qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use CSS::SAC::Condition::Negative qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use CSS::SAC::Condition::Positional qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
20
21 #---------------------------------------------------------------------#
22 # build the fields for an array based object
23 #---------------------------------------------------------------------#
24 2 ▶use Class::ArrayObjects define => { fields => [] };
Subroutine BEGIN: called CC=1 SCAR=0.0
25 #---------------------------------------------------------------------#
26
27
28 ### Constructor #######################################################
29 # #
30 # #
31
32
33 #---------------------------------------------------------------------#
34 # CSS::SAC::ConditionFactory->new
35 # creates a new sac condition factory
36 #---------------------------------------------------------------------#
37 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
38 2 ▶ my $class = ref($_[0])?ref(shift):shift;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 2 2
39 2 return bless [], $class;
40 }
41 #---------------------------------------------------------------------#
42
43
44 # #
45 # #
46 ### Constructor #######################################################
47
48
49
50 ### Factory Methods ###################################################
51 # #
52 # #
53
54
55 # defined aliases
56 2 *CSS::SAC::ConditionFactory::createAndCondition = \&create_and_condition;
57 2 *CSS::SAC::ConditionFactory::createAttributeCondition = \&create_attribute_condition;
58 2 *CSS::SAC::ConditionFactory::createBeginHyphenAttributeCondition = \&create_begin_hyphen_attribute_condition;
59 2 *CSS::SAC::ConditionFactory::createClassCondition = \&create_class_condition;
60 2 *CSS::SAC::ConditionFactory::createContentCondition = \&create_content_condition;
61 2 *CSS::SAC::ConditionFactory::createIdCondition = \&create_id_condition;
62 2 *CSS::SAC::ConditionFactory::createLangCondition = \&create_lang_condition;
63 2 *CSS::SAC::ConditionFactory::createNegativeCondition = \&create_negative_condition;
64 2 *CSS::SAC::ConditionFactory::createOneOfAttributeCondition = \&create_one_of_attribute_condition;
65 2 *CSS::SAC::ConditionFactory::createOnlyChildCondition = \&create_only_child_condition;
66 2 *CSS::SAC::ConditionFactory::createOnlyTypeCondition = \&create_only_type_condition;
67 2 *CSS::SAC::ConditionFactory::createOrCondition = \&create_or_condition;
68 2 *CSS::SAC::ConditionFactory::createPositionalCondition = \&create_positional_condition;
69 2 *CSS::SAC::ConditionFactory::createPseudoClassCondition = \&create_pseudo_class_condition;
70
71
72 #---------------------------------------------------------------------#
73 # my $cond = $cf->create_and_condition($first,$second)
74 # creates a combinator condition of type and
75 #---------------------------------------------------------------------#
76 2 ▶sub create_and_condition {
Subroutine create_and_condition: called CC=1 SCAR=0.0
Pod documented
77 2 my $cf = shift;
78 2 my $first = shift;
79 2 my $second = shift;
80
81 2 return CSS::SAC::Condition::Combinator->new(
82 AND_CONDITION,
83 $first,
84 $second,
85 );
86 }
87 #---------------------------------------------------------------------#
88
89
90 #---------------------------------------------------------------------#
91 # my $cond = $cf->create_attribute_condition($lname,$ns,$specified,$value)
92 # creates an attr condition
93 #---------------------------------------------------------------------#
94 5 ▶sub create_attribute_condition {
Subroutine create_attribute_condition: called CC=1 SCAR=0.0
Pod documented
95 5 my $cf = shift;
96 5 my $lname = shift;
97 5 my $ns = shift;
98 5 my $specified = shift;
99 5 my $value = shift;
100
101 5 return CSS::SAC::Condition::Attribute->new(
102 ATTRIBUTE_CONDITION,
103 $lname,
104 $ns,
105 $specified,
106 $value,
107 );
108 }
109 #---------------------------------------------------------------------#
110
111
112 #---------------------------------------------------------------------#
113 # my $cond = $cf->create_begin_hyphen_attribute_condition($lname,$ns,$specified,$value)
114 # creates a attr condition of type bh
115 #---------------------------------------------------------------------#
116 1 ▶sub create_begin_hyphen_attribute_condition {
Subroutine create_begin_hyphen_attribute_condition: called CC=1 SCAR=0.0
Pod documented
117 1 my $cf = shift;
118 1 my $lname = shift;
119 1 my $ns = shift;
120 1 my $specified = shift;
121 1 my $value = shift;
122
123 1 return CSS::SAC::Condition::Attribute->new(
124 BEGIN_HYPHEN_ATTRIBUTE_CONDITION,
125 $lname,
126 $ns,
127 $specified,
128 $value,
129 );
130 }
131 #---------------------------------------------------------------------#
132
133
134 #---------------------------------------------------------------------#
135 # my $cond = $cf->create_class_condition($ns,$value)
136 # creates a attr condition of type class
137 #---------------------------------------------------------------------#
138 2 ▶sub create_class_condition {
Subroutine create_class_condition: called CC=1 SCAR=0.0
Pod documented
139 2 my $cf = shift;
140 2 my $ns = shift;
141 2 my $value = shift;
142
143 2 return CSS::SAC::Condition::Attribute->new(
144 CLASS_CONDITION,
145 undef,
146 $ns,
147 0,
148 $value,
149 );
150 }
151 #---------------------------------------------------------------------#
152
153
154 #---------------------------------------------------------------------#
155 # my $cond = $cf->create_content_condition($data)
156 # creates a content condition
157 #---------------------------------------------------------------------#
158 1 ▶sub create_content_condition {
Subroutine create_content_condition: called CC=1 SCAR=0.0
Pod documented
159 1 my $cf = shift;
160 1 my $data = shift;
161
162 1 return CSS::SAC::Condition::Content->new(
163 CONTENT_CONDITION,
164 $data,
165 );
166 }
167 #---------------------------------------------------------------------#
168
169
170 #---------------------------------------------------------------------#
171 # my $cond = $cf->create_id_condition($value)
172 # creates a attr condition of type id
173 #---------------------------------------------------------------------#
174 2 ▶sub create_id_condition {
Subroutine create_id_condition: called CC=1 SCAR=0.0
Pod documented
175 2 my $cf = shift;
176 2 my $value = shift;
177
178 2 return CSS::SAC::Condition::Attribute->new(
179 ID_CONDITION,
180 undef,
181 undef,
182 0,
183 $value,
184 );
185 }
186 #---------------------------------------------------------------------#
187
188
189 #---------------------------------------------------------------------#
190 # my $cond = $cf->create_lang_condition($lang)
191 # creates a lang condition
192 #---------------------------------------------------------------------#
193 1 ▶sub create_lang_condition {
Subroutine create_lang_condition: called CC=1 SCAR=0.0
Pod documented
194 1 my $cf = shift;
195 1 my $lang = shift;
196
197 1 return CSS::SAC::Condition::Lang->new(
198 LANG_CONDITION,
199 $lang,
200 );
201 }
202 #---------------------------------------------------------------------#
203
204
205 #---------------------------------------------------------------------#
206 # my $cond = $cf->create_negative_condition($cond)
207 # creates a negative condition
208 #---------------------------------------------------------------------#
209 2 ▶sub create_negative_condition {
Subroutine create_negative_condition: called CC=1 SCAR=0.0
Pod documented
210 2 my $cf = shift;
211 2 my $cond = shift;
212
213 2 return CSS::SAC::Condition::Negative->new(
214 NEGATIVE_CONDITION,
215 $cond,
216 );
217 }
218 #---------------------------------------------------------------------#
219
220
221 #---------------------------------------------------------------------#
222 # my $cond = $cf->create_one_of_attribute_condition($lname,$ns,$specified,$value)
223 # creates a attr condition of type id
224 #---------------------------------------------------------------------#
225 1 ▶sub create_one_of_attribute_condition {
Subroutine create_one_of_attribute_condition: called CC=1 SCAR=0.0
Pod documented
226 1 my $cf = shift;
227 1 my $lname = shift;
228 1 my $ns = shift;
229 1 my $specified = shift;
230 1 my $value = shift;
231
232 1 return CSS::SAC::Condition::Attribute->new(
233 ONE_OF_ATTRIBUTE_CONDITION,
234 $lname,
235 $ns,
236 $specified,
237 $value,
238 );
239 }
240 #---------------------------------------------------------------------#
241
242
243 #---------------------------------------------------------------------#
244 # my $cond = $cf->create_only_child_condition()
245 # creates a only-child condition
246 #---------------------------------------------------------------------#
247 0 ▶sub create_only_child_condition {
Subroutine create_only_child_condition: not called CC=1 SCAR=6.9
Pod documented
248 0 my $cf = shift;
249 0 return CSS::SAC::Condition->new(ONLY_CHILD_CONDITION);
250 }
251 #---------------------------------------------------------------------#
252
253
254 #---------------------------------------------------------------------#
255 # my $cond = $cf->create_only_type_condition()
256 # creates a only-type condition
257 #---------------------------------------------------------------------#
258 0 ▶sub create_only_type_condition {
Subroutine create_only_type_condition: not called CC=1 SCAR=6.9
Pod documented
259 0 my $cf = shift;
260 0 return CSS::SAC::Condition->new(ONLY_TYPE_CONDITION);
261 }
262 #---------------------------------------------------------------------#
263
264
265 #---------------------------------------------------------------------#
266 # my $cond = $cf->create_or_condition($first,$second)
267 # creates a combinator condition of type or
268 #---------------------------------------------------------------------#
269 0 ▶sub create_or_condition {
Subroutine create_or_condition: not called CC=1 SCAR=6.9
Pod documented
270 0 my $cf = shift;
271 0 my $first = shift;
272 0 my $second = shift;
273
274 0 return CSS::SAC::Condition::Combinator->new(
275 OR_CONDITION,
276 $first,
277 $second,
278 );
279 }
280 #---------------------------------------------------------------------#
281
282
283 #---------------------------------------------------------------------#
284 # my $cond = $cf->create_positional_condition($position,$type_node,$same_type)
285 # creates a positional condition
286 #---------------------------------------------------------------------#
287 14 ▶sub create_positional_condition {
Subroutine create_positional_condition: called CC=1 SCAR=0.0
Pod documented
288 14 my $cf = shift;
289 14 my $position = shift;
290 14 my $type_node = shift;
291 14 my $same_type = shift;
292
293 14 return CSS::SAC::Condition::Positional->new(
294 POSITIONAL_CONDITION,
295 $position,
296 $type_node,
297 $same_type,
298 );
299 }
300 #---------------------------------------------------------------------#
301
302
303 #---------------------------------------------------------------------#
304 # my $cond = $cf->create_pseudo_class_condition($ns,$value)
305 # creates a attr condition of type pseudo class
306 #---------------------------------------------------------------------#
307 2 ▶sub create_pseudo_class_condition {
Subroutine create_pseudo_class_condition: called CC=1 SCAR=0.0
Pod documented
308 2 my $cf = shift;
309 2 my $ns = shift;
310 2 my $value = shift;
311
312 2 return CSS::SAC::Condition::Attribute->new(
313 PSEUDO_CLASS_CONDITION,
314 undef,
315 $ns,
316 0,
317 $value,
318 );
319 }
320 #---------------------------------------------------------------------#
321
322
323 # #
324 # #
325 ### Factory Methods ###################################################
326
327
328
329 ### EXPERIMENTAL Factory Methods ######################################
330 # #
331 # #
332
333
334 ### IMPORTANT NOTE ####################################################
335 # #
336 # These factory methods are considered experiemental. They will #
337 # remain undocumented until further notice. CSS::SAC uses them when #
338 # it meets the corresponding tokens, but they should not be relied on #
339 # for most uses unless you know what you are doing. These methods are #
340 # just as stable as the others, but given that I have implemented #
341 # them on my own without consulting with the other SAC implementors #
342 # (in fact, I tried to consult but they didn't appear to be #
343 # interested at that moment in time) they are subject to change. #
344 # #
345 #######################################################################
346
347
348 #---------------------------------------------------------------------#
349 # my $cond = $cf->create_starts_with_attribute_condition($lname,$ns,$specified,$value)
350 # creates a attr condition of type sw
351 #---------------------------------------------------------------------#
352 1 ▶sub create_starts_with_attribute_condition {
Subroutine create_starts_with_attribute_condition: called CC=1 SCAR=0.0
Pod undocumented
353 1 my $cf = shift;
354 1 my $lname = shift;
355 1 my $ns = shift;
356 1 my $specified = shift;
357 1 my $value = shift;
358
359 1 return CSS::SAC::Condition::Attribute->new(
360 STARTS_WITH_ATTRIBUTE_CONDITION,
361 $lname,
362 $ns,
363 $specified,
364 $value,
365 );
366 }
367 #---------------------------------------------------------------------#
368
369
370 #---------------------------------------------------------------------#
371 # my $cond = $cf->create_ends_with_attribute_condition($lname,$ns,$specified,$value)
372 # creates a attr condition of type ew
373 #---------------------------------------------------------------------#
374 1 ▶sub create_ends_with_attribute_condition {
Subroutine create_ends_with_attribute_condition: called CC=1 SCAR=0.0
Pod undocumented
375 1 my $cf = shift;
376 1 my $lname = shift;
377 1 my $ns = shift;
378 1 my $specified = shift;
379 1 my $value = shift;
380
381 1 return CSS::SAC::Condition::Attribute->new(
382 ENDS_WITH_ATTRIBUTE_CONDITION,
383 $lname,
384 $ns,
385 $specified,
386 $value,
387 );
388 }
389 #---------------------------------------------------------------------#
390
391
392 #---------------------------------------------------------------------#
393 # my $cond = $cf->create_contains_attribute_condition($lname,$ns,$specified,$value)
394 # creates a attr condition of type sw
395 #---------------------------------------------------------------------#
396 0 ▶sub create_contains_attribute_condition {
Subroutine create_contains_attribute_condition: not called CC=1 SCAR=6.9
Pod undocumented
397 0 my $cf = shift;
398 0 my $lname = shift;
399 0 my $ns = shift;
400 0 my $specified = shift;
401 0 my $value = shift;
402
403 0 return CSS::SAC::Condition::Attribute->new(
404 CONTAINS_ATTRIBUTE_CONDITION,
405 $lname,
406 $ns,
407 $specified,
408 $value,
409 );
410 }
411 #---------------------------------------------------------------------#
412
413
414 #---------------------------------------------------------------------#
415 # my $cond = $cf->create_is_root_condition()
416 # creates a root condition
417 #---------------------------------------------------------------------#
418 2 ▶sub create_is_root_condition {
Subroutine create_is_root_condition: called CC=1 SCAR=0.0
Pod undocumented
419 2 my $cf = shift;
420 2 return CSS::SAC::Condition->new(IS_ROOT_CONDITION);
421 }
422 #---------------------------------------------------------------------#
423
424
425 #---------------------------------------------------------------------#
426 # my $cond = $cf->create_is_empty_condition()
427 # creates a empty condition
428 #---------------------------------------------------------------------#
429 1 ▶sub create_is_empty_condition {
Subroutine create_is_empty_condition: called CC=1 SCAR=0.0
Pod undocumented
430 1 my $cf = shift;
431 1 return CSS::SAC::Condition->new(IS_EMPTY_CONDITION);
432 }
433 #---------------------------------------------------------------------#
434
435
436
437
438 # #
439 # #
440 ### EXPERIMENTAL Factory Methods ######################################
441
442
443 2 1;
444
445 =pod
446
447 =head1 NAME
448
449 CSS::SAC::ConditionFactory - the default ConditionFactory
450
451 =head1 SYNOPSIS
452
453 my $cf = CSS::SAC::ConditionFactory->new;
454 my $cond1 = $cf->create_foo_condition;
455 my $cond2 = $cf->create_bar_condition;
456
457 =head1 DESCRIPTION
458
459 This is the default ConditionFactory for CSS::SAC. It creates
460 conditions of all types defined in SAC. You may wish to subclass or
461 replace the default ConditionFactory in order to get your own
462 condition objects.
463
464 I plan on adding more flexibility to this factory so that one could
465 tell it the classes to use for various conditions, that would avoid
466 enforcing subclassing/recoding for people that only want to replace
467 a family of factory methods.
468
469 I know that some of the method names are quite lengthy, but given the
470 great number of possible conditions it helps to have descriptive
471 names.
472
473 =head1 METHODS
474
475 These define the interface that must be adhered to by
476 ConditionFactories. The Java names (given in parens) work too, though
477 the Perl ones are recommended.
478
479 =over 4
480
481 =item * CSS::SAC::ConditionFactory->new or $cf->new
482
483 Creates a new condition factory object.
484
485 =item * $cf->create_and_condition($first,$second) (createAndCondition)
486
487 creates a combinator condition of type and
488
489 =item * $cf->create_attribute_condition($lname,$ns,$specified,$value) (createAttributeCondition)
490
491 creates an attr condition
492
493 =item * $cf->create_begin_hyphen_attribute_condition($lname,$ns,$specified,$value) (createBeginHyphenAttributeCondition)
494
495 creates a attr condition of type bh
496
497 =item * $cf->create_class_condition($ns,$value) (createClassCondition)
498
499 creates a attr condition of type class
500
501 =item * $cf->create_content_condition($data) (createContentCondition)
502
503 creates a content condition
504
505 =item * $cf->create_id_condition($value) (createIdCondition)
506
507 creates a attr condition of type id
508
509 =item * $cf->create_lang_condition($lang) (createLangCondition)
510
511 creates a lang condition
512
513 =item * $cf->create_negative_condition($cond) (createNegativeCondition)
514
515 creates a negative condition
516
517 =item * $cf->create_one_of_attribute_condition($lname,$ns,$specified,$value) (createOneOfAttributeCondition)
518
519 creates a attr condition of type id
520
521 =item * $cf->create_only_child_condition() (createOnlyChildCondition)
522
523 creates a only-child condition
524
525 =item * $cf->create_only_type_condition() (createOnlyTypeCondition)
526
527 creates a only-type condition
528
529 =item * $cf->create_or_condition($first,$second) (createOrCondition)
530
531 creates a combinator condition of type or
532
533 =item * $cf->create_positional_condition($position,$type_node,$same_type) (createPositionalCondition)
534
535 creates a positional condition
536
537 =item * $cf->create_pseudo_class_condition($ns,$value) (createPseudoClassCondition)
538
539 creates a attr condition of type pseudo class
540
541 =back
542
543 =head1 EXPERIMENTAL
544
545 There's some experimental stuff in here to provide for some new CSS
546 constructs. It is and will remain undocumented until there is
547 consensus on the handling of these new tokens. If you badly need to
548 use one of the new CSS3 conditions that isn't documented, look at the
549 source for features tagged EXPERIMENTAL.
550
551 =head1 AUTHOR
552
553 Robin Berjon <robin@knowscape.com>
554
555 This module is licensed under the same terms as Perl itself.
556
557 =cut
558
559
« SAC/SelectorFactory.pm ↑ Summary