blib/lib/URI/CrawlableHash.pm

filter: Statementstmt 96.0% 72 / 75 Branchbran 63.6% 14 / 22 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 16 / 16 Podpod 14.2% 1 / 7 totaltotal 83.3% 105 / 126 CC 14 SCAR 8.8
CC
14
Cov
87%
convert_always
4.1
fragment_to_query
4.0
query_to_fragment
3.0
CRAP 2.4
↑ Summary
1 package URI::CrawlableHash;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 our $VERSION = '0.02';
6  
7 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Guard;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶sub convert_always {
Subroutine convert_always: called CC=4 SCAR=14.1
Pod documented
12 2 my ( $class, $option ) = @_;
13 3 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶ $option ||= "query";
Condition50%1/2
$option ||= "query"
l!l
20
MC/DC0%0/1
$option ||= "query"
$option
Truth table50%1/2
A
A= $option
Aresult
11
00
16  
17 2 my $orig = URI->can('new');
18 2 my $conv = $class->can("convert_to_" . $option);
19 0 ▶ unless ($conv) { die "unknown option: " . $option }
Branch: 1 branch
BranchTrueFalseTotal
unless ($conv) 0 2 2
20
21 3 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶ *{'URI::new'} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
24 2 my $self = $orig->(@_);
25 2 ▶ if ($self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 2 0 2
26 2 $conv->($self);
27 }
28 2 };
29  
30 2 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 2 0 2
31 2 ▶ return guard {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 2 *{"URI::new"} = $orig;
33 2 };
34 }
35 }
36  
37 1 ▶sub convert_to_query {
Subroutine convert_to_query: called CC=2 SCAR=7.6
Pod undocumented
38 1 my $self = shift;
39 1 ▶ if ($self->has_crawlable_hash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_crawlable_hash) { } 1 0 1
40 1 $self->fragment_to_query
41 } else {
42 0 $self
43 }
44 }
45  
46 1 ▶sub convert_to_hash {
Subroutine convert_to_hash: called CC=2 SCAR=7.6
Pod undocumented
47 1 my $self = shift;
48 1 ▶ if ($self->has_escaped_fragment) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_escaped_fragment) { } 1 0 1
49 1 $self->query_to_fragment
50 } else {
51 0 $self
52 }
53 }
54  
55 5 ▶sub URI::has_crawlable_hash {
Subroutine has_crawlable_hash: called CC=2 SCAR=7.2
Pod undocumented
56 5 my ($uri) = @_;
57 5 ▶ ($uri->fragment || "") =~/^!/
Condition50%1/2
$uri->fragment || ''
l!l
50
MC/DC0%0/1
$uri->fragment || ''
$uri->fragment
Truth table50%1/2
A
A= $uri->fragment
Aresult
11
00
58 }
59  
60 4 ▶sub URI::has_escaped_fragment {
Subroutine has_escaped_fragment: called CC=2 SCAR=7.1
Pod undocumented
61 4 my ($uri) = @_;
62 4 my %hash = $uri->query_form;
63 4 ▶ $hash{_escaped_fragment_} ? 1 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$hash{'_escaped_fragment_'} ? : 4 0 4
64 }
65  
66 4 ▶sub URI::fragment_to_query {
Subroutine fragment_to_query: called CC=4 SCAR=13.9
Pod undocumented
67 4 my $self = shift;
68 4 ▶ return $self unless $self->has_crawlable_hash;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_crawlable_hash 0 4 4
69  
70 4 my $fragment = $self->fragment;
71 4 $fragment =~s/^!//;
72 4 my $q = "_escaped_fragment_=" . uri_escape($fragment, "\x00-\x20\x23\x25\x26\x2b\x7f-\xff");
73 4 ▶ if ($self->query) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->query) { } 2 2 4
74 2 my $old = $self->query;
75 2 $old =~s/_escaped_fragment_=[^\&]*$//;
76 2 ▶ my $delimiter = $old ? "&" : "";
Branch: 1 branch
BranchTrueFalseTotal
$old ? : 1 1 2
77 2 $self->query( $old . $delimiter . $q );
78 } else {
79 2 $self->query($q);
80 }
81 4 $self->fragment(undef);
82 4 $self;
83 }
84  
85 3 ▶sub URI::query_to_fragment {
Subroutine query_to_fragment: called CC=3 SCAR=11.0
Pod undocumented
86 3 my $self = shift;
87 3 ▶ return $self unless $self->has_escaped_fragment;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_escaped_fragment 0 3 3
88  
89 3 my %query = $self->query_form;
90 3 my $escaped = delete $query{_escaped_fragment_};
91  
92 3 my $old = $self->query;
93 3 $old =~s/\&?_escaped_fragment_=[^\&]*$//;
94  
95 3 ▶ if ($old) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old) { } 1 2 3
96 1 $self->query($old)
97 } else {
98 2 $self->query(undef);
99 }
100  
101 3 $self->fragment('!' . uri_unescape($escaped));
102 3 $self;
103 }
104  
105 3 1;
106 __END__
↑ Summary