HTTP/Cookies/Wget.pm

filter: Statementstmt 15.9% 7 / 44 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 25.0% 1 / 4 Podpod 100% 2 / 2 totaltotal 10.7% 10 / 93 CC 18 SCAR 41.1
CC
18
Cov
9%
load
90.0
__ANON__
56.0
save
20.0
CRAP 61.1
« WWW/FetchStory/Fetcher/AO3.pm ↑ Summary WWW/FetchStory.pm »
1 package HTTP::Cookies::Wget;
2 25 $HTTP::Cookies::Wget::VERSION = '0.2602';
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 25 our @ISA=qw(HTTP::Cookies);
6 25 require HTTP::Cookies;
7  
8 sub load
9 0 ▶{
Subroutine load: not called CC=9 SCAR=45.0
Pod documented
10 0 my($self, $file) = @_;
11 0 ▶ $file ||= $self->{'file'} || return;
Condition0%0/5
$file ||= $self->{"file"} || (return)
l!l&&r!l&&!r
000
$self->{'file'} || (return)
l!l
00
MC/DC0%0/2
$file ||= $self->{"file"} || (return)
$file $self->{'file'}
Truth table0%0/3
A ||= B
A= $fileB= $self->{'file'}
ABresult
1X1
011
000
12 0 local(*FILE, $_);
13 0 local $/ = "\n"; # make sure we got standard record separator
14 0 my @cookies;
15 0 ▶ open(FILE, $file) || return;
Branch: 1 branch
BranchTrueFalseTotal
open FILE, $file or return 0 0 0
16  
17 # don't check for a header; not all export programs save one
18  
19 0 my $now = time() - $HTTP::Cookies::EPOCH_OFFSET;
20 0 ▶ while (<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 0 0 0
21 0 ▶ next if /^\s*\#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*\#/ 0 0 0
22 0 ▶ next if /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*$/ 0 0 0
23 0 tr/\n\r//d;
24 0 my($domain,$bool1,$path,$secure, $expires,$key,$val) = split(/\t/, $_);
25 0 $secure = ($secure eq "TRUE");
26  
27 # Give expired cookies a fake maxage, because we want all cookies
28 # including session cookies
29 0 my $maxage = $expires-$now;
30 0 ▶ if ($maxage < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($maxage < 0) 0 0 0
31 {
32 0 $maxage = 9999999;
33 }
34 # Tweak the domain for livejournal cookies,
35 # because it puts '.' in front of all of them
36 # whether they need it or not, and this apparently confuses LWP
37 0 ▶ if ($domain =~ /^\.([-\w]+\.livejournal\.com)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($domain =~ /^\.([-\w]+\.livejournal\.com)$/) 0 0 0
38 {
39 0 $domain = $1;
40 }
41  
42 0 $self->set_cookie(undef,$key,$val,$path,$domain,undef,
43 0,$secure,$maxage, 0);
44 }
45 0 close(FILE);
46 0 1;
47 }
48  
49 sub save
50 0 ▶{
Subroutine save: not called CC=4 SCAR=30.0
Pod documented
51 0 my($self, $file) = @_;
52 0 ▶ $file ||= $self->{'file'} || return;
Condition0%0/5
$file ||= $self->{"file"} || (return)
l!l&&r!l&&!r
000
$self->{'file'} || (return)
l!l
00
MC/DC0%0/2
$file ||= $self->{"file"} || (return)
$file $self->{'file'}
Truth table0%0/3
A ||= B
A= $fileB= $self->{'file'}
ABresult
1X1
011
000
53 0 local(*FILE, $_);
54 0 ▶ open(FILE, ">$file") || return;
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$file" or return 0 0 0
55  
56 # Use old, now broken link to the old cookie spec just in case something
57 # else (not us!) requires the comment block exactly this way.
58 0 print FILE <<EOT;
59 # Wget HTTP Cookie File
60 # http://www.netscape.com/newsref/std/cookie_spec.html
61 # This is a generated file! Do not edit.
62  
63 EOT
64  
65 0 my $now = time - $HTTP::Cookies::EPOCH_OFFSET;
66 0 ▶ $self->scan(sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
67 0 my($version,$key,$val,$path,$domain,$port,
68 $path_spec,$secure,$expires,$discard,$rest) = @_;
69 0 ▶ return if $discard && !$self->{ignore_discard};
Branch: 1 branch
BranchTrueFalseTotal
if $discard and not $self->{"ignore_discard"} 0 0 0
Condition0%0/3
$discard and not $self->{"ignore_discard"}
!ll&&!rl&&r
000
MC/DC0%0/2
$discard and not $self->{"ignore_discard"}
$discard not $self->{"ignore_discard"}
Truth table0%0/3
A and not(B)
A= $discardB= not $self->{"ignore_discard"}
ABresult
0X0
100
111
70 0 ▶ $expires = $expires ? $expires - $HTTP::Cookies::EPOCH_OFFSET : 0;
Branch: 1 branch
BranchTrueFalseTotal
$expires ? : 0 0 0
71 0 ▶ return if $now > $expires;
Branch: 1 branch
BranchTrueFalseTotal
if $now > $expires 0 0 0
72 0 ▶ $secure = $secure ? "TRUE" : "FALSE";
Branch: 1 branch
BranchTrueFalseTotal
$secure ? : 0 0 0
73 0 ▶ my $bool = $domain =~ /^\./ ? "TRUE" : "FALSE";
Branch: 1 branch
BranchTrueFalseTotal
$domain =~ /^\./ ? : 0 0 0
74 0 print FILE join("\t", $domain, $bool, $path, $secure, $expires, $key, $val), "\n";
75 0 });
76 0 close(FILE);
77 0 1;
78 }
79  
80 25 1;
81 __END__
« WWW/FetchStory/Fetcher/AO3.pm ↑ Summary WWW/FetchStory.pm »