blib/lib/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
« blib/lib/WWW/FetchStory/Fetcher.pm ↑ Summary blib/lib/WWW/FetchStory/Fetcher/PotionsAndSnitches.pm »
1 package HTTP::Cookies::Wget;
2 3 $HTTP::Cookies::Wget::VERSION = '0.2001';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our @ISA=qw(HTTP::Cookies);
6 3 require HTTP::Cookies;
7  
8 sub load
9 {
10 0 ▶ my($self, $file) = @_;
Subroutine load: not called CC=9 SCAR=45.0
Pod documented
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 {
51 0 ▶ my($self, $file) = @_;
Subroutine save: not called CC=4 SCAR=30.0
Pod documented
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 $self->scan(sub {
67 0 ▶ my($version,$key,$val,$path,$domain,$port,
Subroutine __ANON__: not called CC=7 SCAR=40.3
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 3 1;
81 __END__
82  
83 =head1 NAME
84  
85 HTTP::Cookies::Wget - access to Wget cookies files
86  
87 =head1 VERSION
88  
89 version 0.2001
90  
91 =head1 SYNOPSIS
92  
93 use LWP;
94 use HTTP::Cookies::Wget;
95 $cookie_jar = HTTP::Cookies::Wget->new(
96 file => "c:/program files/netscape/users/ZombieCharity/cookies.txt",
97 );
98 my $browser = LWP::UserAgent->new;
99 $browser->cookie_jar( $cookie_jar );
100  
101 =head1 DESCRIPTION
102  
103 This is a subclass of C<HTTP::Cookies> that reads (and optionally
104 writes) Wget/Mozilla cookie files.
105  
106 See the documentation for L<HTTP::Cookies>.
107  
108 =head1 CAVEATS
109  
110 Please note that the Wget/Mozilla cookie file format can't store
111 all the information available in the Set-Cookie2 headers, so you will
112 probably lose some information if you save in this format.
113  
114 At time of writing, this module seems to work fine with Mozilla
115 Phoenix/Firebird.
116  
117 =head1 SEE ALSO
118  
119 L<HTTP::Cookies::Netscape>
120  
121 =head1 COPYRIGHT
122  
123 Copyright 2002-2003 Gisle Aas
124  
125 This library is free software; you can redistribute it and/or
126 modify it under the same terms as Perl itself.
127  
128 =cut
« blib/lib/WWW/FetchStory/Fetcher.pm ↑ Summary blib/lib/WWW/FetchStory/Fetcher/PotionsAndSnitches.pm »