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
|
|
2502061
|
use vars '$VERSION'; |
|
51
|
|
|
|
|
486
|
|
|
51
|
|
|
|
|
2237
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.63'; |
12
|
|
|
|
|
|
|
|
13
|
51
|
|
|
51
|
|
252
|
use base 'Exporter'; |
|
51
|
|
|
|
|
92
|
|
|
51
|
|
|
|
|
5939
|
|
14
|
|
|
|
|
|
|
|
15
|
51
|
|
|
51
|
|
275
|
use warnings; |
|
51
|
|
|
|
|
89
|
|
|
51
|
|
|
|
|
1313
|
|
16
|
51
|
|
|
51
|
|
219
|
use strict; |
|
51
|
|
|
|
|
79
|
|
|
51
|
|
|
|
|
4732
|
|
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
|
|
|
|
|
4638
|
{ 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
|
|
270
|
}; |
|
51
|
|
|
|
|
75
|
|
34
|
|
|
|
|
|
|
|
35
|
51
|
|
|
51
|
|
19206
|
use Log::Report 'xml-compile'; |
|
51
|
|
|
|
|
3819351
|
|
|
51
|
|
|
|
|
277
|
|
36
|
51
|
|
|
51
|
|
11582
|
use POSIX qw/mktime/; |
|
51
|
|
|
|
|
80
|
|
|
51
|
|
|
|
|
272
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub pack_type($;$) |
40
|
10317
|
100
|
100
|
10317
|
1
|
68180
|
{ @_==1 ? $_[0] |
|
|
50
|
|
|
|
|
|
41
|
|
|
|
|
|
|
: !defined $_[0] || !length $_[0] ? $_[1] |
42
|
|
|
|
|
|
|
: "{$_[0]}$_[1]" |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
12078
|
100
|
|
12078
|
1
|
64799
|
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
|
2929
|
sub unpack_id($) { split /\#/, $_[0], 2 } |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
887
|
100
|
|
887
|
1
|
998
|
sub odd_elements(@) { my $i = 0; map {$i++ % 2 ? $_ : ()} @_ } |
|
887
|
|
|
|
|
1398
|
|
|
1456
|
|
|
|
|
3467
|
|
56
|
470
|
100
|
|
470
|
1
|
518
|
sub even_elements(@) { my $i = 0; map {$i++ % 2 ? () : $_} @_ } |
|
470
|
|
|
|
|
929
|
|
|
626
|
|
|
|
|
1417
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub type_of_node($) |
60
|
1322
|
50
|
|
1322
|
1
|
2109
|
{ my $node = shift or return (); |
61
|
1322
|
|
|
|
|
8588
|
pack_type $node->namespaceURI, $node->localName; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
51
|
|
|
51
|
|
15196
|
use constant SECOND => 1; |
|
51
|
|
|
|
|
108
|
|
|
51
|
|
|
|
|
3610
|
|
66
|
51
|
|
|
51
|
|
258
|
use constant MINUTE => 60 * SECOND; |
|
51
|
|
|
|
|
100
|
|
|
51
|
|
|
|
|
2354
|
|
67
|
51
|
|
|
51
|
|
277
|
use constant HOUR => 60 * MINUTE; |
|
51
|
|
|
|
|
99
|
|
|
51
|
|
|
|
|
2887
|
|
68
|
51
|
|
|
51
|
|
348
|
use constant DAY => 24 * HOUR; |
|
51
|
|
|
|
|
106
|
|
|
51
|
|
|
|
|
2445
|
|
69
|
51
|
|
|
51
|
|
248
|
use constant MONTH => 30.4 * DAY; |
|
51
|
|
|
|
|
96
|
|
|
51
|
|
|
|
|
2335
|
|
70
|
51
|
|
|
51
|
|
244
|
use constant YEAR => 365.256 * DAY; |
|
51
|
|
|
|
|
75
|
|
|
51
|
|
|
|
|
15912
|
|
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
|
1058
|
{ my $stamp = shift or return undef; |
79
|
|
|
|
|
|
|
|
80
|
18
|
50
|
|
|
|
156
|
$stamp =~ $duration |
81
|
|
|
|
|
|
|
or error __x"illegal duration format: {d}", d => $stamp; |
82
|
|
|
|
|
|
|
|
83
|
18
|
100
|
100
|
|
|
291
|
($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
|
2842
|
{ my $stamp = shift or return; |
96
|
8
|
|
33
|
|
|
35
|
my ($secs, $min, $hour, $mday, $mon, $year) = gmtime(shift // time); |
97
|
|
|
|
|
|
|
|
98
|
8
|
50
|
|
|
|
70
|
$stamp =~ $duration |
99
|
|
|
|
|
|
|
or error __x"illegal duration format: {d}", d => $stamp; |
100
|
|
|
|
|
|
|
|
101
|
8
|
100
|
|
|
|
23
|
my $sign = $1 eq '-' ? -1 : 1; |
102
|
8
|
|
100
|
|
|
140
|
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; |