| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyrights 2006-2024 by [Mark Overmeer ]. |
|
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
|
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
|
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.03. |
|
5
|
|
|
|
|
|
|
# This code is part of distribution XML-Compile. Meta-POD processed with |
|
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
|
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package XML::Compile::Util;{ |
|
10
|
|
|
|
|
|
|
our $VERSION = '1.64'; |
|
11
|
|
|
|
|
|
|
} |
|
12
|
|
|
|
|
|
|
|
|
13
|
51
|
|
|
51
|
|
4239595
|
use base 'Exporter'; |
|
|
51
|
|
|
|
|
106
|
|
|
|
51
|
|
|
|
|
7972
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
51
|
|
|
51
|
|
378
|
use warnings; |
|
|
51
|
|
|
|
|
114
|
|
|
|
51
|
|
|
|
|
3453
|
|
|
16
|
51
|
|
|
51
|
|
303
|
use strict; |
|
|
51
|
|
|
|
|
125
|
|
|
|
51
|
|
|
|
|
7132
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my @constants = qw/XMLNS SCHEMA1999 SCHEMA2000 SCHEMA2001 SCHEMA2001i/; |
|
19
|
|
|
|
|
|
|
our @EXPORT = qw/pack_type unpack_type/; |
|
20
|
|
|
|
|
|
|
our @EXPORT_OK = |
|
21
|
|
|
|
|
|
|
( qw/pack_id unpack_id odd_elements even_elements type_of_node |
|
22
|
|
|
|
|
|
|
escape duration2secs add_duration/ |
|
23
|
|
|
|
|
|
|
, @constants |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
our %EXPORT_TAGS = (constants => \@constants); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use constant |
|
28
|
51
|
|
|
|
|
6583
|
{ XMLNS => 'http://www.w3.org/XML/1998/namespace' |
|
29
|
|
|
|
|
|
|
, SCHEMA1999 => 'http://www.w3.org/1999/XMLSchema' |
|
30
|
|
|
|
|
|
|
, SCHEMA2000 => 'http://www.w3.org/2000/10/XMLSchema' |
|
31
|
|
|
|
|
|
|
, SCHEMA2001 => 'http://www.w3.org/2001/XMLSchema' |
|
32
|
|
|
|
|
|
|
, SCHEMA2001i => 'http://www.w3.org/2001/XMLSchema-instance' |
|
33
|
51
|
|
|
51
|
|
326
|
}; |
|
|
51
|
|
|
|
|
177
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
51
|
|
|
51
|
|
28451
|
use Log::Report 'xml-compile'; |
|
|
51
|
|
|
|
|
5191757
|
|
|
|
51
|
|
|
|
|
291
|
|
|
36
|
51
|
|
|
51
|
|
18387
|
use POSIX qw/mktime/; |
|
|
51
|
|
|
|
|
98
|
|
|
|
51
|
|
|
|
|
380
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub pack_type($;$) |
|
40
|
10561
|
100
|
100
|
10561
|
1
|
88999
|
{ @_==1 ? $_[0] |
|
|
|
50
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
: !defined $_[0] || !length $_[0] ? $_[1] |
|
42
|
|
|
|
|
|
|
: "{$_[0]}$_[1]" |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
12221
|
100
|
|
12221
|
1
|
103781
|
sub unpack_type($) { $_[0] =~ m/^\{(.*?)\}(.*)$/ ? ($1, $2) : ('', $_[0]) } |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
1
|
0
|
sub pack_id($$) { "$_[0]#$_[1]" } |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
779
|
|
|
779
|
1
|
3745
|
sub unpack_id($) { split /\#/, $_[0], 2 } |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
908
|
100
|
|
908
|
1
|
1371
|
sub odd_elements(@) { my $i = 0; map {$i++ % 2 ? $_ : ()} @_ } |
|
|
908
|
|
|
|
|
1970
|
|
|
|
1482
|
|
|
|
|
4352
|
|
|
56
|
484
|
100
|
|
484
|
1
|
696
|
sub even_elements(@) { my $i = 0; map {$i++ % 2 ? () : $_} @_ } |
|
|
484
|
|
|
|
|
1280
|
|
|
|
640
|
|
|
|
|
1792
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub type_of_node($) |
|
60
|
1355
|
50
|
|
1355
|
1
|
3169
|
{ my $node = shift or return (); |
|
61
|
1355
|
|
|
|
|
14001
|
pack_type $node->namespaceURI, $node->localName; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
51
|
|
|
51
|
|
26320
|
use constant SECOND => 1; |
|
|
51
|
|
|
|
|
272
|
|
|
|
51
|
|
|
|
|
5451
|
|
|
66
|
51
|
|
|
51
|
|
473
|
use constant MINUTE => 60 * SECOND; |
|
|
51
|
|
|
|
|
151
|
|
|
|
51
|
|
|
|
|
3705
|
|
|
67
|
51
|
|
|
51
|
|
402
|
use constant HOUR => 60 * MINUTE; |
|
|
51
|
|
|
|
|
150
|
|
|
|
51
|
|
|
|
|
3398
|
|
|
68
|
51
|
|
|
51
|
|
299
|
use constant DAY => 24 * HOUR; |
|
|
51
|
|
|
|
|
150
|
|
|
|
51
|
|
|
|
|
3544
|
|
|
69
|
51
|
|
|
51
|
|
313
|
use constant MONTH => 30.4 * DAY; |
|
|
51
|
|
|
|
|
155
|
|
|
|
51
|
|
|
|
|
3249
|
|
|
70
|
51
|
|
|
51
|
|
336
|
use constant YEAR => 365.256 * DAY; |
|
|
51
|
|
|
|
|
1877
|
|
|
|
51
|
|
|
|
|
25307
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $duration = qr/ |
|
73
|
|
|
|
|
|
|
^ (\-?) P (?:([0-9]+)Y)? (?:([0-9]+)M)? (?:([0-9]+)D)? |
|
74
|
|
|
|
|
|
|
(?:T (?:([0-9]+)H)? (?:([0-9]+)M)? (?:([0-9]+(?:\.[0-9]+)?)S)? |
|
75
|
|
|
|
|
|
|
)?$/x; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub duration2secs($) |
|
78
|
18
|
50
|
|
18
|
1
|
345601
|
{ my $stamp = shift or return undef; |
|
79
|
|
|
|
|
|
|
|
|
80
|
18
|
50
|
|
|
|
321
|
$stamp =~ $duration |
|
81
|
|
|
|
|
|
|
or error __x"illegal duration format: {d}", d => $stamp; |
|
82
|
|
|
|
|
|
|
|
|
83
|
18
|
100
|
50
|
|
|
452
|
($1 eq '-' ? -1 : 1) |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
84
|
|
|
|
|
|
|
* ( ($2 // 0) * YEAR |
|
85
|
|
|
|
|
|
|
+ ($3 // 0) * MONTH |
|
86
|
|
|
|
|
|
|
+ ($4 // 0) * DAY |
|
87
|
|
|
|
|
|
|
+ ($5 // 0) * HOUR |
|
88
|
|
|
|
|
|
|
+ ($6 // 0) * MINUTE |
|
89
|
|
|
|
|
|
|
+ ($7 // 0) * SECOND |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub add_duration($;$) |
|
95
|
8
|
50
|
|
8
|
1
|
3527
|
{ my $stamp = shift or return; |
|
96
|
8
|
|
33
|
|
|
46
|
my ($secs, $min, $hour, $mday, $mon, $year) = gmtime(shift // time); |
|
97
|
|
|
|
|
|
|
|
|
98
|
8
|
50
|
|
|
|
81
|
$stamp =~ $duration |
|
99
|
|
|
|
|
|
|
or error __x"illegal duration format: {d}", d => $stamp; |
|
100
|
|
|
|
|
|
|
|
|
101
|
8
|
100
|
|
|
|
25
|
my $sign = $1 eq '-' ? -1 : 1; |
|
102
|
8
|
|
100
|
|
|
156
|
mktime |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$secs + $sign*($7//0) |
|
104
|
|
|
|
|
|
|
, $min + $sign*($6//0) |
|
105
|
|
|
|
|
|
|
, $hour + $sign*($5//0) |
|
106
|
|
|
|
|
|
|
, $mday + $sign*($4//0) |
|
107
|
|
|
|
|
|
|
, $mon + $sign*($3//0) |
|
108
|
|
|
|
|
|
|
, $year + $sign*($2//0) |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |