URI/urn.pm

filter: Statementstmt 82.1% 60 / 73 Branchbran 53.5% 15 / 28 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.9% 10 / 11 Podpod 33.3% 1 / 3 totaltotal 70.4% 88 / 125 CC 17 SCAR 19.9
CC
17
Cov
72%
canonical
20.0
_init
9.6
nss
4.0
CRAP 7.3
« URI/irc.pm ↑ Summary URI/_punycode.pm »
1 package URI::urn; # RFC 2141
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '5.40';
7  
8 2 ▶use parent 'URI';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Carp qw(carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 my %implementor;
13  
14 3 ▶sub _init {
Subroutine _init: called CC=9 SCAR=22.6
15 3 my $class = shift;
16 3 my $self = $class->SUPER::_init(@_);
17 3 my $nid = $self->nid;
18  
19 3 my $impclass = $implementor{$nid};
20 3 ▶ return $impclass->_urn_init($self, $nid) if $impclass;
Branch: 1 branch
BranchTrueFalseTotal
if $impclass 1 2 3
21  
22 2 $impclass = "URI::urn";
23 2 ▶ if ($nid =~ /^[A-Za-z\d][A-Za-z\d\-]*\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nid =~ /^[A-Za-z\d][A-Za-z\d\-]*\z/) { } 2 0 2
24 2 my $id = $nid;
25  
26 # make it a legal perl identifier
27 2 $id =~ s/-/_/g;
28 2 ▶ $id = "_$id" if $id =~ /^\d/;
Branch: 1 branch
BranchTrueFalseTotal
if $id =~ /^\d/ 0 2 2
29  
30 2 $impclass = "URI::urn::$id";
31 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶ unless (@{"${impclass}::ISA"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{"${impclass}::ISA";}) 2 0 2
33  
34 # Try to load it
35 2 my $_old_error = $@;
36 2 eval "require $impclass";
37 2 ▶ die $@ if $@ && $@ !~ /Can\'t locate.*in \@INC/;
Branch: 1 branch
BranchTrueFalseTotal
if $@ and not $@ =~ /Can\'t locate.*in \@INC/ 0 2 2
Condition66%2/3
$@ and not $@ =~ /Can\'t locate.*in \@INC/
!ll&&!rl&&r
110
MC/DC0%0/2
$@ and not $@ =~ /Can\'t locate.*in \@INC/
$@ not $@ =~ /Can\'t locate.*in \@INC/
Truth table66%2/3
A and not(B)
A= $@B= not $@ =~ /Can\'t locate.*in \@INC/
ABresult
0X0
100
111
38 2 $@ = $_old_error;
39 2 ▶ $impclass = "URI::urn" unless @{"${impclass}::ISA"};
Branch: 1 branch
BranchTrueFalseTotal
unless @{"${impclass}::ISA";} 1 1 2
40 }
41 }
42 else {
43 0 ▶ carp("Illegal namespace identifier '$nid' for URN '$self'") if $^W;
Branch: 1 branch
BranchTrueFalseTotal
if $^W 0 0 0
44 }
45 2 $implementor{$nid} = $impclass;
46 2 return $impclass->_urn_init($self, $nid);
47 }
48  
49 3 ▶sub _urn_init {
Subroutine _urn_init: called CC=1 SCAR=0.0
50 3 my ($class, $self) = @_;
51 3 bless $self, $class;
52 }
53  
54 4 ▶sub _nid {
Subroutine _nid: called CC=2 SCAR=8.7
55 4 my $self = shift;
56 4 my $opaque = $self->opaque;
57 4 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 4 4
58 0 my $v = $opaque;
59 0 my $new = shift;
60 0 $v =~ s/[^:]*/$new/;
61 0 $self->opaque($v);
62  
63 # XXX possible rebless
64 }
65 4 $opaque =~ s/:.*//s;
66 4 return $opaque;
67 }
68  
69 4 ▶sub nid { # namespace identifier
Subroutine nid: called CC=2 SCAR=7.0
Pod undocumented
70 4 my $self = shift;
71 4 my $nid = $self->_nid(@_);
72 4 ▶ $nid = lc($nid) if defined($nid);
Branch: 1 branch
BranchTrueFalseTotal
if defined $nid 4 0 4
73 4 return $nid;
74 }
75  
76 5 ▶sub nss { # namespace specific string
Subroutine nss: called CC=4 SCAR=13.9
Pod undocumented
77 5 my $self = shift;
78 5 my $opaque = $self->opaque;
79 5 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 4 5
80 1 my $v = $opaque;
81 1 my $new = shift;
82 1 ▶ if (defined $new) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) { } 1 0 1
83 1 $v =~ s/(:|\z).*/:$new/;
84 }
85 else {
86 0 $v =~ s/:.*//s;
87 }
88 1 $self->opaque($v);
89 }
90 5 ▶ return undef unless $opaque =~ s/^[^:]*://;
Branch: 1 branch
BranchTrueFalseTotal
unless $opaque =~ s/^[^:]*:// 2 3 5
91 3 return $opaque;
92 }
93  
94 0 ▶sub canonical {
Subroutine canonical: not called CC=4 SCAR=30.0
Pod documented
95 0 my $self = shift;
96 0 my $nid = $self->_nid;
97 0 my $new = $self->SUPER::canonical;
98 0 ▶ return $new if $nid !~ /[A-Z]/ || $nid =~ /%/;
Branch: 1 branch
BranchTrueFalseTotal
if not $nid =~ /[A-Z]/ or $nid =~ /%/ 0 0 0
Condition0%0/3
not $nid =~ /[A-Z]/ or $nid =~ /%/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $nid =~ /[A-Z]/ or $nid =~ /%/
not $nid =~ /[A-Z]/ $nid =~ /%/
Truth table0%0/3
not(A) or B
A= not $nid =~ /[A-Z]/B= $nid =~ /%/
ABresult
1X1
011
000
99 0 ▶ $new = $new->clone if $new == $self;
Branch: 1 branch
BranchTrueFalseTotal
if $new == $self 0 0 0
100 0 $new->nid(lc($nid));
101 0 return $new;
102 }
103  
104 2 1;
« URI/irc.pm ↑ Summary URI/_punycode.pm »