| 1 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | package WWW::Mechanize::Cached; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use Module::Runtime 'use_module'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use Moo 1.004005; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 12 | ▶ | use MooX::Types::MooseLike::Base qw(AnyOf Bool Enum Maybe); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 12 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | extends 'WWW::Mechanize'; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 12 | ▶ | use Carp qw( carp croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 12 | ▶ | use Data::Dump qw( dump ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 12 | ▶ | use Storable qw( nfreeze thaw ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | our $VERSION = '1.55'; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 12 | has is_cached => ( is => 'rw', isa => Maybe [Bool], default => undef ); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 12 | has positive_cache => ( is => 'rw', isa => Bool, default => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | 12 | has ref_in_cache_key => ( is => 'rw', isa => Bool, default => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | 12 | has _verbose_dwarn => ( is => 'rw', isa => Bool, default => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 24 | 12 | has _last_request => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 12 | has [qw/ cache_undef_content_length cache_zero_content_length /] => | |||||||||||||||||||||||||||||||||||||||||
| 27 | ( is => 'rw', isa => AnyOf [ Bool, Enum ['warn'] ], default => 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 12 | has cache_mismatch_content_length => ( | |||||||||||||||||||||||||||||||||||||||||
| 30 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | isa => AnyOf [ Bool, Enum ['warn'] ], | ||||||||||||||||||||||||||||||||||||||||||
| 32 | default => 'warn', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 12 | has cache => ( is => 'lazy', isa => \&_isa_warn_cache ); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | sub FOREIGNBUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 22 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FOREIGNBUILDARGS: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # WWW::Mechanize/LWP::UserAgent would complain about these | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 22 | for my $attribute ( | |||||||||||||||||||||||||||||||||||||||||
| 42 | qw( | ||||||||||||||||||||||||||||||||||||||||||
| 43 | is_cached | ||||||||||||||||||||||||||||||||||||||||||
| 44 | positive_cache | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ref_in_cach_key | ||||||||||||||||||||||||||||||||||||||||||
| 46 | _verbose_dwarn | ||||||||||||||||||||||||||||||||||||||||||
| 47 | cache_undef_content_length | ||||||||||||||||||||||||||||||||||||||||||
| 48 | cache_zero_content_length | ||||||||||||||||||||||||||||||||||||||||||
| 49 | cache_mismatch_content_length | ||||||||||||||||||||||||||||||||||||||||||
| 50 | cache | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 176 | delete $args{$attribute}; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 22 | return %args; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | sub _isa_warn_cache { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | return | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | ▶ | if 'HASH' ne ref $_[0] | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_isa_warn_cache: called CC=4 SCAR=14.1
Branch: 1 branch
Condition66%4/6
"HASH" ne ref $_[0] and $_[0]->can("get") and $_[0]->can("set")
"HASH" ne ref $_[0] and $_[0]->can("get")
MC/DC33%1/3
"HASH" ne ref $_[0] and $_[0]->can("get") and $_[0]->can("set")
"HASH" ne ref $_[0]
$_[0]->can("get")
$_[0]->can("set")
Truth table50%2/4
A and B and C
A= "HASH" ne ref $_[0]B= $_[0]->can("get")C= $_[0]->can("set")
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | and $_[0]->can('get') | ||||||||||||||||||||||||||||||||||||||||||
| 63 | and $_[0]->can('set'); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | carp 'The cache param must be an initialized cache object'; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | $_[0] = undef; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | sub _build_cache { | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_cache: called CC=3 SCAR=16.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | return Cache::FileCache->new( | ||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | default_expires_in => '1d', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | namespace => 'www-mechanize-cached', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | ▶ | ) if eval { use_module('Cache::FileCache') }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | return CHI->new( | ||||||||||||||||||||||||||||||||||||||||||
| 79 | driver => 'File', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | expires_in => '1d', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | namespace => 'www-mechanize-cached', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | ) if eval { use_module('CHI') }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | croak( 'Could not create a default cache.' | |||||||||||||||||||||||||||||||||||||||||
| 85 | . 'Please make sure either CHI or Cache::FileCache are installed or configure manually as appropriate' | ||||||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | around _make_request => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 59 | ▶ | my ( $orig, $self, $request ) = splice @_, 0, 3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 59 | my $req = $request; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 59 | $self->is_cached(0); | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # An odd line to need. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # No idea what purpose this serves? OALDERS | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 59 | ▶ | $self->{proxy} = {} unless defined $self->{proxy}; ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | # RT #56757 | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 59 | ▶ | if ( !$self->ref_in_cache_key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 59 | my $clone = $request->clone; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 59 | $clone->header( Referer => undef ); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 59 | $req = $clone->as_string; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 59 | my $response = $self->cache->get($req); | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 59 | ▶ | if ($response) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 32 | $response = thaw($response); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 59 | ▶ | if ( $self->_cache_ok($response) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 32 | $self->is_cached(1); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 32 | $self->_last_request($req); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 32 | return $response; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 27 | $response = $self->$orig( $request, @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | # decode strips some important headers. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 27 | my $headers = $response->headers->clone; | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 27 | my $should_cache = $self->_response_cache_ok( $response, $headers ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | # http://rt.cpan.org/Public/Bug/Display.html?id=42693 | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 27 | $response->decode(); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 27 | delete $response->{handlers}; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 27 | ▶ | if ($should_cache) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 18 | $self->_last_request($req); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 18 | $self->cache->set( $req, nfreeze($response) ); | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 27 | return $response; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | sub invalidate_last_request { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
invalidate_last_request: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | return unless $self->is_cached; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | my $request = $self->_last_request; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | return unless $request; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | $self->cache->remove($request); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | return $self->is_cached( $self->cache->get($request) ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | sub _dwarn_filter { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | hide_keys => [ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dwarn_filter: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | qw( _content cookie content set-cookie handlers cookie_jar cache req res page_stack ) | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 152 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | sub _dwarn { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dwarn: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $message = shift; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return unless my $handler = $self->{onwarn}; ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | return if $self->quiet; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if ( $self->_verbose_dwarn ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $payload = { | |||||||||||||||||||||||||||||||||||||||||
| 166 | self => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 167 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | debug => \@_, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | require Data::Dump; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return $handler->( Data::Dump::dumpf( $payload, \&_dwarn_filter ) ); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return $handler->($message); | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | sub _response_cache_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 30 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_response_cache_ok: called CC=20 SCAR=41.3
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 30 | my $response = shift; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 30 | my $headers = shift; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 30 | ▶ | return 0 if !$response; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 30 | ▶ | return 1 if !$self->positive_cache; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 30 | ▶ | return 0 if $response->code < 200; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 30 | ▶ | return 0 if $response->code > 301; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 30 | my $size; | |||||||||||||||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 30 | ▶ | if ( $headers->header('Client-Transfer-Encoding') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | my @cte = $headers->header('Client-Transfer-Encoding'); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 3 | for my $cte (@cte) { | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | # Transfer-Encoding = chunked means document consistency | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # is independent of Content-Length value, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # and that Content-Length can be safely ignored. | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # Its not obvious how the lower levels represent a | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # failed chunked-transfer yet. | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # But its safe to say relying on content-length proves pointless. | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | return 1 if $cte eq 'chunked'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 28 | $size = $headers->{'content-length'}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 28 | ▶ | if ( not defined $size ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 10 | ▶ | if ( $self->cache_undef_content_length . q{} eq q{warn} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $self->_dwarn( | |||||||||||||||||||||||||||||||||||||||||
| 211 | q[Content-Length header was undefined, not caching] | ||||||||||||||||||||||||||||||||||||||||||
| 212 | . q[ (E=WWW_MECH_CACHED_CONTENTLENGTH_MISSING)], | ||||||||||||||||||||||||||||||||||||||||||
| 213 | $headers | ||||||||||||||||||||||||||||||||||||||||||
| 214 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 10 | ▶ | if ( $self->cache_undef_content_length == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 10 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 18 | ▶ | if ( defined $size and $size == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $size and $size == 0
MC/DC0%0/2
defined $size and $size == 0
defined $size
$size == 0
Truth table33%1/3
A and B
A= defined $sizeB= $size == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if ( $self->cache_zero_content_length . q{} eq q{warn} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $self->_dwarn( | |||||||||||||||||||||||||||||||||||||||||
| 225 | q{Content-Length header was 0, not caching} | ||||||||||||||||||||||||||||||||||||||||||
| 226 | . q{ (E=WWW_MECH_CACHED_CONTENTLENGTH_ZERO)}, | ||||||||||||||||||||||||||||||||||||||||||
| 227 | $headers | ||||||||||||||||||||||||||||||||||||||||||
| 228 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if ( $self->cache_zero_content_length == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 18 | ▶ | if ( defined $size | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $size and $size != 0 and $size != length $response->content
defined $size and $size != 0
MC/DC0%0/3
defined $size and $size != 0 and $size != length $response->content
defined $size
$size != 0
$size != length $response->content
Truth table25%1/4
A and B and C
A= defined $sizeB= $size != 0C= $size != length $response->content
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | and $size != 0 | ||||||||||||||||||||||||||||||||||||||||||
| 238 | and $size != length( $response->content ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ( $self->cache_mismatch_content_length . "" eq "warn" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->_dwarn( | |||||||||||||||||||||||||||||||||||||||||
| 241 | q{Content-Length header did not match contents actual length, not caching} | ||||||||||||||||||||||||||||||||||||||||||
| 242 | . q{ (E=WWW_MECH_CACHED_CONTENTLENGTH_MISSMATCH)} ); | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | if ( $self->cache_mismatch_content_length == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 18 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | sub _cache_ok { | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 63 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cache_ok: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 63 | my $response = shift; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 63 | ▶ | return 0 if !$response; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 36 | ▶ | return 1 if !$self->positive_cache; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 34 | ▶ | return 0 if $response->code < 200; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 34 | ▶ | return 0 if $response->code > 301; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 33 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 12 | ▶ | no warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 12 | "We miss you, Spoon"; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | # ABSTRACT: Cache response to be polite | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | __END__ | ||||||||||||||||||||||||||||||||||||||||||