URI/WithBase.pm

filter: Statementstmt 100% 62 / 62 Branchbran 80.7% 21 / 26 Conditioncond 76.0% 19 / 25 MC/DCmcdc 53.8% 7 / 13 Subroutinesub 100% 15 / 15 Podpod 50.0% 4 / 8 totaltotal 85.9% 128 / 149 CC 23 SCAR 14.1
CC
23
Cov
90%
base
8.2
rel
4.8
new
4.0
CRAP 4.1
« URI/URL.pm ↑ Summary URI/file/QNX.pm »
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
BranchTrueFalseTotal
if ($base and builtin::blessed($base) and $base->isa(__PACKAGE__)) 9 248 257
Condition100%6/6
$base and builtin::blessed($base) and $base->isa(__PACKAGE__)
!ll&&!rl&&r
24629
$base and builtin::blessed($base)
!ll&&!rl&&r
1648211
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__)
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
if builtin::blessed($other) and $other->isa(__PACKAGE__) 6 4 10
Condition66%2/3
builtin::blessed($other) and $other->isa(__PACKAGE__)
!ll&&!rl&&r
406
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__)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $method eq "DESTROY" 357 655 1012
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
BranchTrueFalseTotal
$self->SUPER::can(@_) or ref $self ? $self->[0]->can(@_) : undef 0 2 2
ref $self ? : 2 0 2
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
BranchTrueFalseTotal
if (@_) 1 85 86
62 1 my $new_base = shift;
63  
64 # ensure absoluteness
65 1 ▶ $new_base = $new_base->abs
Branch: 1 branch
BranchTrueFalseTotal
if ref $new_base and $new_base->isa(__PACKAGE__) 0 1 1
Condition33%1/3
ref $new_base and $new_base->isa(__PACKAGE__)
!ll&&!rl&&r
100
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__)
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined wantarray 1 85 86
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
BranchTrueFalseTotal
if (defined $base and not ref $base) 63 22 85
Condition100%3/3
defined $base and not ref $base
!ll&&!rl&&r
61663
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
ABresult
0X0
100
111
77 63 $base = ref($self)->new($base);
78 63 ▶ $self->[1] = $base unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 63 0 63
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
BranchTrueFalseTotal
if ref $base 1 6 7
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)
l!l
775
shift() or $self->base
l!l&&r!l&&!r
18163
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
ABresult
1X1
011
000
93 77 ▶ $base = $base->as_string if ref($base);
Branch: 1 branch
BranchTrueFalseTotal
if ref $base 59 18 77
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)
l!l
150
shift() or $self->base
l!l&&r!l&&!r
0015
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
ABresult
1X1
011
000
100 15 ▶ $base = $base->as_string if ref($base);
Branch: 1 branch
BranchTrueFalseTotal
if ref $base 15 0 15
101 15 bless [$self->[0]->rel($base, @_), $base], ref($self);
102 }
103  
104 7 1;
105  
106 __END__
« URI/URL.pm ↑ Summary URI/file/QNX.pm »