blib/lib/Web/ID/Util.pm

filter: Statementstmt 76.8% 63 / 82 Branchbran 29.1% 7 / 24 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 16 / 16 Podpod 100% 4 / 4 totaltotal 65.9% 93 / 141 CC 17 SCAR 32.4
CC
17
Cov
63%
make_bigint_from_node
60.4
u
4.6
get_trine_model
2.1
CRAP 25.6
« lib/Web/ID/Certificate/Generator.pm ↑ Summary blib/lib/Web/ID.pm »
1 package Web::ID::Util;
2  
3 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 $Web::ID::Util::AUTHORITY = 'cpan:TOBYINK';
9 3 $Web::ID::Util::VERSION = '1.927';
10 }
11  
12 3 ▶use match::simple qw/match/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Math::BigInt 0 try => 'GMP';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use RDF::Trine::NamespaceMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use List::MoreUtils qw(:all !true !false);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use Exporter::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 our @EXPORT = qw(
20 make_bigint_from_node get_trine_model u uu
21 true false read_only read_write
22 );
23 our @EXPORT_OK = (
24 @EXPORT,
25 3 grep {!/^(true|false)$/} @List::MoreUtils::EXPORT_OK
26 );
27 3 our @ISA = qw( Exporter::Tiny );
28  
29 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 read_only => 'ro',
31 read_write => 'rw',
32 3 };
33  
34 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 true => !!1,
36 false => !!0,
37 3 };
38  
39 sub u (;$)
40 53 ▶{
Subroutine u: called CC=4 SCAR=15.2
Pod documented
41 53 ▶ state $namespaces //= RDF::Trine::NamespaceMap->new({
Condition66%2/3
state $namespaces //= "RDF::Trine::NamespaceMap"->new({"rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs", "http://www.w3.org/2000/01/rdf-schema#", "owl", "http://www.w3.org/2002/07/owl#", "xsd", "http://www.w3.org/2001/XMLSchema#", "foaf", "http://xmlns.com/foaf/0.1/", "cert", "http://www.w3.org/ns/auth/cert#", "rsa", "http://www.w3.org/ns/auth/rsa#"})
l!l&&r!l&&!r
5210
MC/DC0%0/2
state $namespaces //= "RDF::Trine::NamespaceMap"->new({"rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs", "http://www.w3.org/2000/01/rdf-schema#", "owl", "http://www.w3.org/2002/07/owl#", "xsd", "http://www.w3.org/2001/XMLSchema#", "foaf", "http://xmlns.com/foaf/0.1/", "cert", "http://www.w3.org/ns/auth/cert#", "rsa", "http://www.w3.org/ns/auth/rsa#"})
state $namespaces "RDF::Trine::NamespaceMap"->new({"rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs", "http://www.w3.org/2000/01/rdf-schema#", "owl", "http://www.w3.org/2002/07/owl#", "xsd", "http://www.w3.org/2001/XMLSchema#", "foaf", "http://xmlns.com/foaf/0.1/", "cert", "http://www.w3.org/ns/auth/cert#", "rsa", "http://www.w3.org/ns/auth/rsa#"})
Truth table66%2/3
A //= B
A= state $namespacesB= "RDF::Trine::NamespaceMap"->new({"rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs", "http://www.w3.org/2000/01/rdf-schema#", "owl", "http://www.w3.org/2002/07/owl#", "xsd", "http://www.w3.org/2001/XMLSchema#", "foaf", "http://xmlns.com/foaf/0.1/", "cert", "http://www.w3.org/ns/auth/cert#", "rsa", "http://www.w3.org/ns/auth/rsa#"})
ABresult
1X1
011
000
42 rdf => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
43 rdfs => 'http://www.w3.org/2000/01/rdf-schema#',
44 owl => 'http://www.w3.org/2002/07/owl#',
45 xsd => 'http://www.w3.org/2001/XMLSchema#',
46 foaf => 'http://xmlns.com/foaf/0.1/',
47 cert => 'http://www.w3.org/ns/auth/cert#',
48 rsa => 'http://www.w3.org/ns/auth/rsa#',
49 });
50
51 53 ▶ if (@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 53 0 53
52 {
53 53 ▶ my $rv = $namespaces->uri(@_)
Branch: 1 branch
BranchTrueFalseTotal
my $rv = $namespaces->uri(@_) or confess("couldn't expand term $_[0]") 53 0 53
54 or confess "couldn't expand term $_[0]";
55 53 return $rv;
56 }
57
58 0 return $namespaces;
59 }
60  
61 sub uu ($)
62 28 ▶{
Subroutine uu: called CC=1 SCAR=0.0
Pod documented
63 28 return u(shift)->uri;
64 }
65  
66 sub get_trine_model
67 7 ▶{
Subroutine get_trine_model: called CC=2 SCAR=7.2
Pod documented
68 7 my ($uri, $model) = @_;
69
70 7 ▶ $model //= "RDF::Trine::Model"->new;
Condition33%1/3
$model //= "RDF::Trine::Model"->new
l!l&&r!l&&!r
700
MC/DC0%0/2
$model //= "RDF::Trine::Model"->new
$model "RDF::Trine::Model"->new
Truth table33%1/3
A //= B
A= $modelB= "RDF::Trine::Model"->new
ABresult
1X1
011
000
71 7 eval {
72 7 "RDF::Trine::Parser"->parse_url_into_model($uri, $model);
73 };
74
75 7 return $model;
76 }
77  
78 sub make_bigint_from_node
79 10 ▶{
Subroutine make_bigint_from_node: called CC=13 SCAR=41.0
Pod documented
80 10 my ($node, %opts) = @_;
81
82 10 state $test_hex = [
83 uu('cert:hex'),
84 uu('xsd:hexBinary'),
85 ];
86
87 10 state $test_unsigned = [
88 uu('cert:decimal'),
89 uu('cert:int'),
90 uu('xsd:unsignedLong'),
91 uu('xsd:unsignedInt'),
92 uu('xsd:unsignedShort'),
93 uu('xsd:unsignedByte'),
94 uu('xsd:positiveInteger'),
95 uu('xsd:nonNegitiveInteger'),
96 ];
97
98 10 state $test_signed = [
99 uu('xsd:integer'),
100 uu('xsd:negitiveInteger'),
101 uu('xsd:nonPositiveInteger'),
102 uu('xsd:long'),
103 uu('xsd:short'),
104 uu('xsd:int'),
105 uu('xsd:byte'),
106 ];
107
108 10 state $test_decimal = uu('xsd:decimal');
109
110 10 ▶ if ($node->is_literal)
Branch: 1 branch
BranchTrueFalseTotal
if ($node->is_literal) 10 0 10
111 {
112 10 for ($node->literal_datatype)
113 {
114 10 ▶ if (match $_, $test_hex)
Branch: 1 branch
BranchTrueFalseTotal
if (match($_, $test_hex)) 5 5 10
115 {
116 5 ( my $hex = $node->literal_value ) =~ s/[^0-9A-F]//ig;
117 5 return "Math::BigInt"->from_hex("0x$hex");
118 }
119
120 5 ▶ if (match $_, $test_unsigned)
Branch: 1 branch
BranchTrueFalseTotal
if (match($_, $test_unsigned)) 0 5 5
121 {
122 0 ( my $dec = $node->literal_value ) =~ s/[^0-9]//ig;
123 0 return "Math::BigInt"->new("$dec");
124 }
125
126 5 ▶ if (match $_, $test_signed)
Branch: 1 branch
BranchTrueFalseTotal
if (match($_, $test_signed)) 5 0 5
127 {
128 5 ( my $dec = $node->literal_value ) =~ s/[^0-9-]//ig;
129 5 return "Math::BigInt"->new("$dec");
130 }
131
132 0 ▶ if (match $_, $test_decimal)
Branch: 1 branch
BranchTrueFalseTotal
if (match($_, $test_decimal)) 0 0 0
133 {
134 0 my ($dec, $frac) = split /\./, $node->literal_value, 2;
135 0 ▶ warn "Ignoring fractional part of xsd:decimal number."
Branch: 1 branch
BranchTrueFalseTotal
if defined $frac 0 0 0
136 if defined $frac;
137
138 0 $dec =~ s/[^0-9-]//ig;
139 0 return "Math::BigInt"->new("$dec");
140 }
141
142 0 ▶ if (match $_, undef)
Branch: 1 branch
BranchTrueFalseTotal
if (match($_, undef)) 0 0 0
143 {
144 0 $opts{'fallback'} = $node;
145 }
146 }
147 }
148
149 0 ▶ if (defined( my $node = $opts{'fallback'} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $node = $opts{"fallback"}) and $opts{"fallback"}->is_literal) 0 0 0
Condition0%0/3
defined(my $node = $opts{"fallback"}) and $opts{"fallback"}->is_literal
!ll&&!rl&&r
000
MC/DC0%0/2
defined(my $node = $opts{"fallback"}) and $opts{"fallback"}->is_literal
defined(my $node = $opts{"fallback"}) $opts{"fallback"}->is_literal
Truth table0%0/3
A and B
A= defined(my $node = $opts{"fallback"})B= $opts{"fallback"}->is_literal
ABresult
0X0
100
111
150 and $opts{'fallback'}->is_literal)
151 {
152 0 ▶ if ($opts{'fallback_type'} eq 'hex')
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'fallback_type'} eq 'hex') { } 0 0 0
153 {
154 0 (my $hex = $node->literal_value) =~ s/[^0-9A-F]//ig;
155 0 return "Math::BigInt"->from_hex("0x$hex");
156 }
157 else # dec
158 {
159 0 my ($dec, $frac) = split /\./, $node->literal_value, 2;
160 0 ▶ warn "Ignoring fractional part of xsd:decimal number."
Branch: 1 branch
BranchTrueFalseTotal
if defined $frac 0 0 0
161 if defined $frac;
162
163 0 $dec =~ s/[^0-9]//ig;
164 0 return "Math::BigInt"->new("$dec");
165 }
166 }
167
168 0 return;
169 }
170  
171  
172 3 __PACKAGE__
173 __END__
« lib/Web/ID/Certificate/Generator.pm ↑ Summary blib/lib/Web/ID.pm »