| 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"
MC/DC0%0/1
$option ||= "query"
$option
Truth table50%1/2
A
A= $option
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 26 | 2 | $conv->($self); | |||||||||||
| 27 | } | ||||||||||||
| 28 | 2 | }; | |||||||||||
| 29 | |||||||||||||
| 30 | 2 | ▶ | if ( defined wantarray ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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 || ''
MC/DC0%0/1
$uri->fragment || ''
$uri->fragment
Truth table50%1/2
A
A= $uri->fragment
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 74 | 2 | my $old = $self->query; | |||||||||||
| 75 | 2 | $old =~s/_escaped_fragment_=[^\&]*$//; | |||||||||||
| 76 | 2 | ▶ | my $delimiter = $old ? "&" : ""; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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__ | ||||||||||||