| 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
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | $impclass = "URI::urn"; | |||||||||||||||||||||||||||
| 23 | 2 | ▶ | if ($nid =~ /^[A-Za-z\d][A-Za-z\d\-]*\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$@ and not $@ =~ /Can\'t locate.*in \@INC/
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/
| |||||||||||||||||||||||||||||
| 38 | 2 | $@ = $_old_error; | |||||||||||||||||||||||||||
| 39 | 2 | ▶ | $impclass = "URI::urn" unless @{"${impclass}::ISA"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | carp("Illegal namespace identifier '$nid' for URN '$self'") if $^W; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 80 | 1 | my $v = $opaque; | |||||||||||||||||||||||||||
| 81 | 1 | my $new = shift; | |||||||||||||||||||||||||||
| 82 | 1 | ▶ | if (defined $new) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
not $nid =~ /[A-Z]/ or $nid =~ /%/
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 =~ /%/
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $new = $new->clone if $new == $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | $new->nid(lc($nid)); | |||||||||||||||||||||||||||
| 101 | 0 | return $new; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | 1; | |||||||||||||||||||||||||||