| 1 | package URI::WithBase; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use URI (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | our $VERSION = '5.40'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use overload '""' => "as_string", fallback => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | sub as_string; # help overload find it | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 257 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 257 | my ($class, $uri, $base) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 257 | my $ibase = $base; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 257 | ▶ | if ($base && blessed($base) && $base->isa(__PACKAGE__)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$base and builtin::blessed($base) and $base->isa(__PACKAGE__)
$base and builtin::blessed($base)
MC/DC100%3/3
$base and builtin::blessed($base) and $base->isa(__PACKAGE__)
$base
builtin::blessed($base)
$base->isa(__PACKAGE__)
Truth table100%4/4
A and B and C
A= $baseB= builtin::blessed($base)C= $base->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | $base = $base->abs; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | $ibase = $base->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 257 | bless [URI->new($uri, $ibase), $base], $class; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | sub new_abs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_abs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | my $self = $class->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | $self->abs; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | my ($str, $scheme) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | bless [URI->new($str, $scheme), undef], $class; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 10 | ▶ | sub eq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eq: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 10 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 10 | ▶ | $other = $other->[0] if blessed($other) and $other->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($other) and $other->isa(__PACKAGE__)
MC/DC50%1/2
builtin::blessed($other) and $other->isa(__PACKAGE__)
builtin::blessed($other)
$other->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= builtin::blessed($other)B= $other->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 10 | $self->[0]->eq($other); | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1012 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1012 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 1012 | my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::') + 2); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 1012 | ▶ | return if $method eq "DESTROY"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 655 | $self->[0]->$method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | sub can { # override UNIVERSAL::can | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | $self->SUPER::can(@_) || (ref($self) ? $self->[0]->can(@_) : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 86 | ▶ | sub base { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
base: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 86 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 86 | my $base = $self->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 86 | ▶ | if (@_) { # set | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | my $new_base = shift; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # ensure absoluteness | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | $new_base = $new_base->abs | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $new_base and $new_base->isa(__PACKAGE__)
MC/DC0%0/2
ref $new_base and $new_base->isa(__PACKAGE__)
ref $new_base
$new_base->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= ref $new_baseB= $new_base->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | if ref($new_base) && $new_base->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | $self->[1] = $new_base; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 86 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # The base attribute supports 'lazy' conversion from URL strings | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # to URL objects. Strings may be stored but when a string is | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # fetched it will automatically be converted to a URL object. | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # The main benefit is to make it much cheaper to say: | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # URI::WithBase->new($random_url_string, 'http:') | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 85 | ▶ | if (defined($base) && !ref($base)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $base and not ref $base
MC/DC100%2/2
defined $base and not ref $base
defined $base
not ref $base
Truth table100%3/3
A and not(B)
A= defined $baseB= not ref $base
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 63 | $base = ref($self)->new($base); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 63 | ▶ | $self->[1] = $base unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 85 | $base; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | my $base = $self->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | ▶ | $base = $base->clone if ref($base); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | bless [$self->[0]->clone, $base], ref($self); | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 82 | ▶ | sub abs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abs: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 82 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 82 | ▶ | my $base = shift || $self->base || return $self->clone; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
shift() || $self->base || (return $self->clone)
shift() or $self->base
MC/DC50%1/2
shift() || $self->base || (return $self->clone)
shift()
$self->base
Truth table66%2/3
A or B
A= shift()B= $self->base
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 77 | ▶ | $base = $base->as_string if ref($base); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 77 | bless [$self->[0]->abs($base, @_), $base], ref($self); | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 15 | ▶ | sub rel { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rel: called CC=4 SCAR=15.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 15 | ▶ | my $base = shift || $self->base || return $self->clone; | ||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
shift() || $self->base || (return $self->clone)
shift() or $self->base
MC/DC0%0/2
shift() || $self->base || (return $self->clone)
shift()
$self->base
Truth table0%0/3
A or B
A= shift()B= $self->base
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 15 | ▶ | $base = $base->as_string if ref($base); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 15 | bless [$self->[0]->rel($base, @_), $base], ref($self); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||||||||||||||||