| 1 | package HTTP::Config; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '7.04'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 12 | 3 | return bless [], $class; | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | sub entries { | ||||||||||||||||||||||||||
|
Subroutine
entries: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 17 | 3 | @$self; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | sub empty { | ||||||||||||||||||||||||||
|
Subroutine
empty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 22 | 3 | not @$self; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 18 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 18 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 28 | 1 | push(@$self, shift); | |||||||||||||||||||||||||||
| 29 | 1 | return; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 17 | my($self, %spec) = @_; | |||||||||||||||||||||||||||
| 32 | 17 | push(@$self, \%spec); | |||||||||||||||||||||||||||
| 33 | 17 | return; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8 | ▶ | sub find2 { | ||||||||||||||||||||||||||
|
Subroutine
find2: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 8 | my($self, %spec) = @_; | |||||||||||||||||||||||||||
| 38 | 8 | my @found; | |||||||||||||||||||||||||||
| 39 | my @rest; | ||||||||||||||||||||||||||||
| 40 | ITEM: | ||||||||||||||||||||||||||||
| 41 | 8 | for my $item (@$self) { | |||||||||||||||||||||||||||
| 42 | 44 | for my $k (keys %spec) { | |||||||||||||||||||||||||||
| 43 | 1 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 36 | ▶ | if (!exists $item->{$k} || $spec{$k} ne $item->{$k}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $item->{$k} or $spec{$k} ne $item->{$k}
MC/DC100%2/2
not exists $item->{$k} or $spec{$k} ne $item->{$k}
not exists $item->{$k}
$spec{$k} ne $item->{$k}
Truth table100%3/3
not(A) or B
A= not exists $item->{$k}B= $spec{$k} ne $item->{$k}
| |||||||||||||||||||||||||||||
| 45 | 31 | push(@rest, $item); | |||||||||||||||||||||||||||
| 46 | 31 | next ITEM; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 13 | push(@found, $item); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 8 | ▶ | return \@found unless wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 6 | return \@found, \@rest; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 2 | ▶ | sub find { | ||||||||||||||||||||||||||
|
Subroutine
find: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | 2 | my $f = $self->find2(@_); | |||||||||||||||||||||||||||
| 58 | 2 | ▶ | return @$f if wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 1 | return $f->[0]; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 6 | ▶ | sub remove { | ||||||||||||||||||||||||||
|
Subroutine
remove: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 6 | my($self, %spec) = @_; | |||||||||||||||||||||||||||
| 64 | 6 | my($removed, $rest) = $self->find2(%spec); | |||||||||||||||||||||||||||
| 65 | 6 | ▶ | @$self = @$rest if @$removed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 6 | return @$removed; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | my %MATCH = ( | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | m_scheme => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 71 | 0 | my($v, $uri) = @_; | |||||||||||||||||||||||||||
| 72 | 0 | return $uri->_scheme eq $v; # URI known to be canonical | |||||||||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||||||||||
| 74 | 9 | ▶ | m_secure => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 75 | 9 | my($v, $uri) = @_; | |||||||||||||||||||||||||||
| 76 | 9 | ▶ | my $secure = $uri->can("secure") ? $uri->secure : $uri->_scheme eq "https"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 9 | return $secure == !!$v; | |||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||
| 79 | 10 | ▶ | m_host_port => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 80 | 10 | my($v, $uri) = @_; | |||||||||||||||||||||||||||
| 81 | 10 | ▶ | return unless $uri->can("host_port"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 10 | return $uri->host_port eq $v, 7; | |||||||||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | m_host => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 85 | 0 | my($v, $uri) = @_; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | return unless $uri->can("host"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | return $uri->host eq $v, 6; | |||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | m_port => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 90 | 0 | my($v, $uri) = @_; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | return unless $uri->can("port"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | return $uri->port eq $v; | |||||||||||||||||||||||||||
| 93 | }, | ||||||||||||||||||||||||||||
| 94 | 4 | ▶ | m_domain => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.8
| |||||||||||||||||||||||||||||
| 95 | 4 | my($v, $uri) = @_; | |||||||||||||||||||||||||||
| 96 | 4 | ▶ | return unless $uri->can("host"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 4 | my $h = $uri->host; | |||||||||||||||||||||||||||
| 98 | 4 | ▶ | $h = "$h.local" unless $h =~ /\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 4 | ▶ | $v = ".$v" unless $v =~ /^\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 4 | ▶ | return length($v), 5 if substr($h, -length($v)) eq $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | return 0; | |||||||||||||||||||||||||||
| 102 | }, | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | m_path => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 104 | 0 | my($v, $uri) = @_; | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | return unless $uri->can("path"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | return $uri->path eq $v, 4; | |||||||||||||||||||||||||||
| 107 | }, | ||||||||||||||||||||||||||||
| 108 | 2 | ▶ | m_path_prefix => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.0
| |||||||||||||||||||||||||||||
| 109 | 2 | my($v, $uri) = @_; | |||||||||||||||||||||||||||
| 110 | 2 | ▶ | return unless $uri->can("path"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 2 | my $path = $uri->path; | |||||||||||||||||||||||||||
| 112 | 2 | my $len = length($v); | |||||||||||||||||||||||||||
| 113 | 2 | ▶ | return $len, 3 if $path eq $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 2 | ▶ | return 0 if length($path) <= $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 2 | ▶ | $v .= "/" unless $v =~ m,/\z,,; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 2 | ▶ | return $len, 3 if substr($path, 0, length($v)) eq $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | return 0; | |||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | m_path_match => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 120 | 0 | my($v, $uri) = @_; | |||||||||||||||||||||||||||
| 121 | 0 | ▶ | return unless $uri->can("path"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | return $uri->path =~ $v; | |||||||||||||||||||||||||||
| 123 | }, | ||||||||||||||||||||||||||||
| 124 | 3 | ▶ | m_uri__ => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=16.5
| |||||||||||||||||||||||||||||
| 125 | 3 | my($v, $k, $uri) = @_; | |||||||||||||||||||||||||||
| 126 | 3 | ▶ | return unless $uri->can($k); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return 1 unless defined $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | return $uri->$k eq $v; | |||||||||||||||||||||||||||
| 129 | }, | ||||||||||||||||||||||||||||
| 130 | 15 | ▶ | m_method => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 131 | 15 | my($v, $uri, $request) = @_; | |||||||||||||||||||||||||||
| 132 | 15 | ▶ | return $request && $request->method eq $v; | ||||||||||||||||||||||||||
|
Condition100%3/3
$request && $request->method eq $v
MC/DC100%2/2
$request && $request->method eq $v
$request
$request->method eq $v
Truth table100%3/3
A && B
A= $requestB= $request->method eq $v
| |||||||||||||||||||||||||||||
| 133 | }, | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | m_proxy => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 135 | 0 | my($v, $uri, $request) = @_; | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | return $request && ($request->{proxy} || "") eq $v; | ||||||||||||||||||||||||||
|
Condition0%0/5
$request && ($request->{'proxy'} || '') eq $v
$request->{'proxy'} || ''
MC/DC0%0/2
$request && ($request->{'proxy'} || '') eq $v
$request
$request->{'proxy'}
Truth table0%0/3
A && B
A= $requestB= $request->{'proxy'}
| |||||||||||||||||||||||||||||
| 137 | }, | ||||||||||||||||||||||||||||
| 138 | 5 | ▶ | m_code => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 139 | 5 | my($v, $uri, $request, $response) = @_; | |||||||||||||||||||||||||||
| 140 | 5 | $v =~ s/xx\z//; | |||||||||||||||||||||||||||
| 141 | 5 | ▶ | return unless $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 2 | ▶ | return length($v), 2 if substr($response->code, 0, length($v)) eq $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | }, | ||||||||||||||||||||||||||||
| 144 | 20 | ▶ | m_media_type => sub { # for request too?? | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 145 | 20 | my($v, $uri, $request, $response) = @_; | |||||||||||||||||||||||||||
| 146 | 20 | ▶ | return unless $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 20 | ▶ | return 1, 1 if $v eq "*/*"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 16 | my $ct = $response->content_type; | |||||||||||||||||||||||||||
| 149 | 16 | ▶ | return 2, 1 if $v =~ s,/\*\z,, && $ct =~ m,^\Q$v\E/,; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$v =~ s[/\*\z][] and $ct =~ m[^\Q$v\E/]
MC/DC100%2/2
$v =~ s[/\*\z][] and $ct =~ m[^\Q$v\E/]
$v =~ s[/\*\z][]
$ct =~ m[^\Q$v\E/]
Truth table100%3/3
A and B
A= $v =~ s[/\*\z][]B= $ct =~ m[^\Q$v\E/]
| |||||||||||||||||||||||||||||
| 150 | 13 | ▶ | return 3, 1 if $v eq "html" && $response->content_is_html; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$v eq "html" and $response->content_is_html
MC/DC100%2/2
$v eq "html" and $response->content_is_html
$v eq "html"
$response->content_is_html
Truth table100%3/3
A and B
A= $v eq "html"B= $response->content_is_html
| |||||||||||||||||||||||||||||
| 151 | 10 | ▶ | return 4, 1 if $v eq "xhtml" && $response->content_is_xhtml; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$v eq "xhtml" and $response->content_is_xhtml
MC/DC100%2/2
$v eq "xhtml" and $response->content_is_xhtml
$v eq "xhtml"
$response->content_is_xhtml
Truth table100%3/3
A and B
A= $v eq "xhtml"B= $response->content_is_xhtml
| |||||||||||||||||||||||||||||
| 152 | 9 | ▶ | return 10, 1 if $v eq $ct; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 7 | return 0; | |||||||||||||||||||||||||||
| 154 | }, | ||||||||||||||||||||||||||||
| 155 | 1 | ▶ | m_header__ => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=27.0
| |||||||||||||||||||||||||||||
| 156 | 1 | my($v, $k, $uri, $request, $response) = @_; | |||||||||||||||||||||||||||
| 157 | 1 | ▶ | return unless $request; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 1 | my $req_header = $request->header($k); | |||||||||||||||||||||||||||
| 159 | 1 | ▶ | return 1 if defined($req_header) && $req_header eq $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $req_header and $req_header eq $v
MC/DC0%0/2
defined $req_header and $req_header eq $v
defined $req_header
$req_header eq $v
Truth table33%1/3
A and B
A= defined $req_headerB= $req_header eq $v
| |||||||||||||||||||||||||||||
| 160 | 1 | ▶ | if ($response) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | my $res_header = $response->header($k); | |||||||||||||||||||||||||||
| 162 | 0 | ▶ | return 1 if defined($res_header) && $res_header eq $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $res_header and $res_header eq $v
MC/DC0%0/2
defined $res_header and $res_header eq $v
defined $res_header
$res_header eq $v
Truth table0%0/3
A and B
A= defined $res_headerB= $res_header eq $v
| |||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 1 | return 0; | |||||||||||||||||||||||||||
| 165 | }, | ||||||||||||||||||||||||||||
| 166 | 0 | ▶ | m_response_attr__ => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 167 | 0 | my($v, $k, $uri, $request, $response) = @_; | |||||||||||||||||||||||||||
| 168 | 0 | ▶ | return unless $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return 1 if !defined($v) && exists $response->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $v and exists $response->{$k}
MC/DC0%0/2
not defined $v and exists $response->{$k}
not defined $v
exists $response->{$k}
Truth table0%0/3
not(A) and B
A= not defined $vB= exists $response->{$k}
| |||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return 0 unless exists $response->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | return 1 if $response->{$k} eq $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | return 0; | |||||||||||||||||||||||||||
| 173 | }, | ||||||||||||||||||||||||||||
| 174 | 1 | ); | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 17 | ▶ | sub matching { | ||||||||||||||||||||||||||
|
Subroutine
matching: called CC=21 SCAR=30.4
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 178 | 17 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 16 | ▶ | if ($_[0]->can("request")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 7 | unshift(@_, $_[0]->request); | |||||||||||||||||||||||||||
| 181 | 7 | ▶ | unshift(@_, undef) unless defined $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 16 | ▶ | unshift(@_, $_[0]->uri_canonical) if $_[0] && $_[0]->can("uri_canonical"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_[0] and $_[0]->can("uri_canonical")
MC/DC100%2/2
$_[0] and $_[0]->can("uri_canonical")
$_[0]
$_[0]->can("uri_canonical")
Truth table100%3/3
A and B
A= $_[0]B= $_[0]->can("uri_canonical")
| |||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | 17 | my($uri, $request, $response) = @_; | |||||||||||||||||||||||||||
| 186 | 17 | ▶ | $uri = URI->new($uri) unless ref($uri); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 17 | my @m; | |||||||||||||||||||||||||||
| 189 | ITEM: | ||||||||||||||||||||||||||||
| 190 | 17 | for my $item (@$self) { | |||||||||||||||||||||||||||
| 191 | 68 | my $order; | |||||||||||||||||||||||||||
| 192 | 68 | for my $ikey (keys %$item) { | |||||||||||||||||||||||||||
| 193 | 121 | my $mkey = $ikey; | |||||||||||||||||||||||||||
| 194 | 121 | my $k; | |||||||||||||||||||||||||||
| 195 | 121 | ▶ | $k = $1 if $mkey =~ s/__(.*)/__/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 121 | ▶ | if (my $m = $MATCH{$mkey}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | #print "$ikey $mkey\n"; | ||||||||||||||||||||||||||||
| 198 | 64 | my($c, $o); | |||||||||||||||||||||||||||
| 199 | 64 | ▶ | my @arg = ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | defined($k) ? $k : (), | ||||||||||||||||||||||||||||
| 201 | $uri, $request, $response | ||||||||||||||||||||||||||||
| 202 | ); | ||||||||||||||||||||||||||||
| 203 | 64 | my $v = $item->{$ikey}; | |||||||||||||||||||||||||||
| 204 | 64 | ▶ | $v = [$v] unless ref($v) eq "ARRAY"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 64 | for (@$v) { | |||||||||||||||||||||||||||
| 206 | 69 | ($c, $o) = $m->($_, @arg); | |||||||||||||||||||||||||||
| 207 | #print " - $_ ==> $c $o\n"; | ||||||||||||||||||||||||||||
| 208 | 69 | ▶ | last if $c; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | 64 | ▶ | next ITEM unless $c; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 31 | ▶ | $order->[$o || 0] += $c; | ||||||||||||||||||||||||||
|
Condition100%2/2
$o || 0
MC/DC100%1/1
$o || 0
$o
Truth table100%2/2
A
A= $o
| |||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | 35 | ▶ | $order->[7] ||= 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$order->[7] ||= 0
MC/DC100%1/1
$order->[7] ||= 0
$order->[7]
Truth table100%2/2
A
A= $order->[7]
| |||||||||||||||||||||||||||||
| 215 | 35 | ▶ | $item->{_order} = join(".", reverse map sprintf("%03d", $_ || 0), @$order); | ||||||||||||||||||||||||||
|
Condition100%2/2
$_ || 0
MC/DC100%1/1
$_ || 0
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||
| 216 | 35 | push(@m, $item); | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | 17 | @m = sort { $b->{_order} cmp $a->{_order} } @m; | |||||||||||||||||||||||||||
| 219 | 17 | delete $_->{_order} for @m; | |||||||||||||||||||||||||||
| 220 | 17 | ▶ | return @m if wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 1 | return $m[0]; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 16 | ▶ | sub add_item { | ||||||||||||||||||||||||||
|
Subroutine
add_item: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 225 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 226 | 16 | my $item = shift; | |||||||||||||||||||||||||||
| 227 | 16 | return $self->add(item => $item, @_); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 5 | ▶ | sub remove_items { | ||||||||||||||||||||||||||
|
Subroutine
remove_items: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 231 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 232 | 5 | return map $_->{item}, $self->remove(@_); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 16 | ▶ | sub matching_items { | ||||||||||||||||||||||||||
|
Subroutine
matching_items: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 236 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 237 | 16 | return map $_->{item}, $self->matching(@_); | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 1 | 1; | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =pod | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | =head1 NAME | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | HTTP::Config - Configuration for request and response objects | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | =head1 VERSION | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | version 7.04 | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | use HTTP::Config; | ||||||||||||||||||||||||||||
| 257 | my $c = HTTP::Config->new; | ||||||||||||||||||||||||||||
| 258 | $c->add(m_domain => ".example.com", m_scheme => "http", verbose => 1); | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | use HTTP::Request; | ||||||||||||||||||||||||||||
| 261 | my $request = HTTP::Request->new(GET => "http://www.example.com"); | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | if (my @m = $c->matching($request)) { | ||||||||||||||||||||||||||||
| 264 | print "Yadayada\n" if $m[0]->{verbose}; | ||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | An C<HTTP::Config> object is a list of entries that | ||||||||||||||||||||||||||||
| 270 | can be matched against request or request/response pairs. Its | ||||||||||||||||||||||||||||
| 271 | purpose is to hold configuration data that can be looked up given a | ||||||||||||||||||||||||||||
| 272 | request or response object. | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | Each configuration entry is a hash. Some keys specify matching to | ||||||||||||||||||||||||||||
| 275 | occur against attributes of request/response objects. Other keys can | ||||||||||||||||||||||||||||
| 276 | be used to hold user data. | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | The following methods are provided: | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | =over 4 | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | =item $conf = HTTP::Config->new | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | Constructs a new empty C<HTTP::Config> object and returns it. | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | =item $conf->entries | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | Returns the list of entries in the configuration object. | ||||||||||||||||||||||||||||
| 289 | In scalar context returns the number of entries. | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | =item $conf->empty | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | Return true if there are no entries in the configuration object. | ||||||||||||||||||||||||||||
| 294 | This is just a shorthand for C<< not $conf->entries >>. | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | =item $conf->add( %matchspec, %other ) | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =item $conf->add( \%entry ) | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | Adds a new entry to the configuration. | ||||||||||||||||||||||||||||
| 301 | You can either pass separate key/value pairs or a hash reference. | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | =item $conf->remove( %spec ) | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | Removes (and returns) the entries that have matches for all the key/value pairs in %spec. | ||||||||||||||||||||||||||||
| 306 | If %spec is empty this will match all entries; so it will empty the configuration object. | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | =item $conf->matching( $uri, $request, $response ) | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | =item $conf->matching( $uri ) | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | =item $conf->matching( $request ) | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | =item $conf->matching( $response ) | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | Returns the entries that match the given $uri, $request and $response triplet. | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | If called with a single $request object then the $uri is obtained by calling its 'uri_canonical' method. | ||||||||||||||||||||||||||||
| 319 | If called with a single $response object, then the request object is obtained by calling its 'request' method; | ||||||||||||||||||||||||||||
| 320 | and then the $uri is obtained as if a single $request was provided. | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | The entries are returned with the most specific matches first. | ||||||||||||||||||||||||||||
| 323 | In scalar context returns the most specific match or C<undef> in none match. | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | =item $conf->add_item( $item, %matchspec ) | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | =item $conf->remove_items( %spec ) | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | =item $conf->matching_items( $uri, $request, $response ) | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | Wrappers that hides the entries themselves. | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | =back | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | =head2 Matching | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | The following keys on a configuration entry specify matching. For all | ||||||||||||||||||||||||||||
| 338 | of these you can provide an array of values instead of a single value. | ||||||||||||||||||||||||||||
| 339 | The entry matches if at least one of the values in the array matches. | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | Entries that require match against a response object attribute will never match | ||||||||||||||||||||||||||||
| 342 | unless a response object was provided. | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | =over | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | =item m_scheme => $scheme | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | Matches if the URI uses the specified scheme; e.g. "http". | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | =item m_secure => $bool | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | If $bool is TRUE; matches if the URI uses a secure scheme. If $bool | ||||||||||||||||||||||||||||
| 353 | is FALSE; matches if the URI does not use a secure scheme. An example | ||||||||||||||||||||||||||||
| 354 | of a secure scheme is "https". | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | =item m_host_port => "$hostname:$port" | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | Matches if the URI's host_port method return the specified value. | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | =item m_host => $hostname | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | Matches if the URI's host method returns the specified value. | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | =item m_port => $port | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | Matches if the URI's port method returns the specified value. | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | =item m_domain => ".$domain" | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | Matches if the URI's host method return a value that within the given | ||||||||||||||||||||||||||||
| 371 | domain. The hostname "www.example.com" will for instance match the | ||||||||||||||||||||||||||||
| 372 | domain ".com". | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | =item m_path => $path | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | Matches if the URI's path method returns the specified value. | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | =item m_path_prefix => $path | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | Matches if the URI's path is the specified path or has the specified | ||||||||||||||||||||||||||||
| 381 | path as prefix. | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | =item m_path_match => $Regexp | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | Matches if the regular expression matches the URI's path. Eg. qr/\.html$/. | ||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | =item m_method => $method | ||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||
| 389 | Matches if the request method matches the specified value. Eg. "GET" or "POST". | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | =item m_code => $digit | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | =item m_code => $status_code | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | Matches if the response status code matches. If a single digit is | ||||||||||||||||||||||||||||
| 396 | specified; matches for all response status codes beginning with that digit. | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | =item m_proxy => $url | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | Matches if the request is to be sent to the given Proxy server. | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | =item m_media_type => "*/*" | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | =item m_media_type => "text/*" | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | =item m_media_type => "html" | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | =item m_media_type => "xhtml" | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | =item m_media_type => "text/html" | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | Matches if the response media type matches. | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | With a value of "html" matches if $response->content_is_html returns TRUE. | ||||||||||||||||||||||||||||
| 415 | With a value of "xhtml" matches if $response->content_is_xhtml returns TRUE. | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | =item m_uri__I<$method> => undef | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | Matches if the URI object provides the method. | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | =item m_uri__I<$method> => $string | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | Matches if the URI's $method method returns the given value. | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | =item m_header__I<$field> => $string | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | Matches if either the request or the response have a header $field with the given value. | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | =item m_response_attr__I<$key> => undef | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | =item m_response_attr__I<$key> => $string | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | Matches if the response object has that key, or the entry has the given value. | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | =back | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | L<URI>, L<HTTP::Request>, L<HTTP::Response> | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | Gisle Aas <gisle@activestate.com> | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | This software is copyright (c) 1994 by Gisle Aas. | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 450 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | =cut | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | __END__ | ||||||||||||||||||||||||||||