Compile/Util.pm

filter: Statementstmt 98.4% 63 / 64 Branchbran 75.0% 18 / 24 Conditioncond 96.5% 28 / 29 MC/DCmcdc 93.3% 14 / 15 Subroutinesub 95.2% 20 / 21 Podpod 100% 9 / 9 totaltotal 93.8% 152 / 162 CC 27 SCAR 17.5
CC
27
Cov
93%
add_duration
11.2
duration2secs
10.1
pack_type
4.0
CRAP 5.8
« Compile/Translate/Reader.pm ↑ Summary Compile/Schema/BuiltInTypes.pm »
1 # Copyrights 2006-2024 by [Mark Overmeer <markov@cpan.org>].
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 51 our $VERSION = '1.64';
11 }
12  
13 51 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 51 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 51 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 51 my @constants = qw/XMLNS SCHEMA1999 SCHEMA2000 SCHEMA2001 SCHEMA2001i/;
19 51 our @EXPORT = qw/pack_type unpack_type/;
20 51 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 51 our %EXPORT_TAGS = (constants => \@constants);
26  
27 use constant
28 51 ▶ { XMLNS => 'http://www.w3.org/XML/1998/namespace'
Subroutine BEGIN: called CC=1 SCAR=0.0
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 };
34  
35 51 ▶use Log::Report 'xml-compile';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 51 ▶use POSIX qw/mktime/;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38  
39 sub pack_type($;$)
40 10563 ▶{ @_==1 ? $_[0]
Subroutine pack_type: called CC=4 SCAR=13.9
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
@_ == 1 ? : 0 10563 10563
!(defined $_[0] && length $_[0]) ? : 1252 9311 10563
Condition100%3/3
defined $_[0] && length $_[0]
!ll&&!rl&&r
1198549311
MC/DC100%2/2
defined $_[0] && length $_[0]
defined $_[0] length $_[0]
Truth table100%3/3
A && B
A= defined $_[0]B= length $_[0]
ABresult
0X0
100
111
41 : !defined $_[0] || !length $_[0] ? $_[1]
42 : "{$_[0]}$_[1]"
43 }
44  
45  
46 12221 ▶sub unpack_type($) { $_[0] =~ m/^\{(.*?)\}(.*)$/ ? ($1, $2) : ('', $_[0]) }
Subroutine unpack_type: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^\{(.*?)\}(.*)$/ ? : 10005 2216 12221
47  
48  
49 0 ▶sub pack_id($$) { "$_[0]#$_[1]" }
Subroutine pack_id: not called CC=1 SCAR=6.9
Pod documented
50  
51  
52 779 ▶sub unpack_id($) { split /\#/, $_[0], 2 }
Subroutine unpack_id: called CC=1 SCAR=0.0
Pod documented
53  
54  
55 908 ▶sub odd_elements(@) { my $i = 0; map {$i++ % 2 ? $_ : ()} @_ }
Subroutine odd_elements: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$i++ % 2 ? : 741 741 1482
56 484 ▶sub even_elements(@) { my $i = 0; map {$i++ % 2 ? () : $_} @_ }
Subroutine even_elements: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$i++ % 2 ? : 320 320 640
57  
58  
59 sub type_of_node($)
60 1357 ▶{ my $node = shift or return ();
Subroutine type_of_node: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $node = shift() or return () 1357 0 1357
61 1357 pack_type $node->namespaceURI, $node->localName;
62 }
63  
64  
65 51 ▶use constant SECOND => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 51 ▶use constant MINUTE => 60 * SECOND;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 51 ▶use constant HOUR => 60 * MINUTE;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 51 ▶use constant DAY => 24 * HOUR;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 51 ▶use constant MONTH => 30.4 * DAY;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 51 ▶use constant YEAR => 365.256 * DAY;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 51 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 ▶{ my $stamp = shift or return undef;
Subroutine duration2secs: called CC=10 SCAR=23.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $stamp = shift() or return undef 18 0 18
79  
80 18 ▶ $stamp =~ $duration
Branch: 1 branch
BranchTrueFalseTotal
$stamp =~ /$duration/ or &error(&__x("illegal duration format: {d}", "d", $stamp)) 18 0 18
81 or error __x"illegal duration format: {d}", d => $stamp;
82  
83 18 ▶ ($1 eq '-' ? -1 : 1)
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '-' ? : 1 17 18
Condition100%12/12
$2 // 0
l!l
135
$3 // 0
l!l
126
$4 // 0
l!l
135
$5 // 0
l!l
216
$6 // 0
l!l
315
$7 // 0
l!l
216
MC/DC100%1/1
$2 // 0
$2
MC/DC100%1/1
$3 // 0
$3
MC/DC100%1/1
$4 // 0
$4
MC/DC100%1/1
$5 // 0
$5
MC/DC100%1/1
$6 // 0
$6
MC/DC100%1/1
$7 // 0
$7
Truth table100%2/2
A
A= $2
Aresult
11
00
Truth table100%2/2
A
A= $3
Aresult
11
00
Truth table100%2/2
A
A= $4
Aresult
11
00
Truth table100%2/2
A
A= $5
Aresult
11
00
Truth table100%2/2
A
A= $6
Aresult
11
00
Truth table100%2/2
A
A= $7
Aresult
11
00
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 ▶{ my $stamp = shift or return;
Subroutine add_duration: called CC=11 SCAR=24.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $stamp = shift() or return 8 0 8
96 8 ▶ my ($secs, $min, $hour, $mday, $mon, $year) = gmtime(shift // time);
Condition50%1/2
shift() // time
l!l
80
MC/DC0%0/1
shift() // time
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
97  
98 8 ▶ $stamp =~ $duration
Branch: 1 branch
BranchTrueFalseTotal
$stamp =~ /$duration/ or &error(&__x("illegal duration format: {d}", "d", $stamp)) 8 0 8
99 or error __x"illegal duration format: {d}", d => $stamp;
100  
101 8 ▶ my $sign = $1 eq '-' ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '-' ? : 1 7 8
102 8 ▶ mktime
Condition100%12/12
$7 // 0
l!l
26
$6 // 0
l!l
35
$5 // 0
l!l
26
$4 // 0
l!l
44
$3 // 0
l!l
35
$2 // 0
l!l
35
MC/DC100%1/1
$7 // 0
$7
MC/DC100%1/1
$6 // 0
$6
MC/DC100%1/1
$5 // 0
$5
MC/DC100%1/1
$4 // 0
$4
MC/DC100%1/1
$3 // 0
$3
MC/DC100%1/1
$2 // 0
$2
Truth table100%2/2
A
A= $7
Aresult
11
00
Truth table100%2/2
A
A= $6
Aresult
11
00
Truth table100%2/2
A
A= $5
Aresult
11
00
Truth table100%2/2
A
A= $4
Aresult
11
00
Truth table100%2/2
A
A= $3
Aresult
11
00
Truth table100%2/2
A
A= $2
Aresult
11
00
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 51 1;
« Compile/Translate/Reader.pm ↑ Summary Compile/Schema/BuiltInTypes.pm »