| 1 | |||||||||||||
| 2 | ### | ||||||||||||
| 3 | # CSS::SAC::Selector::Sibling - SAC SiblingSelector | ||||||||||||
| 4 | # Robin Berjon <robin@knowscape.com> | ||||||||||||
| 5 | # 24/02/2001 | ||||||||||||
| 6 | ### | ||||||||||||
| 7 | |||||||||||||
| 8 | package CSS::SAC::Selector::Sibling; | ||||||||||||
| 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'
MC/DC0%0/1
$CSS::SAC::VERSION || '0.03'
$CSS::SAC::VERSION
Truth table50%1/2
A
A= $CSS::SAC::VERSION
| |||||||||||||
| 12 | |||||||||||||
| 13 | 2 | ▶ | use base qw(CSS::SAC::Selector); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | |||||||||||||
| 16 | #---------------------------------------------------------------------# | ||||||||||||
| 17 | # build the fields for an array based object | ||||||||||||
| 18 | #---------------------------------------------------------------------# | ||||||||||||
| 19 | 2 | ▶ | use Class::ArrayObjects extend => { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | class => 'CSS::SAC::Selector', | ||||||||||||
| 21 | with => [qw( | ||||||||||||
| 22 | _node_type_ | ||||||||||||
| 23 | _selector_ | ||||||||||||
| 24 | _sibling_selector_ | ||||||||||||
| 25 | )], | ||||||||||||
| 26 | 2 | }; | |||||||||||
| 27 | #---------------------------------------------------------------------# | ||||||||||||
| 28 | |||||||||||||
| 29 | |||||||||||||
| 30 | |||||||||||||
| 31 | ### Constants ######################################################### | ||||||||||||
| 32 | # # | ||||||||||||
| 33 | # # | ||||||||||||
| 34 | |||||||||||||
| 35 | sub ELEMENT_NODE () { 1 } | ||||||||||||
| 36 | sub ATTRIBUTE_NODE () { 2 } | ||||||||||||
| 37 | sub TEXT_NODE () { 3 } | ||||||||||||
| 38 | sub CDATA_SECTION_NODE () { 4 } | ||||||||||||
| 39 | sub ENTITY_REFERENCE_NODE () { 5 } | ||||||||||||
| 40 | sub ENTITY_NODE () { 6 } | ||||||||||||
| 41 | sub PROCESSING_INSTRUCTION_NODE () { 7 } | ||||||||||||
| 42 | sub COMMENT_NODE () { 8 } | ||||||||||||
| 43 | sub DOCUMENT_NODE () { 9 } | ||||||||||||
| 44 | sub DOCUMENT_TYPE_NODE () { 10 } | ||||||||||||
| 45 | sub DOCUMENT_FRAGMENT_NODE () { 11 } | ||||||||||||
| 46 | sub NOTATION_NODE () { 12 } | ||||||||||||
| 47 | sub ANY_NODE () { 13 } | ||||||||||||
| 48 | |||||||||||||
| 49 | |||||||||||||
| 50 | #---------------------------------------------------------------------# | ||||||||||||
| 51 | # import() | ||||||||||||
| 52 | # all import can do is export the constants | ||||||||||||
| 53 | #---------------------------------------------------------------------# | ||||||||||||
| 54 | 3 | ▶ | sub import { | ||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| |||||||||||||
| 55 | 3 | my $class = shift; | |||||||||||
| 56 | 3 | ▶ | my $tag = shift || ''; | ||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 57 | |||||||||||||
| 58 | # check that we have the right tag | ||||||||||||
| 59 | 3 | ▶ | return unless $tag eq ':constants'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | |||||||||||||
| 61 | # define some useful vars | ||||||||||||
| 62 | 3 | my $pkg = caller; | |||||||||||
| 63 | 3 | my @constants = qw( | |||||||||||
| 64 | ELEMENT_NODE | ||||||||||||
| 65 | ATTRIBUTE_NODE | ||||||||||||
| 66 | TEXT_NODE | ||||||||||||
| 67 | CDATA_SECTION_NODE | ||||||||||||
| 68 | ENTITY_REFERENCE_NODE | ||||||||||||
| 69 | ENTITY_NODE | ||||||||||||
| 70 | PROCESSING_INSTRUCTION_NODE | ||||||||||||
| 71 | COMMENT_NODE | ||||||||||||
| 72 | DOCUMENT_NODE | ||||||||||||
| 73 | DOCUMENT_TYPE_NODE | ||||||||||||
| 74 | DOCUMENT_FRAGMENT_NODE | ||||||||||||
| 75 | NOTATION_NODE | ||||||||||||
| 76 | ANY_NODE | ||||||||||||
| 77 | ); | ||||||||||||
| 78 | |||||||||||||
| 79 | # now lets create the constants in the caller's package | ||||||||||||
| 80 | 2 | ▶ | no strict 'refs'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 81 | 3 | for my $c (@constants) { | |||||||||||
| 82 | 39 | my $qname = "${pkg}::$c"; | |||||||||||
| 83 | 39 | *$qname = \&{$c}; | |||||||||||
| 84 | } | ||||||||||||
| 85 | } | ||||||||||||
| 86 | #---------------------------------------------------------------------# | ||||||||||||
| 87 | |||||||||||||
| 88 | |||||||||||||
| 89 | # # | ||||||||||||
| 90 | # # | ||||||||||||
| 91 | ### Constants ######################################################### | ||||||||||||
| 92 | |||||||||||||
| 93 | |||||||||||||
| 94 | ### Constructor ####################################################### | ||||||||||||
| 95 | # # | ||||||||||||
| 96 | # # | ||||||||||||
| 97 | |||||||||||||
| 98 | |||||||||||||
| 99 | #---------------------------------------------------------------------# | ||||||||||||
| 100 | # CSS::SAC::Selector::Sibling->new($type,$node_type,$sel,$sibling_sel) | ||||||||||||
| 101 | # creates a new sac SiblingSelector object | ||||||||||||
| 102 | #---------------------------------------------------------------------# | ||||||||||||
| 103 | 2 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||
| 104 | 2 | ▶ | my $class = ref($_[0])?ref(shift):shift; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | 2 | my $type = shift; | |||||||||||
| 106 | 2 | my $node_type = shift; | |||||||||||
| 107 | 2 | my $sel = shift; | |||||||||||
| 108 | 2 | my $sibling_sel = shift; | |||||||||||
| 109 | |||||||||||||
| 110 | # create a selector | ||||||||||||
| 111 | 2 | my $ssel = $class->SUPER::new($type); | |||||||||||
| 112 | |||||||||||||
| 113 | # add our fields | ||||||||||||
| 114 | 2 | ▶ | $ssel->[_node_type_] = $node_type || ANY_NODE; | ||||||||||
|
Condition50%1/2
$node_type || 13
MC/DC0%0/1
$node_type || 13
$node_type
Truth table50%1/2
A
A= $node_type
| |||||||||||||
| 115 | 2 | $ssel->[_selector_] = $sel; | |||||||||||
| 116 | 2 | $ssel->[_sibling_selector_] = $sibling_sel; | |||||||||||
| 117 | |||||||||||||
| 118 | 2 | return $ssel; | |||||||||||
| 119 | } | ||||||||||||
| 120 | #---------------------------------------------------------------------# | ||||||||||||
| 121 | |||||||||||||
| 122 | |||||||||||||
| 123 | # # | ||||||||||||
| 124 | # # | ||||||||||||
| 125 | ### Constructor ####################################################### | ||||||||||||
| 126 | |||||||||||||
| 127 | |||||||||||||
| 128 | |||||||||||||
| 129 | ### Accessors ######################################################### | ||||||||||||
| 130 | # # | ||||||||||||
| 131 | # # | ||||||||||||
| 132 | |||||||||||||
| 133 | 2 | *CSS::SAC::Selector::Sibling::getNodeType = \&NodeType; | |||||||||||
| 134 | 2 | *CSS::SAC::Selector::Sibling::getSelector = \&Selector; | |||||||||||
| 135 | 2 | *CSS::SAC::Selector::Sibling::getSiblingSelector = \&SiblingSelector; | |||||||||||
| 136 | |||||||||||||
| 137 | #---------------------------------------------------------------------# | ||||||||||||
| 138 | # my $node_type = $ssel->NodeType() | ||||||||||||
| 139 | # $ssel->NodeType($node_type) | ||||||||||||
| 140 | # get/set the node type to which we apply | ||||||||||||
| 141 | #---------------------------------------------------------------------# | ||||||||||||
| 142 | 0 | ▶ | sub NodeType { | ||||||||||
|
Subroutine
NodeType: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 143 | 0 | ▶ | (@_==2) ? $_[0]->[_node_type_] = $_[1] : | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 144 | $_[0]->[_node_type_]; | ||||||||||||
| 145 | } | ||||||||||||
| 146 | #---------------------------------------------------------------------# | ||||||||||||
| 147 | |||||||||||||
| 148 | |||||||||||||
| 149 | #---------------------------------------------------------------------# | ||||||||||||
| 150 | # my $sel = $ssel->Selector() | ||||||||||||
| 151 | # $ssel->Selector($sel) | ||||||||||||
| 152 | # get/set the selector | ||||||||||||
| 153 | #---------------------------------------------------------------------# | ||||||||||||
| 154 | 2 | ▶ | sub Selector { | ||||||||||
|
Subroutine
Selector: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||
| 155 | 2 | ▶ | (@_==2) ? $_[0]->[_selector_] = $_[1] : | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 156 | $_[0]->[_selector_]; | ||||||||||||
| 157 | } | ||||||||||||
| 158 | #---------------------------------------------------------------------# | ||||||||||||
| 159 | |||||||||||||
| 160 | |||||||||||||
| 161 | #---------------------------------------------------------------------# | ||||||||||||
| 162 | # my $o_ssel = $ssel->SiblingSelector() | ||||||||||||
| 163 | # $ssel->SiblingSelector($o_ssel) | ||||||||||||
| 164 | # get/set the sibling selector | ||||||||||||
| 165 | #---------------------------------------------------------------------# | ||||||||||||
| 166 | 2 | ▶ | sub SiblingSelector { | ||||||||||
|
Subroutine
SiblingSelector: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||
| 167 | 2 | ▶ | (@_==2) ? $_[0]->[_sibling_selector_] = $_[1] : | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 168 | $_[0]->[_sibling_selector_]; | ||||||||||||
| 169 | } | ||||||||||||
| 170 | #---------------------------------------------------------------------# | ||||||||||||
| 171 | |||||||||||||
| 172 | |||||||||||||
| 173 | # # | ||||||||||||
| 174 | # # | ||||||||||||
| 175 | ### Accessors ######################################################### | ||||||||||||
| 176 | |||||||||||||
| 177 | |||||||||||||
| 178 | |||||||||||||
| 179 | 2 | 1; | |||||||||||
| 180 | |||||||||||||
| 181 | =pod | ||||||||||||
| 182 | |||||||||||||
| 183 | =head1 NAME | ||||||||||||
| 184 | |||||||||||||
| 185 | CSS::SAC::Selector::Sibling - SAC SiblingSelector | ||||||||||||
| 186 | |||||||||||||
| 187 | =head1 SYNOPSIS | ||||||||||||
| 188 | |||||||||||||
| 189 | see CSS::SAC::Selector | ||||||||||||
| 190 | |||||||||||||
| 191 | =head1 DESCRIPTION | ||||||||||||
| 192 | |||||||||||||
| 193 | This is a subclass of CSS::SAC::Selector, look there for more | ||||||||||||
| 194 | documentation. This class adds the methods described below. | ||||||||||||
| 195 | |||||||||||||
| 196 | This subclass also defines the constants for the DOM nodes. It uses | ||||||||||||
| 197 | the same constants as the DOM, and adds the ANY_NODE constant which | ||||||||||||
| 198 | matches any node. | ||||||||||||
| 199 | |||||||||||||
| 200 | =head1 CONSTANTS | ||||||||||||
| 201 | |||||||||||||
| 202 | =over | ||||||||||||
| 203 | |||||||||||||
| 204 | =item * ELEMENT_NODE | ||||||||||||
| 205 | |||||||||||||
| 206 | =item * ATTRIBUTE_NODE | ||||||||||||
| 207 | |||||||||||||
| 208 | =item * TEXT_NODE | ||||||||||||
| 209 | |||||||||||||
| 210 | =item * CDATA_SECTION_NODE | ||||||||||||
| 211 | |||||||||||||
| 212 | =item * ENTITY_REFERENCE_NODE | ||||||||||||
| 213 | |||||||||||||
| 214 | =item * ENTITY_NODE | ||||||||||||
| 215 | |||||||||||||
| 216 | =item * PROCESSING_INSTRUCTION_NODE | ||||||||||||
| 217 | |||||||||||||
| 218 | =item * COMMENT_NODE | ||||||||||||
| 219 | |||||||||||||
| 220 | =item * DOCUMENT_NODE | ||||||||||||
| 221 | |||||||||||||
| 222 | =item * DOCUMENT_TYPE_NODE | ||||||||||||
| 223 | |||||||||||||
| 224 | =item * DOCUMENT_FRAGMENT_NODE | ||||||||||||
| 225 | |||||||||||||
| 226 | =item * NOTATION_NODE | ||||||||||||
| 227 | |||||||||||||
| 228 | =item * ANY_NODE | ||||||||||||
| 229 | |||||||||||||
| 230 | =back | ||||||||||||
| 231 | |||||||||||||
| 232 | =head1 METHODS | ||||||||||||
| 233 | |||||||||||||
| 234 | These also exist in spec style, simply prepend them with 'get'. | ||||||||||||
| 235 | |||||||||||||
| 236 | =over | ||||||||||||
| 237 | |||||||||||||
| 238 | =item * CSS::SAC::Selector::Sibling->new($type,$node_type,$sel,$sibling_sel) | ||||||||||||
| 239 | =item * $ssel->new($type,$node_type,$sel,$sibling_sel) | ||||||||||||
| 240 | |||||||||||||
| 241 | Creates a new sibling selector. | ||||||||||||
| 242 | |||||||||||||
| 243 | =item * $ssel->NodeType([$node_type]) | ||||||||||||
| 244 | |||||||||||||
| 245 | get/set the node type to which we apply | ||||||||||||
| 246 | |||||||||||||
| 247 | =item * $ssel->Selector([$sel]) | ||||||||||||
| 248 | |||||||||||||
| 249 | get/set the selector's sub selector | ||||||||||||
| 250 | |||||||||||||
| 251 | =item * $ssel->SiblingSelector([$sib_sel]) | ||||||||||||
| 252 | |||||||||||||
| 253 | get/set the selector's sibling selector | ||||||||||||
| 254 | |||||||||||||
| 255 | =back | ||||||||||||
| 256 | |||||||||||||
| 257 | =head1 AUTHOR | ||||||||||||
| 258 | |||||||||||||
| 259 | Robin Berjon <robin@knowscape.com> | ||||||||||||
| 260 | |||||||||||||
| 261 | This module is licensed under the same terms as Perl itself. | ||||||||||||
| 262 | |||||||||||||
| 263 | =cut | ||||||||||||