| 1 | ## -*- cperl -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package XML::DT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use 5.008006; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use LWP::Simple; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use XML::DTDParser "ParseDTDFile"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use XML::LibXML ':libxml'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | our $PARSER = 'XML::LibXML'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use parent 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | use vars qw($c $u %v $q @dtcontext %dtcontextcount @dtatributes | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | @dtattributes ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | our @EXPORT = qw(&dt &dtstring &dturl &inctxt &ctxt &mkdtskel &inpath | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | &mkdtskel_fromDTD &mkdtdskel &tohtml &toxml &MMAPON $c %v $q $u | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | &xmltree &pathdturl @dtcontext %dtcontextcount | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | @dtatributes @dtattributes &pathdt &pathdtstring | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | &father &gfather &ggfather &root); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | our $VERSION = '0.68'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | XML::DT - a package for down translation of XML files | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | use XML::DT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | %xml=( 'music' => sub{"Music from: $c\n"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'lyrics' => sub{"Lyrics from: $v{name}\n"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'title' => sub{ uc($c) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | '-userdata => { something => 'I like' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | '-default' => sub{"$q:$c"} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | print dt($filename,%xml); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | =head1 ABSTRACT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | This module is a XML down processor. It maps tag (element) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | names to functions to process that element and respective | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | contents. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | This module processes XML files with an approach similar to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | OMNIMARK. As XML parser it uses XML::LibXML module in an independent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | way. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | You can parse HTML files as if they were XML files. For this, you must | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | supply an extra option to the hash: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | %hander = ( -html => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | You can also ask the parser to recover from XML errors: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | %hander = ( -recover => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | =head1 Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | =head2 dt | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | Down translation function C<dt> receives a filename and a set of | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | expressions (functions) defining the processing and associated values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | for each element. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | =head2 dtstring | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | C<dtstring> works in a similar way with C<dt> but takes input from a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | string instead of a file. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | =head2 dturl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | C<dturl> works in a similar way with C<dt> but takes input from an | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | Internet url instead of a file. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | =head2 pathdt | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | The C<pathdt> function is a C<dt> function which can handle a subset | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | of XPath on handler keys. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | %handler = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | "article/title" => sub{ toxml("h1",{},$c) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | "section/title" => sub{ toxml("h2",{},$c) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | "title" => sub{ $c }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | "//image[@type='jpg']" => sub{ "JPEG: <img src=\"$c\">" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | "//image[@type='bmp']" => sub{ "BMP: sorry, no bitmaps on the web" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | pathdt($filename, %handler); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | Here are some examples of valid XPath expressions under XML::DT: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | /aaa | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | /aaa/bbb | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | //ccc - ccc somewhere (same as "ccc") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | /*/aaa/* | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | //* - same as "-default" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | /aaa[@id] - aaa with an attribute id | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | /*[@*] - root with an attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | /aaa[not(@name)] - aaa with no attribute "name" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | //bbb[@name='foo'] - ... attribute "name" = "foo" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | /ccc[normalize-space(@name)='bbb'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | //*[name()='bbb'] - complex way of saying "//bbb" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | //*[starts-with(name(),'aa')] - an element named "aa.*" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | //*[contains(name(),'c')] - an element ".*c.*" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | //aaa[string-length(name())=4] "...." | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | //aaa[string-length(name())<4] ".{1,4}" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | //aaa[string-length(name())>5] ".{5,}" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | Note that not all XPath is currently handled by XML::DT. A lot of | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | XPath will never be added to XML::DT because is not in accordance with | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | the down translation model. For more documentation about XPath check | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | the specification at http://www.w3c.org or some tutorials under | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | http://www.zvon.org | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | =head2 pathdtstring | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | Like the C<dtstring> function but supporting XPath. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | =head2 pathdturl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | Like the C<dturl> function but supporting XPath. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | =head2 ctxt | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | Returns the context element of the currently being processed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | element. So, if you call C<ctxt(1)> you will get your father element, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | and so on. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | =head2 inpath | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | C<inpath(pattern)> is true if the actual element path matches the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | provided pattern. This function is meant to be used in the element | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | functions in order to achieve context dependent processing. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | =head2 inctxt | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | C<inctxt(pattern)> is true if the actual element father matches the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | provided pattern. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | =head2 toxml | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | This is the default "-default" function. It can be used to generate | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | XML based on C<$c> C<$q> and C<%v> variables. Example: add a new | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | attribute to element C<ele1> without changing it: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | %handler=( ... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ele1 => sub { $v{at1} = "v1"; toxml(); }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | C<toxml> can also be used with 3 arguments: tag, attributes and contents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | toxml("a",{href=> "http://local/f.html"}, "example") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | <a href='http://local/f.html'>example</a> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | Empty tags are written as empty tags. If you want an empty tag with opening and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | closing tags, then use the C<tohtml>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | =head2 tohtml | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | See C<toxml>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | =head2 xmltree | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | This simple function just makes a HASH reference: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | { -c => $c, -q => $q, all_the_other_attributes } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | The function C<toxml> understands this structure and makes XML with it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | =head2 mkdtskel | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | Used by the mkdtskel script to generate automatically a XML::DT perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | script file based on an XML file. Check C<mkdtskel> manpage for | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | details. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | =head2 mkdtskel_fromDTD | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | Used by the mkdtskel script to generate automatically a XML::DT perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | script file based on an DTD file. Check C<mkdtskel> manpage for | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | details. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | =head2 mkdtdskel | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | Used by the mkdtskel script to generate automatically a XML::DT perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | script file based on a DTD file. Check C<mkdtdskel> manpage for | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | details. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | =head1 Accessing parents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | With XML::DT you can access an element parent (or grand-parent) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | attributes, till the root of the XML document. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | If you use c<$dtattributes[1]{foo} = 'bar'> on a processing function, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | you are defining the attribute C<foo> for that element parent. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | In the same way, you can use C<$dtattributes[2]> to access the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | grand-parent. C<$dtattributes[-1]> is, as expected, the XML document | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | root element. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | There are some shortcuts: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | =item C<father> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | =item C<gfather> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | =item C<ggfather> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | You can use these functions to access to your C<father>, grand-father | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | (C<gfather>) or great-grand-father (C<ggfather>): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | father("x"); # returns value for attribute "x" on father element | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | father("x", "value"); # sets value for attribute "x" on father | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # element | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | You can also use it directly as a reference to C<@dtattributes>: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | father->{"x"}; # gets the attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | father->{"x"} = "value"; # sets the attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | $attributes = father; # gets all attributes reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | =item C<root> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | You can use it as a function to access to your tree root element. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | root("x"); # gets attribute C<x> on root element | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | root("x", "value"); # sets value for attribute C<x> on root | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | You can also use it directly as a reference to C<$dtattributes[-1]>: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | root->{"x"}; # gets the attribute x | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | root->{"x"} = "value"; # sets the attribute x | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | $attributes = root; # gets all attributes reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | =head1 User provided element processing functions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | The user must provide an HASH with a function for each element, that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | computes element output. Functions can use the element name C<$q>, the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | element content C<$c> and the attribute values hash C<%v>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | All those global variables are defined in C<$CALLER::>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | Each time an element is find the associated function is called. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | Content is calculated by concatenation of element contents strings and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | interior elements return values. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | =head2 C<-default> function | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | When a element has no associated function, the function associated | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | with C<-default> called. If no C<-default> function is defined the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | default function returns a XML like string for the element. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | When you use C</-type> definitions, you often need do set C<-default> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | function to return just the contents: C<sub{$c}>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | =head2 C<-outputenc> option | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | C<-outputenc> defines the output encoding (default is Unicode UTF8). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | =head2 C<-inputenc> option | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | C<-inputenc> forces a input encoding type. Whenever that is possible, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | define the input encoding in the XML file: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | <?xml version='1.0' encoding='ISO-8859-1'?> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | =head2 C<-pcdata> function | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | C<-pcdata> function is used to define transformation over the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | contents. Typically this function should look at context (see | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | C<inctxt> function) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | The default C<-pcdata> function is the identity | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | =head2 C<-cdata> function | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | You can process C<<CDATA>> in a way different from pcdata. If you | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | define a C<-cdata> method, it will be used. Otherwise, the C<-pcdata> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | method is called. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | =head2 C<-begin> function | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | Function to be executed before processing XML file. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | Example of use: initialization of side-effect variables | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | =head2 C<-end> function | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | Function to be executed after processing XML file. I can use C<$c> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | content value. The value returned by C<-end> will be the C<dt> return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | value. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | Example of use: post-processing of returned contents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | =head2 C<-recover> option | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | If set, the parser will try to recover in XML errors. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | =head2 C<-html> option | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | If set, the parser will try to recover in errors. Note that this | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | differs from the previous one in the sense it uses some knowledge of | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | the HTML structure for the recovery. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | =head2 C<-userdata> option | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | Use this to pass any information you like to your handlers. The data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | structure you pass in this option will be available as C<< $u >> in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | your code. -- New in 0.62. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | =head1 Elements with values other than strings (C<-type>) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | By default all elements return strings, and contents (C<$c>) is the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | concatenation of the strings returned by the sub-elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | In some situations the XML text contains values that are better | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | processed as a structured type. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | The following types (functors) are available: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | =item THE_CHILD | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | Return the result of processing the only child of the element. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | =item LAST_CHILD | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | Returns the result of processing the last child of the element. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | =item STR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | concatenates all the sub-elements returned values (DEFAULT) all the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | sub-element should return strings to be concatenated; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | =item SEQ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | makes an ARRAY with all the sub elements contents; attributes are | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | ignored (they should be processed in the sub-element). (returns a ref) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | If you have different types of sub-elements, you should use SEQH | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | =item SEQH | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | makes an ARRAY of HASH with all the sub elements (returns a ref); for | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | each sub-element: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | -q => element name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | -c => contents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | at1 => at value1 for each attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | =item MAP | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | makes an HASH with the sub elements; keys are the sub-element names, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | values are their contents. Attributes are ignored. (they should be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | processed in the sub-element) (returns a ref) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | =item MULTIMAP | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | makes an HASH of ARRAY; keys are the sub-element names; values are | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | lists of contents; attributes are ignored (they should be processed in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | the sub-element); (returns a ref) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | =item MMAPON(element-list) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | makes an HASH with the sub-elements; keys are the sub-element names, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | values are their contents; attributes are ignored (they should be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | processed in the sub-element); for all the elements contained in the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | element-list, it is created an ARRAY with their contents. (returns a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | ref) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | =item XML | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | return a reference to an HASH with: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | -q => element name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | -c => contents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | at1 => at value1 for each attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | =item ZERO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | don't process the sub-elements; return "" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | When you use C</-type> definitions, you often need do set C<-default> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | function returning just the contents C<sub{$id}>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | =head2 An example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | use XML::DT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | %handler = ( contacts => sub{ [ split(";",$c)] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | -default => sub{$c}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | -type => { institution => 'MAP', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | degrees => MMAPON('name') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | tels => 'SEQ' } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | $a = dt ("f.xml", %handler); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | with the following f.xml | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | <degrees> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | <institution> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | <id>U.M.</id> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | <name>University of Minho</name> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | <tels> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | <item>1111</item> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | <item>1112</item> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | <item>1113</item> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | </tels> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | <where>Portugal</where> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | <contacts>J.Joao; J.Rocha; J.Ramalho</contacts> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | </institution> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | <name>Computer science</name> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | <name>Informatica </name> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | <name> history </name> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | </degrees> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | would make $a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | { 'name' => [ 'Computer science', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 'Informatica ', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | ' history ' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 'institution' => { 'tels' => [ 1111, 1112, 1113 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 'name' => 'University of Minho', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 'where' => 'Portugal', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 'id' => 'U.M.', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 'contacts' => [ 'J.Joao', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | ' J.Rocha', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | ' J.Ramalho' ] } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | =head1 DT Skeleton generation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | It is possible to build an initial processor program based on an example | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | To do this use the function C<mkdtskel(filename)>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | perl -MXML::DT -e 'mkdtskel "f.xml"' > f.pl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | =head1 DTD skeleton generation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | It makes a naive DTD based on an example(s). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | To do this use the function C<mkdtdskel(filename*)>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | perl -MXML::DT -e 'mkdtdskel "f.xml"' > f.dtd | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | mkdtskel(1) and mkdtdskel(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | Home for XML::DT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | http://natura.di.uminho.pt/~jj/perl/XML/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | Jose Joao Almeida, <jj@di.uminho.pt> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | Alberto Manuel Simões, <albie@alfarrabio.di.uminho.pt> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | Michel Rodriguez <mrodrigu@ieee.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | José Carlos Ramalho <jcr@di.uminho.pt> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | Mark A. Hillebrand | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | Copyright 1999-2012 Project Natura. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | This library is free software; you can redistribute it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 7 | our %ty = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | sub dt { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 13 | ▶ | my ($file, %xml)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dt: called CC=12 SCAR=32.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 13 | my ($parser, $tree); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | # Treat -decl option | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 13 | my $declr = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 13 | ▶ | if ($xml{-declr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | if ($xml{-outputenc}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | $declr = "<?xml version=\"1.0\" encoding=\"$xml{-outputenc}\"?>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | $declr = "<?xml version=\"1.0\"?>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 13 | %ty = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 13 | ▶ | %ty = (%{$xml{'-type'}}) if defined($xml{'-type'}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 13 | $ty{-ROOT} = "NONE"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 13 | ▶ | &{$xml{-begin}} if $xml{-begin}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # TODO --- how to force encoding with XML::LibXML? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | # $xml{-inputenc} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | # create a new LibXML parser | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 13 | $parser = XML::LibXML->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | #### We don't wan't DT to load everytime the DTD (I Think!) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 13 | $parser->validation(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # $parser->expand_xinclude(0); # testing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 13 | $parser->load_ext_dtd(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 13 | $parser->expand_entities(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 13 | ▶ | $parser->expand_xincludes(1) if $xml{'-xinclude'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # parse the file | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 13 | my $doc; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 13 | ▶ | if ( $xml{'-recover'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | $parser->recover(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | local $SIG{__WARN__} = sub{}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | $doc = $parser->parse_file($file); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | return undef if !$doc; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | elsif ( $xml{'-html'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | $parser->recover(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | local $SIG{__WARN__} = sub{}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $doc = $parser->parse_html_file($file); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | return undef if !$doc; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 13 | $doc = $parser->parse_file($file) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | # get the document root element | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 13 | $tree = $doc->getDocumentElement(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 13 | my $return = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # execute End action if it exists | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 13 | ▶ | if($xml{-end}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | $c = _omni("-ROOT", \%xml, $tree); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | $return = &{$xml{-end}} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 12 | $return = _omni("-ROOT",\%xml, $tree) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 13 | ▶ | if ($declr) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | return $declr.$return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 13 | return $return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | sub ctxt { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | my $level = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ctxt: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | $dtcontext[-$level-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | sub inpath { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | my $pattern = shift ; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inpath: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | join ("/", @dtcontext) =~ m!\b$pattern\b!; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | sub inctxt { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 38 | ▶ | my $pattern = shift ; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inctxt: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # see if is in root context... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 38 | ▶ | return 1 if (($pattern eq "^" && @dtcontext==1) || $pattern eq ".*"); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$pattern eq "^" and @XML::DT::dtcontext == 1 or $pattern eq ".*"
$pattern eq "^" and @XML::DT::dtcontext == 1
MC/DC100%3/3
$pattern eq "^" and @XML::DT::dtcontext == 1 or $pattern eq ".*"
$pattern eq "^"
@XML::DT::dtcontext == 1
$pattern eq ".*"
Truth table80%4/5
A and B or C
A= $pattern eq "^"B= @XML::DT::dtcontext == 1C= $pattern eq ".*"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 11 | join("/", @dtcontext) =~ m!$pattern/[^/]*$! ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | sub father { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | my ($a,$b)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
father: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | if (defined($b)){$dtattributes[1]{$a} = $b} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | elsif(defined($a)){$dtattributes[1]{$a} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | else {$dtattributes[1]} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | sub gfather { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | ▶ | my ($a,$b)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gfather: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | if (defined($b)){$dtattributes[2]{$a} = $b} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | elsif(defined($a)){$dtattributes[2]{$a} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | else {$dtattributes[2]} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | sub ggfather { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | my ($a,$b)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ggfather: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | if (defined($b)){$dtattributes[3]{$a} = $b} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | elsif(defined($a)){$dtattributes[3]{$a} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | else {$dtattributes[3]} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | sub root { ### the root | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | my ($a,$b)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | if (defined($b)){$dtattributes[-1]{$a} = $b } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | elsif(defined($a)){$dtattributes[-1]{$a} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | else {$dtattributes[-1] } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | sub pathdtstring{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 12 | ▶ | my $string = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pathdtstring: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 12 | my %h = _pathtodt(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 12 | return dtstring($string,%h); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | sub pathdturl{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | my $url = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pathdturl: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | my %h = _pathtodt(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | return dturl($url,%h); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | sub dturl{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | ▶ | my $url = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dturl: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | my $contents = get($url); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | if ($contents) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | return dtstring($contents, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | sub dtstring { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 20 | ▶ | my ($string, %xml)=@_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dtstring: called CC=12 SCAR=30.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 20 | my ($parser, $tree); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 20 | my $declr = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 20 | ▶ | if ($xml{-declr}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | ▶ | if ($xml{-outputenc}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | $declr = "<?xml version=\"1.0\" encoding=\"$xml{-outputenc}\"?>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 1 | $declr = "<?xml version=\"1.0\"?>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 20 | ▶ | $xml{'-type'} = {} unless defined $xml{'-type'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 20 | %ty = (%{$xml{'-type'}}, -ROOT => "NONE"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | # execute Begin action if it exists | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 20 | ▶ | if ($xml{-begin}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | &{$xml{-begin}} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 20 | ▶ | if ($xml{-inputenc}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 3 | $string = XML::LibXML::encodeToUTF8($xml{-inputenc}, $string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # create a new LibXML parser | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 20 | $parser = XML::LibXML->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 20 | $parser->validation(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 20 | $parser->load_ext_dtd(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 20 | $parser->expand_entities(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | # parse the string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 20 | my $doc; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 20 | ▶ | if ( $xml{'-recover'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | $parser->recover(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | ▶ | local $SIG{__WARN__} = sub{}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | $doc = $parser->parse_string($string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | return undef if !$doc; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | elsif ( $xml{'-html'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | $parser->recover(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | eval{ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | ▶ | local $SIG{__WARN__} = sub{}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | $doc = $parser->parse_html_string($string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # if ($@) { return undef; } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | ▶ | return undef unless defined $doc; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 20 | $doc = $parser->parse_string($string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # get the document root element | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 20 | $tree = $doc->getDocumentElement(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 20 | my $return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # Check if we have an end function | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 20 | ▶ | if ($xml{-end}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | $c = _omni("-ROOT", \%xml, $tree); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | $return = &{$xml{-end}} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 20 | $return = _omni("-ROOT", \%xml, $tree) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 20 | ▶ | if ($declr) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 1 | return $declr.$return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 19 | return $return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | sub pathdt{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | ▶ | my $file = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pathdt: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | my %h = _pathtodt(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | return dt($file,%h); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | # Parsing dos predicados do XPath | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | sub _testAttr { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 9 | ▶ | my $atr = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_testAttr: called CC=14 SCAR=36.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 9 | for ($atr) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 9 | s/name\(\)/'$q'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | # s/\@([A-Za-z_]+)/'$v{$1}'/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 9 | ▶ | s/\@([A-Za-z_]+)/defined $v{$1}?"'$v{$1}'":"''"/ge; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 9 | ▶ | s/\@\*/keys %v?"'1'":"''"/ge; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 9 | ▶ | if (/^not\((.*)\)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | return ! _testAttr($1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | } elsif (/^('|")([^\1]*)(\1)\s*=\s*('|")([^\4]*)\4$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 4 | return ($2 eq $5); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | } elsif (/^(.*?)normalize-space\((['"])([^\2)]*)\2\)(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | my ($back,$forward)=($1,$4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | my $x = _normalize_space($3); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | return _testAttr("$back'$x'$forward"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } elsif (/starts-with\((['"])([^\1))]*)\1,(['"])([^\3))]*)\3\)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | my $x = _starts_with($2,$4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | return $x; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } elsif (/contains\((['"])([^\1))]*)\1,(['"])([^\3))]*)\3\)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | my $x = _contains($2,$4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | return $x; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | } elsif (/^(.*?)string-length\((['"])([^\2]*)\2\)(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | my ($back,$forward) = ($1,$4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | my $x = length($3); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | return _testAttr("$back$x$forward"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | } elsif (/^(\d+)\s*=(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | return ($1 == $2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | } elsif (/^(\d+)\s*<(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | return ($1 < $2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | } elsif (/^(\d+)\s*>(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | return ($1 > $2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | } elsif (/^(['"])([^\1]*)\1$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 5 | return $2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | return 0; #$atr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # Funcao auxiliar de teste de predicados do XPath | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | sub _starts_with { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | ▶ | my ($string,$preffix) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_starts_with: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | ▶ | return 0 unless ($string && $preffix); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$string and $preffix
MC/DC0%0/2
$string and $preffix
$string
$preffix
Truth table0%0/3
A and B
A= $stringB= $preffix
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | return 1 if ($string =~ m!^$preffix!); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | # Funcao auxiliar de teste de predicados do XPath | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | sub _contains { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | ▶ | my ($string,$s) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_contains: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | ▶ | return 0 unless ($string && $s); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$string and $s
MC/DC0%0/2
$string and $s
$string
$s
Truth table0%0/3
A and B
A= $stringB= $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | ▶ | return 1 if ($string =~ m!$s!); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | # Funcao auxiliar de teste de predicados do XPath | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | sub _normalize_space { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 4 | ▶ | my $z = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_space: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 4 | $z =~ /^\s*(.*?)\s*$/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 4 | $z = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 4 | $z =~ s!\s+! !g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 4 | return $z; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | sub _pathtodt { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 12 | ▶ | my %h = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pathtodt: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 12 | my %aux=(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 12 | my %aux2=(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 12 | my %n = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 12 | my $z; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 12 | for $z (keys %h) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | # TODO - Make it more generic | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 16 | ▶ | if ( $z=~m{\w+(\|\w+)+}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 1 | my @tags = split /\|/, $z; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 1 | for(@tags) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 3 | $aux2{$_}=$h{$z} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | elsif ( $z=~m{(//|/|)(.*)/([^\[]*)(?:\[(.*)\])?} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 10 | my ($first,$second,$third,$fourth) = ($1,$2,$3,$4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 10 | ▶ | if (($first eq "/") && (!$second)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$first eq "/" and not $second
MC/DC100%2/2
$first eq "/" and not $second
$first eq "/"
not $second
Truth table100%3/3
A and not(B)
A= $first eq "/"B= not $second
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 7 | $first = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 7 | $second = '.*'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 7 | $third =~ s!\*!-default!; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 3 | $second =~ s!\*!\[^/\]\+!g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 3 | $second =~ s!/$!\(/\.\*\)\?!g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 3 | $second =~ s!//!\(/\.\*\)\?/!g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 3 | $third =~ s!\*!-default!g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 10 | push( @{$aux{$third}} , [$first,$second,$h{$z},$fourth]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 5 | else { $aux2{$z}=$h{$z};} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 12 | for $z (keys %aux){ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | my $code = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 38 | ▶ | my $l; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 38 | for $l (@{$aux{$z}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 38 | my $prefix = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 38 | ▶ | $prefix = "^" unless (($l->[0]) or ($l->[1])); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$l->[0] or $l->[1]
MC/DC100%2/2
$l->[0] or $l->[1]
$l->[0]
$l->[1]
Truth table100%3/3
A or B
A= $l->[0]B= $l->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 38 | ▶ | $prefix = "^" if (($l->[0] eq "/") && ($l->[1])); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$l->[0] eq "/" and $l->[1]
MC/DC50%1/2
$l->[0] eq "/" and $l->[1]
$l->[0] eq "/"
$l->[1]
Truth table66%2/3
A and B
A= $l->[0] eq "/"B= $l->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 38 | ▶ | if ($l->[3]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 9 | ▶ | if(inctxt("$prefix$l->[1]") && _testAttr($l->[3])) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
inctxt("$prefix$l->[1]") and _testAttr($l->[3])
MC/DC50%1/2
inctxt("$prefix$l->[1]") and _testAttr($l->[3])
inctxt("$prefix$l->[1]")
_testAttr($l->[3])
Truth table66%2/3
A and B
A= inctxt("$prefix$l->[1]")B= _testAttr($l->[3])
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 4 | {return &{$l->[2]}; } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 29 | ▶ | if(inctxt("$prefix$l->[1]")) {return &{$l->[2]};} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 14 | ▶ | return &{ $aux2{$z}} if $aux2{$z} ; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 14 | ▶ | return &{ $h{-default}} if $h{-default}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 10 | &toxml(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 10 | $n{$z} = $code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 12 | for $z (keys %aux2){ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 8 | ▶ | $n{$z} ||= $aux2{$z} ; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$n{$z} ||= $aux2{$z}
MC/DC0%0/2
$n{$z} ||= $aux2{$z}
$n{$z}
$aux2{$z}
Truth table33%1/3
A ||= B
A= $n{$z}B= $aux2{$z}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 12 | return %n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | sub _omni { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 242 | ▶ | my ($par, $xml, @l) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_omni: called CC=62 SCAR=64.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | my $defaulttype = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | (exists($xml->{-type}) && exists($xml->{-type}{-default})) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 242 | ▶ | $xml->{-type}{-default} : "STR"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $xml->{"-type"} and exists $xml->{"-type"}{"-default"}
MC/DC100%2/2
exists $xml->{"-type"} and exists $xml->{"-type"}{"-default"}
exists $xml->{"-type"}
exists $xml->{"-type"}{"-default"}
Truth table100%3/3
A and B
A= exists $xml->{"-type"}B= exists $xml->{"-type"}{"-default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 242 | ▶ | my $type = $ty{$par} || $defaulttype; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$XML::DT::ty{$par} || $defaulttype
MC/DC0%0/2
$XML::DT::ty{$par} || $defaulttype
$XML::DT::ty{$par}
$defaulttype
Truth table66%2/3
A || B
A= $XML::DT::ty{$par}B= $defaulttype
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 242 | my %typeargs = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 242 | ▶ | if (ref($type) eq "mmapon") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | $typeargs{$_} = 1 for (@$type); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 0 | $type = "MMAPON"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 242 | my $r ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 242 | ▶ | if( $type eq 'STR') { $r = "" } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | ▶ | elsif( $type eq 'THE_CHILD' or $type eq 'LAST_CHILD') { $r = 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "THE_CHILD" or $type eq "LAST_CHILD"
MC/DC0%0/2
$type eq "THE_CHILD" or $type eq "LAST_CHILD"
$type eq "THE_CHILD"
$type eq "LAST_CHILD"
Truth table33%1/3
A or B
A= $type eq "THE_CHILD"B= $type eq "LAST_CHILD"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 5 | ▶ | elsif( $type eq 'SEQ' or $type eq "ARRAY") { $r = [] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$type eq "SEQ" or $type eq "ARRAY"
MC/DC50%1/2
$type eq "SEQ" or $type eq "ARRAY"
$type eq "SEQ"
$type eq "ARRAY"
Truth table66%2/3
A or B
A= $type eq "SEQ"B= $type eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 2 | ▶ | elsif( $type eq 'SEQH' or $type eq "ARRAYOFHASH") { $r = [] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$type eq "SEQH" or $type eq "ARRAYOFHASH"
MC/DC50%1/2
$type eq "SEQH" or $type eq "ARRAYOFHASH"
$type eq "SEQH"
$type eq "ARRAYOFHASH"
Truth table66%2/3
A or B
A= $type eq "SEQH"B= $type eq "ARRAYOFHASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | ▶ | elsif( $type eq 'MAP' or $type eq "HASH") { $r = {} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "MAP" or $type eq "HASH"
MC/DC0%0/2
$type eq "MAP" or $type eq "HASH"
$type eq "MAP"
$type eq "HASH"
Truth table33%1/3
A or B
A= $type eq "MAP"B= $type eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | elsif( $type eq 'MULTIMAP') { $r = {} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | ▶ | elsif( $type eq 'MMAPON' or $type eq "HASHOFARRAY") { $r = {} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "MMAPON" or $type eq "HASHOFARRAY"
MC/DC0%0/2
$type eq "MMAPON" or $type eq "HASHOFARRAY"
$type eq "MMAPON"
$type eq "HASHOFARRAY"
Truth table33%1/3
A or B
A= $type eq "MMAPON"B= $type eq "HASHOFARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 33 | elsif( $type eq 'NONE') { $r = "" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 0 | elsif( $type eq 'ZERO') { return "" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 242 | my ($name, $val, @val, $atr, $aux); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 242 | $u = $xml->{-userdata}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 242 | ▶ | while(@l) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 507 | my $tree = shift @l; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 507 | ▶ | next unless $tree; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 507 | ▶ | $name = ref($tree) eq "XML::LibXML::CDATASection" ? "-pcdata" : $tree->getName(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 507 | ▶ | if (ref($tree) eq "XML::LibXML::CDATASection") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 0 | $val = $tree->getData(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | $name = "-cdata"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 0 | ▶ | $aux = (defined($xml->{-outputenc}))?_fromUTF8($val,$xml->{-outputenc}):$val; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | ▶ | if (defined($xml->{-cdata})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | push(@dtcontext,"-cdata"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | $c = $aux; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | $aux = &{$xml->{-cdata}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | pop(@dtcontext); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } elsif (defined($xml->{-pcdata})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | push(@dtcontext,"-pcdata"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | $c = $aux; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | $aux = &{$xml->{-pcdata}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | pop(@dtcontext); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | } elsif (ref($tree) eq "XML::LibXML::Comment") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | ### At the moment, treat as Text | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | ### We will need to change this, I hope! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | $val = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 0 | $name = "-pcdata"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | ▶ | $aux= (defined($xml->{-outputenc}))?_fromUTF8($val, $xml->{-outputenc}):$val; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | ▶ | if (defined($xml->{-pcdata})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | push(@dtcontext,"-pcdata"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | $c = $aux; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | $aux = &{$xml->{-pcdata}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | pop(@dtcontext); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | elsif (ref($tree) eq "XML::LibXML::Text") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 298 | $val = $tree->getData(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 298 | $name = "-pcdata"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 298 | ▶ | $aux = (defined($xml->{-outputenc}))?_fromUTF8($val,$xml->{-outputenc}):$val; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 298 | ▶ | if (defined($xml->{-pcdata})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | push(@dtcontext,"-pcdata"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | $c = $aux; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | $aux = &{$xml->{-pcdata}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | pop(@dtcontext); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | } elsif (ref($tree) eq "XML::LibXML::Element") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 209 | my %atr = _nodeAttributes($tree); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 209 | $atr = \%atr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 209 | ▶ | if (exists($xml->{-ignorecase})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 40 | $name = lc($name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 40 | for (keys %$atr) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 8 | my ($k,$v) = (lc($_),$atr->{$_}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 8 | delete($atr->{$_}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 8 | $atr->{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 209 | push(@dtcontext,$name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 209 | $dtcontextcount{$name}++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 209 | unshift(@dtatributes, $atr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 209 | unshift(@dtattributes, $atr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 209 | $aux = _omniele($xml, $name, _omni($name, $xml, ($tree->getChildnodes())), $atr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 209 | shift(@dtatributes); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 209 | shift(@dtattributes); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 209 | pop(@dtcontext); $dtcontextcount{$name}--; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | } elsif (ref($tree) eq "XML::LibXML::Node") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | ▶ | if ($tree->nodeType == XML_ENTITY_REF_NODE) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | # if we get here, is because we are not expanding entities (I think) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 0 | ▶ | if ($tree->textContent) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | $aux = $tree->textContent; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | $aux = '&'.$tree->nodeName.';'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 0 | print STDERR "Not handled, generic node of type: [",$tree->nodeType,"]\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 0 | print STDERR "Not handled: [",ref($tree),"]\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 507 | ▶ | if ($type eq "STR"){ if (defined($aux)) {$r .= $aux} ;} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | ▶ | elsif ($type eq "THE_CHILD" or $type eq "LAST_CHILD"){ | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "THE_CHILD" or $type eq "LAST_CHILD"
MC/DC0%0/2
$type eq "THE_CHILD" or $type eq "LAST_CHILD"
$type eq "THE_CHILD"
$type eq "LAST_CHILD"
Truth table33%1/3
A or B
A= $type eq "THE_CHILD"B= $type eq "LAST_CHILD"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | ▶ | $r = $aux unless _whitepc($aux, $name); } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | ▶ | elsif ($type eq "SEQ" or $type eq "ARRAY"){ | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$type eq "SEQ" or $type eq "ARRAY"
MC/DC50%1/2
$type eq "SEQ" or $type eq "ARRAY"
$type eq "SEQ"
$type eq "ARRAY"
Truth table66%2/3
A or B
A= $type eq "SEQ"B= $type eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 9 | ▶ | push(@$r, $aux) unless _whitepc($aux, $name);} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | ▶ | elsif ($type eq "SEQH" or $type eq "ARRAYHASH"){ | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$type eq "SEQH" or $type eq "ARRAYHASH"
MC/DC50%1/2
$type eq "SEQH" or $type eq "ARRAYHASH"
$type eq "SEQH"
$type eq "ARRAYHASH"
Truth table66%2/3
A or B
A= $type eq "SEQH"B= $type eq "ARRAYHASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 4 | ▶ | push(@$r,{"-c" => $aux, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | "-q" => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | _nodeAttributes($tree) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | }) unless _whitepc($aux,$name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | elsif($type eq "MMAPON"){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | ▶ | if(not _whitepc($aux,$name)){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | ▶ | if(! $typeargs{$name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 0 | ▶ | warn "duplicated tag '$name'\n" if(defined($r->{$name})); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 0 | $r->{$name} = $aux } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 0 | ▶ | else { push(@{$r->{$name}},$aux) unless _whitepc($aux,$name)}} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | ▶ | elsif($type eq "MAP" or $type eq "HASH"){ | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$type eq "MAP" or $type eq "HASH"
MC/DC0%0/2
$type eq "MAP" or $type eq "HASH"
$type eq "MAP"
$type eq "HASH"
Truth table33%1/3
A or B
A= $type eq "MAP"B= $type eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 0 | ▶ | if(not _whitepc($aux,$name)){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 0 | ▶ | warn "duplicated tag '$name'\n" if(defined($r->{$name})); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 0 | $r->{$name} = $aux }} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | elsif($type eq "MULTIMAP"){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | ▶ | push(@{$r->{$name}},$aux) unless _whitepc($aux,$name)} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 33 | elsif($type eq "NONE"){ $r = $aux;} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | else { $r="undefined type !!!"} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 242 | $r; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | sub _omniele { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 209 | ▶ | my $xml = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_omniele: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 209 | my $aux; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 209 | ($q, $c, $aux) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 209 | %v = %$aux; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | 209 | ▶ | if (defined($xml->{-outputenc})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 3 | for (keys %v){ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | $v{$_} = _fromUTF8($v{$_}, $xml->{-outputenc}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 209 | ▶ | if (defined $xml->{$q}) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 53 | { &{$xml->{$q}} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | elsif (defined $xml->{'-default'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 149 | { &{$xml->{'-default'}} } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | elsif (defined $xml->{'-tohtml'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 0 | { tohtml() } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 7 | { toxml() } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | ▶ | sub xmltree { +{'-c' => $c, '-q' => $q, %v} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xmltree: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | sub tohtml { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 44 | ▶ | my ($q,$v,$c); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tohtml: called CC=22 SCAR=38.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 44 | ▶ | if (not @_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 0 | ($q,$v,$c) = ($XML::DT::q, \%XML::DT::v, $XML::DT::c); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | } elsif (ref($_[0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | 21 | $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 23 | ($q,$v,$c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 44 | ▶ | if (not ref($c)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 23 | ▶ | if ($q eq "-pcdata") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 0 | return $c | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | ▶ | } elsif ($q eq "link" || $q eq "br" || $q eq "hr" || $q eq "img") { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
$q eq "link" or $q eq "br" or $q eq "hr" or $q eq "img"
$q eq "link" or $q eq "br" or $q eq "hr"
$q eq "link" or $q eq "br"
MC/DC100%4/4
$q eq "link" or $q eq "br" or $q eq "hr" or $q eq "img"
$q eq "link"
$q eq "br"
$q eq "hr"
$q eq "img"
Truth table100%5/5
A or B or C or D
A= $q eq "link"B= $q eq "br"C= $q eq "hr"D= $q eq "img"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 4 | return _openTag($q,$v) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 19 | return _openTag($q,$v) . "$c</$q>" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | ▶ | elsif (ref($c) eq "HASH" && $c->{'-q'} && $c->{'-c'}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
ref $c eq "HASH" and $c->{"-q"} and $c->{"-c"}
ref $c eq "HASH" and $c->{"-q"}
MC/DC33%1/3
ref $c eq "HASH" and $c->{"-q"} and $c->{"-c"}
ref $c eq "HASH"
$c->{"-q"}
$c->{"-c"}
Truth table50%2/4
A and B and C
A= ref $c eq "HASH"B= $c->{"-q"}C= $c->{"-c"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 16 | my %a = %$c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 16 | my ($q,$c) = delete @a{"-q","-c"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 16 | ▶ | tohtml($q,\%a,(ref($c)?tohtml($c):$c)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | elsif (ref($c) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | _openTag($q,$v). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | join("",map {($_ ne "-pcdata") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | ? ( (ref($c->{$_}) eq "ARRAY") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | ? "<$_>". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | join("</$_>\n<$_>", @{$c->{$_}}). | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | "</$_>\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | ▶ | : tohtml($_,{},$c->{$_})."\n" ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | : () } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 0 | keys %{$c} ) . | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | "$c->{-pcdata}</$q>" } ######## "NOTYetREady" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | elsif (ref($c) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 5 | ▶ | if (defined($q) && exists($ty{$q}) && $ty{$q} eq "SEQH") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
defined $q and exists $XML::DT::ty{$q} and $XML::DT::ty{$q} eq "SEQH"
defined $q and exists $XML::DT::ty{$q}
MC/DC0%0/3
defined $q and exists $XML::DT::ty{$q} and $XML::DT::ty{$q} eq "SEQH"
defined $q
exists $XML::DT::ty{$q}
$XML::DT::ty{$q} eq "SEQH"
Truth table25%1/4
A and B and C
A= defined $qB= exists $XML::DT::ty{$q}C= $XML::DT::ty{$q} eq "SEQH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 0 | tohtml($q,$v,join("\n",map {tohtml($_)} @$c)) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | } elsif (defined $q) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 0 | tohtml($q,$v,join("",@{$c})) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 5 | ▶ | join("\n",map {(ref($_)?tohtml($_):$_)} @$c) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | sub toxml { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 118 | ▶ | my ($q,$v,$c); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toxml: called CC=19 SCAR=35.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 118 | ▶ | if (not @_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 64 | ($q, $v, $c) = ($XML::DT::q, \%XML::DT::v, $XML::DT::c); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | } elsif (ref($_[0])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 27 | $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 27 | ($q, $v, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 118 | ▶ | if (not ref($c)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 91 | ▶ | if ($q eq "-pcdata") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 3 | return $c | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | } elsif ($c eq "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 3 | return _emptyTag($q,$v) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 85 | return _openTag($q,$v) . "$c</$q>" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | ▶ | elsif (ref($c) eq "HASH" && $c->{'-q'} && $c->{'-c'}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
ref $c eq "HASH" and $c->{"-q"} and $c->{"-c"}
ref $c eq "HASH" and $c->{"-q"}
MC/DC33%1/3
ref $c eq "HASH" and $c->{"-q"} and $c->{"-c"}
ref $c eq "HASH"
$c->{"-q"}
$c->{"-c"}
Truth table50%2/4
A and B and C
A= ref $c eq "HASH"B= $c->{"-q"}C= $c->{"-c"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 20 | my %a = %$c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 20 | my ($q,$c) = delete @a{"-q","-c"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | ### _openTag($q,\%a).toxml($c).). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | ### toxml($q,\%a,join("\n",map {toxml($_)} @$c)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 20 | ▶ | toxml($q,\%a,(ref($c)?toxml($c):$c)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | elsif (ref($c) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | _openTag($q,$v). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | join("",map {($_ ne "-pcdata") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | ? ( (ref($c->{$_}) eq "ARRAY") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | ? "<$_>". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 0 | join("</$_>\n<$_>", @{$c->{$_}}). | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | "</$_>\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 0 | ▶ | : toxml($_,{},$c->{$_})."\n" ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | : () } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | keys %{$c} ) . | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | "$c->{-pcdata}</$q>" } ######## "NOTYetREady" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | elsif (ref($c) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 7 | ▶ | if (defined($q) && exists($ty{$q}) && $ty{$q} eq "SEQH") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
defined $q and exists $XML::DT::ty{$q} and $XML::DT::ty{$q} eq "SEQH"
defined $q and exists $XML::DT::ty{$q}
MC/DC0%0/3
defined $q and exists $XML::DT::ty{$q} and $XML::DT::ty{$q} eq "SEQH"
defined $q
exists $XML::DT::ty{$q}
$XML::DT::ty{$q} eq "SEQH"
Truth table25%1/4
A and B and C
A= defined $qB= exists $XML::DT::ty{$q}C= $XML::DT::ty{$q} eq "SEQH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | toxml($q,$v,join("\n",map {toxml($_)} @$c)) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | } elsif (defined $q) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | 0 | toxml($q,$v,join("",@{$c})) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 7 | ▶ | join("\n",map {(ref($_)?toxml($_):$_)} @$c) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | sub _openTag{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 108 | ▶ | "<$_[0]". join("",map {" $_=\"$_[1]{$_}\""} keys %{$_[1]} ).">" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_openTag: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | sub _emptyTag{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 3 | ▶ | "<$_[0]". join("",map {" $_=\"$_[1]{$_}\""} keys %{$_[1]} )."/>" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emptyTag: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | sub mkdtskel_fromDTD { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | 1 | ▶ | my $filename = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mkdtskel_fromDTD: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 1 | my $file = ParseDTDFile($filename); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 1 | print <<'PERL'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | use XML::DT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | my $filename = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | # Variable Reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | # $c - contents after child processing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | # $q - element name (tag) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | # %v - hash of attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | my %handler=( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | # '-outputenc' => 'ISO-8859-1', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | # '-default' => sub{"<$q>$c</$q>"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | PERL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 1 | for (sort keys %{$file}) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 3 | print " '$_' => sub { },"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | print " # attributes: ", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 3 | ▶ | join(", ", keys %{$file->{$_}{attributes}}) if exists($file->{$_}{attributes}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 3 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 1 | print <<'PERL'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | print dt($filename, %handler); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | PERL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | sub mkdtskel{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 1 | ▶ | my @files = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mkdtskel: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 1 | my $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 1 | my $HTML = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 1 | my %element; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | my %att; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | my %mkdtskel = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | ('-default' => sub{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 10 | ▶ | $element{$q}++; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 10 | for (keys %v) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 2 | $att{$q}{$_} = 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 10 | ""}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | '-end' => sub{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 1 | ▶ | print <<'END'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | use XML::DT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | my $filename = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | # Variable Reference | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | # $c - contents after child processing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | # $q - element name (tag) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | # %v - hash of attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | my %handler=( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | # '-outputenc' => 'ISO-8859-1', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | # '-default' => sub{"<$q>$c</$q>"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | END | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 1 | print $HTML; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 1 | for $name (sort keys %element) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 3 | print " '$name' => sub{ }, #"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 3 | print " $element{$name} occurrences;"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | print ' attributes: ', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 3 | ▶ | join(', ', keys %{$att{$name}}) if $att{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | # print " \"\$q:\$c\"\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 3 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 1 | print <<'END'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | print dt($filename, %handler); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | END | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | 1 | my $file = shift(@files); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | 1 | ▶ | while($file =~ /^-/){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 0 | ▶ | if ($file eq "-html") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 0 | $HTML = " '-html' => 1,\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | 0 | $mkdtskel{'-html'} = 1;} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 0 | elsif($file eq "-latin1") { $mkdtskel{'-inputenc'}='ISO-8859-1';} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 0 | else { die("usage mktskel [-html] [-latin1] file \n")} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | 0 | $file=shift(@files)} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | 1 | dt($file,%mkdtskel) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | sub _nodeAttributes { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 213 | ▶ | my $node = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_nodeAttributes: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 213 | my %answer = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 213 | my @attrs = $node->getAttributes(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | 213 | for (@attrs) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | 37 | ▶ | if (ref($_) eq "XML::LibXML::Namespace") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | # TODO: This should not be ignored, I think. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | # This sould be converted on a standard attribute with | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | # key 'namespace' and respective contents | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 37 | $answer{$_->getName()} = $_->getValue(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 213 | return %answer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | sub mkdtdskel { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 0 | ▶ | my @files = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mkdtdskel: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | my $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | my %att; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 0 | my %ele; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 0 | my %elel; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 0 | my $root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | my %handler=( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | '-outputenc' => 'ISO-8859-1', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | '-default' => sub{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 0 | ▶ | $elel{$q}++; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | 0 | ▶ | $root = $q unless ctxt(1); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 0 | $ele{ctxt(1)}{$q} ++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 0 | for(keys(%v)){$att{$q}{$_} ++ } ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | 0 | ▶ | '-pcdata' => sub{ if ($c =~ /[^ \t\n]/){ $ele{ctxt(1)}{"#PCDATA"}=1 }}, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | 0 | ▶ | while($files[0] =~ /^-/){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 0 | ▶ | if ($files[0] eq "-html") { $handler{'-html'} = 1;} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 0 | elsif($files[0] eq "-latin1") { $handler{'-inputenc'}='ISO-8859-1';} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 0 | else { die("usage mkdtdskel [-html] [-latin1] file* \n")} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 0 | shift(@files)} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 0 | for my $filename (@files){ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 0 | dt($filename,%handler); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | 0 | print "<!-- DTD $root ... -->\n<!-- (C) ... " . localtime(time) ." -->\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 0 | delete $elel{$root}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | 0 | for ($root, keys %elel){ | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 0 | _putele($_, \%ele); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 0 | for $name (keys(%{$att{$_}})) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 0 | print( "\t<!-- $name : ... -->\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | 0 | print( "\t<!ATTLIST $_ $name CDATA #IMPLIED >\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | sub _putele { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | 0 | ▶ | my ($e,$ele) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_putele: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 0 | my @f ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 0 | ▶ | if ($ele->{$e}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | 0 | @f = keys %{$ele->{$e}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 0 | ▶ | print "<!ELEMENT $e (", join("|", @f ),")", | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@f >= 1 and $f[0] eq "#PCDATA"
MC/DC0%0/2
@f >= 1 and $f[0] eq "#PCDATA"
@f >= 1
$f[0] eq "#PCDATA"
Truth table0%0/3
A and B
A= @f >= 1B= $f[0] eq "#PCDATA"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | (@f >= 1 && $f[0] eq "#PCDATA" ? "" : "*"), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | " >\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 0 | print "<!-- ", join(" | ", (map {"$_=$ele->{$e}{$_}"} @f )), " -->\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | 0 | print "<!ELEMENT $e EMPTY >\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | sub _whitepc { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | 13 | ▶ | $_[1] eq '-pcdata' and $_[0] =~ /^[ \t\r\n]*$/ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_whitepc: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | sub MMAPON { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 0 | ▶ | bless([@_],"mmapon") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
MMAPON: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | sub _fromUTF8 { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 4 | ▶ | my $string = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fromUTF8: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | 4 | my $encode = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 4 | my $ans = eval { XML::LibXML::decodeFromUTF8($encode, $string) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 4 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | 0 | return $string | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 4 | return $ans | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||