| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyrights 2006-2019 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.02. |
|
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
|
51
|
|
|
51
|
|
2958726
|
use vars '$VERSION'; |
|
|
51
|
|
|
|
|
547
|
|
|
|
51
|
|
|
|
|
2490
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.62'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
51
|
|
|
51
|
|
295
|
use base 'Exporter'; |
|
|
51
|
|
|
|
|
101
|
|
|
|
51
|
|
|
|
|
6897
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
51
|
|
|
51
|
|
384
|
use warnings; |
|
|
51
|
|
|
|
|
135
|
|
|
|
51
|
|
|
|
|
1497
|
|
|
16
|
51
|
|
|
51
|
|
253
|
use strict; |
|
|
51
|
|
|
|
|
83
|
|
|
|
51
|
|
|
|
|
5519
|
|
|
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
|
|
|
|
|
5204
|
{ 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
|
|
321
|
}; |
|
|
51
|
|
|
|
|
104
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
51
|
|
|
51
|
|
23433
|
use Log::Report 'xml-compile'; |
|
|
51
|
|
|
|
|
4470422
|
|
|
|
51
|
|
|
|
|
325
|
|
|
36
|
51
|
|
|
51
|
|
13398
|
use POSIX qw/mktime/; |
|
|
51
|
|
|
|
|
99
|
|
|
|
51
|
|
|
|
|
295
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub pack_type($;$) |
|
40
|
10316
|
100
|
100
|
10316
|
1
|
79641
|
{ @_==1 ? $_[0] |
|
|
|
50
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
: !defined $_[0] || !length $_[0] ? $_[1] |
|
42
|
|
|
|
|
|
|
: "{$_[0]}$_[1]" |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
12078
|
100
|
|
12078
|
1
|
76212
|
sub unpack_type($) { $_[0] =~ m/^\{(.*?)\}(.*)$/ ? ($1, $2) : ('', $_[0]) } |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
1
|
0
|
sub pack_id($$) { "$_[0]#$_[1]" } |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
771
|
|
|
771
|
1
|
3188
|
sub unpack_id($) { split /\#/, $_[0], 2 } |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
887
|
100
|
|
887
|
1
|
1131
|
sub odd_elements(@) { my $i = 0; map {$i++ % 2 ? $_ : ()} @_ } |
|
|
887
|
|
|
|
|
1648
|
|
|
|
1456
|
|
|
|
|
3569
|
|
|
56
|
470
|
100
|
|
470
|
1
|
597
|
sub even_elements(@) { my $i = 0; map {$i++ % 2 ? () : $_} @_ } |
|
|
470
|
|
|
|
|
1049
|
|
|
|
626
|
|
|
|
|
1572
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub type_of_node($) |
|
60
|
1321
|
50
|
|
1321
|
1
|
2845
|
{ my $node = shift or return (); |
|
61
|
1321
|
|
|
|
|
10107
|
pack_type $node->namespaceURI, $node->localName; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
51
|
|
|
51
|
|
17445
|
use constant SECOND => 1; |
|
|
51
|
|
|
|
|
120
|
|
|
|
51
|
|
|
|
|
4179
|
|
|
66
|
51
|
|
|
51
|
|
316
|
use constant MINUTE => 60 * SECOND; |
|
|
51
|
|
|
|
|
95
|
|
|
|
51
|
|
|
|
|
2842
|
|
|
67
|
51
|
|
|
51
|
|
317
|
use constant HOUR => 60 * MINUTE; |
|
|
51
|
|
|
|
|
123
|
|
|
|
51
|
|
|
|
|
3283
|
|
|
68
|
51
|
|
|
51
|
|
413
|
use constant DAY => 24 * HOUR; |
|
|
51
|
|
|
|
|
112
|
|
|
|
51
|
|
|
|
|
2887
|
|
|
69
|
51
|
|
|
51
|
|
303
|
use constant MONTH => 30.4 * DAY; |
|
|
51
|
|
|
|
|
111
|
|
|
|
51
|
|
|
|
|
2704
|
|
|
70
|
51
|
|
|
51
|
|
282
|
use constant YEAR => 365.256 * DAY; |
|
|
51
|
|
|
|
|
99
|
|
|
|
51
|
|
|
|
|
18758
|
|
|
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
|
1176
|
{ my $stamp = shift or return undef; |
|
79
|
|
|
|
|
|
|
|
|
80
|
18
|
50
|
|
|
|
193
|
$stamp =~ $duration |
|
81
|
|
|
|
|
|
|
or error __x"illegal duration format: {d}", d => $stamp; |
|
82
|
|
|
|
|
|
|
|
|
83
|
18
|
100
|
100
|
|
|
365
|
($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
|
3441
|
{ my $stamp = shift or return; |
|
96
|
8
|
|
33
|
|
|
40
|
my ($secs, $min, $hour, $mday, $mon, $year) = gmtime(shift // time); |
|
97
|
|
|
|
|
|
|
|
|
98
|
8
|
50
|
|
|
|
82
|
$stamp =~ $duration |
|
99
|
|
|
|
|
|
|
or error __x"illegal duration format: {d}", d => $stamp; |
|
100
|
|
|
|
|
|
|
|
|
101
|
8
|
100
|
|
|
|
27
|
my $sign = $1 eq '-' ? -1 : 1; |
|
102
|
8
|
|
100
|
|
|
171
|
mktime |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
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
|
|
|
|
|
|
|
1; |