| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | XML::Easy::Classify - classification of XML-related items | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | use XML::Easy::Classify qw( | ||||||||||||||||||||||||||||
| 8 | is_xml_name check_xml_name | ||||||||||||||||||||||||||||
| 9 | is_xml_encname check_xml_encname | ||||||||||||||||||||||||||||
| 10 | is_xml_chardata check_xml_chardata | ||||||||||||||||||||||||||||
| 11 | is_xml_attributes check_xml_attributes | ||||||||||||||||||||||||||||
| 12 | is_xml_content_object check_xml_content_object | ||||||||||||||||||||||||||||
| 13 | is_xml_content_twine check_xml_content_twine | ||||||||||||||||||||||||||||
| 14 | is_xml_content check_xml_content | ||||||||||||||||||||||||||||
| 15 | is_xml_element check_xml_element | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | if(is_xml_name($arg)) { ... | ||||||||||||||||||||||||||||
| 19 | check_xml_name($arg); | ||||||||||||||||||||||||||||
| 20 | if(is_xml_encname($arg)) { ... | ||||||||||||||||||||||||||||
| 21 | check_xml_encname($arg); | ||||||||||||||||||||||||||||
| 22 | if(is_xml_chardata($arg)) { ... | ||||||||||||||||||||||||||||
| 23 | check_xml_chardata($arg); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | if(is_xml_attributes($arg)) { ... | ||||||||||||||||||||||||||||
| 26 | check_xml_attributes($arg); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | if(is_xml_content_object($arg)) { ... | ||||||||||||||||||||||||||||
| 29 | check_xml_content_object($arg); | ||||||||||||||||||||||||||||
| 30 | if(is_xml_content_twine($arg)) { ... | ||||||||||||||||||||||||||||
| 31 | check_xml_content_twine($arg); | ||||||||||||||||||||||||||||
| 32 | if(is_xml_content($arg)) { ... | ||||||||||||||||||||||||||||
| 33 | check_xml_content($arg); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | if(is_xml_element($arg)) { ... | ||||||||||||||||||||||||||||
| 36 | check_xml_element($arg); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | This module provides various type-testing functions, relating to data | ||||||||||||||||||||||||||||
| 41 | types used in the L<XML::Easy> ensemble. These are mainly intended to be | ||||||||||||||||||||||||||||
| 42 | used to enforce validity of data being processed by XML-related functions. | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | There are two flavours of function in this module. Functions of the first | ||||||||||||||||||||||||||||
| 45 | flavour only provide type classification, to allow code to discriminate | ||||||||||||||||||||||||||||
| 46 | between argument types. Functions of the second flavour package up the | ||||||||||||||||||||||||||||
| 47 | most common type of type discrimination: checking that an argument is | ||||||||||||||||||||||||||||
| 48 | of an expected type. The functions come in matched pairs. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | package XML::Easy::Classify; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 15 | ▶ | { use 5.008; } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 15 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 15 | ▶ | use Params::Classify 0.000 qw(is_string is_ref is_strictly_blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | use XML::Easy::Syntax 0.000 | ||||||||||||||||||||||||||||
| 60 | 15 | ▶ | qw($xml10_char_rx $xml10_name_rx $xml10_encname_rx); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 15 | our $VERSION = "0.010"; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 15 | ▶ | use parent "Exporter"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 15 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 66 | is_xml_name check_xml_name | ||||||||||||||||||||||||||||
| 67 | is_xml_encname check_xml_encname | ||||||||||||||||||||||||||||
| 68 | is_xml_chardata check_xml_chardata | ||||||||||||||||||||||||||||
| 69 | is_xml_attributes check_xml_attributes | ||||||||||||||||||||||||||||
| 70 | is_xml_content_object check_xml_content_object | ||||||||||||||||||||||||||||
| 71 | is_xml_content_twine check_xml_content_twine | ||||||||||||||||||||||||||||
| 72 | is_xml_content_array | ||||||||||||||||||||||||||||
| 73 | is_xml_content check_xml_content | ||||||||||||||||||||||||||||
| 74 | is_xml_element check_xml_element | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub _throw_data_error($) { | ||||||||||||||||||||||||||||
| 78 | 32092 | ▶ | my($msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_throw_data_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | 32092 | die "invalid XML data: $msg\n"; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Each of these functions takes one scalar argument (I<ARG>) to be tested. | ||||||||||||||||||||||||||||
| 85 | Any scalar value is acceptable for the argument to be tested. Each C<is_> | ||||||||||||||||||||||||||||
| 86 | function returns a simple truth value result, which is true iff I<ARG> | ||||||||||||||||||||||||||||
| 87 | is of the type being checked for. Each C<check_> function will return | ||||||||||||||||||||||||||||
| 88 | normally if the argument is of the type being checked for, or will C<die> | ||||||||||||||||||||||||||||
| 89 | if it is not. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =over | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =item is_xml_name(ARG) | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =item check_xml_name(ARG) | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Check whether I<ARG> is a plain string satisfying the XML name syntax. | ||||||||||||||||||||||||||||
| 98 | (Such names are used to identify element types, attributes, entities, | ||||||||||||||||||||||||||||
| 99 | and other things in XML.) | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =cut | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub is_xml_name($) { | ||||||||||||||||||||||||||||
| 104 | 15 | ▶ | no warnings "utf8"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 105 | 18632 | ▶ | return is_string($_[0]) && $_[0] =~ /\A$xml10_name_rx\z/o; | ||||||||||||||||||||||||||
|
Subroutine
is_xml_name: called CC=2 SCAR=6.9
Pod
documented
Condition100%3/3
rand $_[0] && $_[0] =~ /\A$XML::Easy::Classify::xml10_name_rx\z/o
MC/DC100%2/2
rand $_[0] && $_[0] =~ /\A$XML::Easy::Classify::xml10_name_rx\z/o
rand $_[0]
$_[0] =~ /\A$XML::Easy::Classify::xml10_name_rx\z/o
Truth table100%3/3
A && B
A= rand $_[0]B= $_[0] =~ /\A$XML::Easy::Classify::xml10_name_rx\z/o
| |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | sub check_xml_name($) { | ||||||||||||||||||||||||||||
| 109 | 558 | ▶ | _throw_data_error("name isn't a string") unless is_string($_[0]); | ||||||||||||||||||||||||||
|
Subroutine
check_xml_name: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 15 | ▶ | no warnings "utf8"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 111 | 532 | ▶ | _throw_data_error("illegal name") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | unless $_[0] =~ /\A$xml10_name_rx\z/o; | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =item is_xml_encname(ARG) | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =item check_xml_encname(ARG) | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Check whether I<ARG> is a plain string satisfying the XML character | ||||||||||||||||||||||||||||
| 120 | encoding name syntax. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub is_xml_encname($) { | ||||||||||||||||||||||||||||
| 125 | 15 | ▶ | no warnings "utf8"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 126 | 578 | ▶ | return is_string($_[0]) && $_[0] =~ /\A$xml10_encname_rx\z/o; | ||||||||||||||||||||||||||
|
Subroutine
is_xml_encname: called CC=2 SCAR=6.9
Pod
documented
Condition100%3/3
rand $_[0] && $_[0] =~ /\A$XML::Easy::Classify::xml10_encname_rx\z/o
MC/DC100%2/2
rand $_[0] && $_[0] =~ /\A$XML::Easy::Classify::xml10_encname_rx\z/o
rand $_[0]
$_[0] =~ /\A$XML::Easy::Classify::xml10_encname_rx\z/o
Truth table100%3/3
A && B
A= rand $_[0]B= $_[0] =~ /\A$XML::Easy::Classify::xml10_encname_rx\z/o
| |||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | sub check_xml_encname($) { | ||||||||||||||||||||||||||||
| 130 | 578 | ▶ | _throw_data_error("encoding name isn't a string") | ||||||||||||||||||||||||||
|
Subroutine
check_xml_encname: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | unless is_string($_[0]); | ||||||||||||||||||||||||||||
| 132 | 15 | ▶ | no warnings "utf8"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 133 | 552 | ▶ | _throw_data_error("illegal encoding name") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | unless $_[0] =~ /\A$xml10_encname_rx\z/o; | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =item is_xml_chardata(ARG) | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =item check_xml_chardata(ARG) | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | Check whether I<ARG> is a plain string consisting of a sequence of | ||||||||||||||||||||||||||||
| 142 | characters that are acceptable to XML. Such a string is valid as data | ||||||||||||||||||||||||||||
| 143 | in an XML element (where it may be intermingled with subelements) or as | ||||||||||||||||||||||||||||
| 144 | the value of an element attribute. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | sub is_xml_chardata($) { | ||||||||||||||||||||||||||||
| 149 | 15 | ▶ | no warnings "utf8"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | 7236 | ▶ | return is_string($_[0]) && $_[0] =~ /\A$xml10_char_rx*\z/o; | ||||||||||||||||||||||||||
|
Subroutine
is_xml_chardata: called CC=2 SCAR=6.9
Pod
documented
Condition100%3/3
rand $_[0] && $_[0] =~ /\A$XML::Easy::Classify::xml10_char_rx*\z/o
MC/DC100%2/2
rand $_[0] && $_[0] =~ /\A$XML::Easy::Classify::xml10_char_rx*\z/o
rand $_[0]
$_[0] =~ /\A$XML::Easy::Classify::xml10_char_rx*\z/o
Truth table100%3/3
A && B
A= rand $_[0]B= $_[0] =~ /\A$XML::Easy::Classify::xml10_char_rx*\z/o
| |||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | sub check_xml_chardata($) { | ||||||||||||||||||||||||||||
| 154 | 705719 | ▶ | _throw_data_error("character data isn't a string") | ||||||||||||||||||||||||||
|
Subroutine
check_xml_chardata: called CC=3 SCAR=11.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | unless is_string($_[0]); | ||||||||||||||||||||||||||||
| 156 | 15 | ▶ | no warnings "utf8"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 157 | 704133 | ▶ | _throw_data_error("character data contains illegal character") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | unless $_[0] =~ /\A$xml10_char_rx*\z/o; | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =item is_xml_attributes(ARG) | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =item check_xml_attributes(ARG) | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | Check whether I<ARG> is a reference to a hash that is well-formed as | ||||||||||||||||||||||||||||
| 166 | an XML element attribute set. To be well-formed, each key in the hash | ||||||||||||||||||||||||||||
| 167 | must be an XML name string, and each value must be an XML character | ||||||||||||||||||||||||||||
| 168 | data string. | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | sub is_xml_attributes($) { | ||||||||||||||||||||||||||||
| 173 | 1186 | ▶ | return undef unless is_ref($_[0], "HASH"); | ||||||||||||||||||||||||||
|
Subroutine
is_xml_attributes: called CC=5 SCAR=16.1
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 1154 | my $attrs = $_[0]; | |||||||||||||||||||||||||||
| 175 | 1154 | foreach(keys %$attrs) { | |||||||||||||||||||||||||||
| 176 | return undef unless | ||||||||||||||||||||||||||||
| 177 | 1350 | ▶ | is_xml_name($_) && is_xml_chardata($attrs->{$_}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&is_xml_name($_) and &is_xml_chardata($attrs->{$_})
MC/DC100%2/2
&is_xml_name($_) and &is_xml_chardata($attrs->{$_})
&is_xml_name($_)
&is_xml_chardata($attrs->{$_})
Truth table100%3/3
A and B
A= &is_xml_name($_)B= &is_xml_chardata($attrs->{$_})
| |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | 444 | return 1; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | sub check_xml_attributes($) { | ||||||||||||||||||||||||||||
| 183 | 349018 | ▶ | _throw_data_error("attribute hash isn't a hash") | ||||||||||||||||||||||||||
|
Subroutine
check_xml_attributes: called CC=4 SCAR=13.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | unless is_ref($_[0], "HASH"); | ||||||||||||||||||||||||||||
| 185 | 348986 | foreach(sort keys %{$_[0]}) { | |||||||||||||||||||||||||||
| 186 | 15 | ▶ | no warnings "utf8"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 187 | 18888 | ▶ | _throw_data_error("illegal attribute name") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | unless /\A$xml10_name_rx\z/o; | ||||||||||||||||||||||||||||
| 189 | 9240 | check_xml_chardata($_[0]->{$_}); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =item is_xml_content_object(ARG) | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =item check_xml_content_object(ARG) | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | Check whether I<ARG> is a reference to an L<XML::Easy::Content> | ||||||||||||||||||||||||||||
| 198 | object, and thus represents a chunk of XML content. | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | sub is_xml_content_object($) { | ||||||||||||||||||||||||||||
| 203 | 668324 | ▶ | return is_strictly_blessed($_[0], "XML::Easy::Content"); | ||||||||||||||||||||||||||
|
Subroutine
is_xml_content_object: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | sub check_xml_content_object($) { | ||||||||||||||||||||||||||||
| 207 | 655686 | ▶ | _throw_data_error("content data isn't a content chunk") | ||||||||||||||||||||||||||
|
Subroutine
check_xml_content_object: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | unless &is_xml_content_object; | ||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =item is_xml_content_twine(ARG) | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =item check_xml_content_twine(ARG) | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | Check whether I<ARG> is a reference to a twine array | ||||||||||||||||||||||||||||
| 216 | (see L<XML::Easy::NodeBasics/Twine>), | ||||||||||||||||||||||||||||
| 217 | and thus represents a chunk of XML content. | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =cut | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | sub is_xml_element($); | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | sub is_xml_content_twine($) { | ||||||||||||||||||||||||||||
| 224 | 3838 | ▶ | return undef unless is_ref($_[0], "ARRAY"); | ||||||||||||||||||||||||||
|
Subroutine
is_xml_content_twine: called CC=6 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 3780 | my $twine = $_[0]; | |||||||||||||||||||||||||||
| 226 | 3780 | ▶ | return undef unless @$twine % 2 == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 3772 | for(my $i = $#$twine; ; $i--) { | |||||||||||||||||||||||||||
| 228 | 5712 | ▶ | return undef unless is_xml_chardata($twine->[$i]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 4116 | ▶ | last if $i-- == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 2004 | ▶ | return undef unless is_xml_element($twine->[$i]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | 2112 | return 1; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | sub check_xml_element($); | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | sub check_xml_content_twine($) { | ||||||||||||||||||||||||||||
| 238 | 353129 | ▶ | _throw_data_error("content array isn't an array") | ||||||||||||||||||||||||||
|
Subroutine
check_xml_content_twine: called CC=4 SCAR=13.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | unless is_ref($_[0], "ARRAY"); | ||||||||||||||||||||||||||||
| 240 | 353099 | my $twine = $_[0]; | |||||||||||||||||||||||||||
| 241 | 353099 | ▶ | _throw_data_error("content array has even length") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | unless @$twine % 2 == 1; | ||||||||||||||||||||||||||||
| 243 | 352923 | for(my $i = 0; ; $i++) { | |||||||||||||||||||||||||||
| 244 | 684441 | check_xml_chardata($twine->[$i]); | |||||||||||||||||||||||||||
| 245 | 672737 | ▶ | last if ++$i == @$twine; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 332926 | check_xml_element($twine->[$i]); | |||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | =item is_xml_content_array(ARG) | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | Deprecated alias for L</is_xml_content_twine>. | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =cut | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 15 | *is_xml_content_array = \&is_xml_content_twine; | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | =item is_xml_content(ARG) | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | =item check_xml_content(ARG) | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | Check whether I<ARG> is a reference to either an L<XML::Easy::Content> | ||||||||||||||||||||||||||||
| 263 | object or a twine array (see L<XML::Easy::NodeBasics/Twine>), | ||||||||||||||||||||||||||||
| 264 | and thus represents a chunk of XML content. | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | =cut | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | sub is_xml_content($) { | ||||||||||||||||||||||||||||
| 269 | 1920 | ▶ | return &is_xml_content_object || &is_xml_content_twine; | ||||||||||||||||||||||||||
|
Subroutine
is_xml_content: called CC=2 SCAR=6.9
Pod
documented
Condition100%3/3
&is_xml_content_object || &is_xml_content_twine
MC/DC100%2/2
&is_xml_content_object || &is_xml_content_twine
&is_xml_content_object
&is_xml_content_twine
Truth table100%3/3
A || B
A= &is_xml_content_objectB= &is_xml_content_twine
| |||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | sub check_xml_content($) { | ||||||||||||||||||||||||||||
| 273 | 1690 | ▶ | if(is_ref($_[0], "ARRAY")) { | ||||||||||||||||||||||||||
|
Subroutine
check_xml_content: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | 1660 | &check_xml_content_twine; | |||||||||||||||||||||||||||
| 275 | } else { | ||||||||||||||||||||||||||||
| 276 | 30 | &check_xml_content_object; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | =item is_xml_element(ARG) | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | =item check_xml_element(ARG) | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | Check whether I<ARG> is a reference to an L<XML::Easy::Element> | ||||||||||||||||||||||||||||
| 285 | object, and thus represents an XML element. | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =cut | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 348974 | ▶ | sub is_xml_element($) { is_strictly_blessed($_[0], "XML::Easy::Element") } | ||||||||||||||||||||||||||
|
Subroutine
is_xml_element: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | sub check_xml_element($) { | ||||||||||||||||||||||||||||
| 292 | 334114 | ▶ | _throw_data_error("element data isn't an element") | ||||||||||||||||||||||||||
|
Subroutine
check_xml_element: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | unless &is_xml_element; | ||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | =back | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | L<Params::Classify>, | ||||||||||||||||||||||||||||
| 301 | L<XML::Easy::NodeBasics> | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | Andrew Main (Zefram) <zefram@fysh.org> | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | Copyright (C) 2009, 2010, 2011, 2017 | ||||||||||||||||||||||||||||
| 310 | Andrew Main (Zefram) <zefram@fysh.org> | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | This module is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 315 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | =cut | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 15 | 1; | |||||||||||||||||||||||||||