| 1 | package HTTP::Cookies::Netscape; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 7 | our $VERSION = '6.12'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 7 | require HTTP::Cookies; | |||||||||||||||||||||||||||
| 8 | 7 | our @ISA = qw(HTTP::Cookies); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 6 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||
| 12 | 6 | ▶ | $file ||= $self->{'file'} || return; | ||||||||||||||||||||||||||
|
Condition80%4/5
$file ||= $self->{"file"} || (return)
$self->{'file'} || (return)
MC/DC0%0/2
$file ||= $self->{"file"} || (return)
$file
$self->{'file'}
Truth table66%2/3
A ||= B
A= $fileB= $self->{'file'}
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | local $/ = "\n"; # make sure we got standard record separator | |||||||||||||||||||||||||||
| 15 | 4 | ▶ | open( my $fh, '<', $file ) || return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 3 | my $magic = <$fh>; | |||||||||||||||||||||||||||
| 17 | 3 | chomp $magic; | |||||||||||||||||||||||||||
| 18 | 3 | ▶ | unless ( $magic =~ /^#(?: Netscape)? HTTP Cookie File/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | warn "$file does not look like a netscape cookies file"; | |||||||||||||||||||||||||||
| 20 | 0 | return; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | my $now = time() - $HTTP::Cookies::EPOCH_OFFSET; | |||||||||||||||||||||||||||
| 24 | 3 | ▶ | while ( my $line = <$fh> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 24 | chomp($line); | |||||||||||||||||||||||||||
| 26 | 24 | $line =~ s/\s*\#HttpOnly_//; | |||||||||||||||||||||||||||
| 27 | 24 | ▶ | next if $line =~ /^\s*\#/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 12 | ▶ | next if $line =~ /^\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 6 | $line =~ tr/\n\r//d; | |||||||||||||||||||||||||||
| 30 | 6 | my ( $domain, $bool1, $path, $secure, $expires, $key, $val ) | |||||||||||||||||||||||||||
| 31 | = split( /\t/, $line ); | ||||||||||||||||||||||||||||
| 32 | 6 | $secure = ( $secure eq "TRUE" ); | |||||||||||||||||||||||||||
| 33 | 6 | $self->set_cookie( | |||||||||||||||||||||||||||
| 34 | undef, $key, $val, $path, $domain, undef, 0, | ||||||||||||||||||||||||||||
| 35 | $secure, $expires - $now, 0 | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 3 | 1; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | sub save { | ||||||||||||||||||||||||||
|
Subroutine
save: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | my %args = ( | ||||||||||||||||||||||||||||
| 44 | file => $self->{'file'}, | ||||||||||||||||||||||||||||
| 45 | 2 | ▶ | ignore_discard => $self->{'ignore_discard'}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | @_ == 1 ? ( file => $_[0] ) : @_ | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | 2 | ▶ | Carp::croak('Unexpected argument to save method') if keys %args > 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 2 | ▶ | my $file = $args{'file'} || return; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'file'} || (return)
MC/DC0%0/1
$args{'file'} || (return)
$args{'file'}
Truth table50%1/2
A
A= $args{'file'}
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | open( my $fh, '>', $file ) || return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # Use old, now broken link to the old cookie spec just in case something | ||||||||||||||||||||||||||||
| 54 | # else (not us!) requires the comment block exactly this way. | ||||||||||||||||||||||||||||
| 55 | 2 | print {$fh} <<EOT; | |||||||||||||||||||||||||||
| 56 | # Netscape HTTP Cookie File | ||||||||||||||||||||||||||||
| 57 | # http://www.netscape.com/newsref/std/cookie_spec.html | ||||||||||||||||||||||||||||
| 58 | # This is a generated file! Do not edit. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | EOT | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | my $now = time - $HTTP::Cookies::EPOCH_OFFSET; | |||||||||||||||||||||||||||
| 63 | $self->scan( | ||||||||||||||||||||||||||||
| 64 | 4 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||
| 65 | my ( | ||||||||||||||||||||||||||||
| 66 | 4 | $version, $key, $val, $path, $domain, $port, $path_spec, | |||||||||||||||||||||||||||
| 67 | $secure, $expires, $discard, $rest | ||||||||||||||||||||||||||||
| 68 | ) = @_; | ||||||||||||||||||||||||||||
| 69 | 4 | ▶ | return if $discard && !$args{'ignore_discard'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$discard and not $args{"ignore_discard"}
MC/DC50%1/2
$discard and not $args{"ignore_discard"}
$discard
not $args{"ignore_discard"}
Truth table66%2/3
A and not(B)
A= $discardB= not $args{"ignore_discard"}
| |||||||||||||||||||||||||||||
| 70 | 3 | ▶ | $expires = $expires ? $expires - $HTTP::Cookies::EPOCH_OFFSET : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 3 | ▶ | return if $now > $expires; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | $secure = $secure ? "TRUE" : "FALSE"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | my $bool = $domain =~ /^\./ ? "TRUE" : "FALSE"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 2 | print {$fh} join( | |||||||||||||||||||||||||||
| 75 | "\t", $domain, $bool, $path, $secure, $expires, $key, | ||||||||||||||||||||||||||||
| 76 | $val | ||||||||||||||||||||||||||||
| 77 | ), | ||||||||||||||||||||||||||||
| 78 | "\n"; | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 2 | ); | |||||||||||||||||||||||||||
| 81 | 2 | 1; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 7 | 1; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =pod | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head1 NAME | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | HTTP::Cookies::Netscape - Access to Netscape cookies files | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 VERSION | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | version 6.12 | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | use LWP; | ||||||||||||||||||||||||||||
| 101 | use HTTP::Cookies::Netscape; | ||||||||||||||||||||||||||||
| 102 | $cookie_jar = HTTP::Cookies::Netscape->new( | ||||||||||||||||||||||||||||
| 103 | file => "c:/program files/netscape/users/ZombieCharity/cookies.txt", | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | my $browser = LWP::UserAgent->new; | ||||||||||||||||||||||||||||
| 106 | $browser->cookie_jar( $cookie_jar ); | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | This is a subclass of C<HTTP::Cookies> that reads (and optionally | ||||||||||||||||||||||||||||
| 111 | writes) Netscape/Mozilla cookie files. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | See the documentation for L<HTTP::Cookies>. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head1 CAVEATS | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | Please note that the Netscape/Mozilla cookie file format can't store | ||||||||||||||||||||||||||||
| 118 | all the information available in the Set-Cookie2 headers, so you will | ||||||||||||||||||||||||||||
| 119 | probably lose some information if you save in this format. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | At time of writing, this module seems to work fine with Mozilla | ||||||||||||||||||||||||||||
| 122 | Phoenix/Firebird. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | L<HTTP::Cookies::Microsoft> | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | Gisle Aas <gisle@activestate.com> | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | This software is copyright (c) 2002 by Gisle Aas. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 137 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | __END__ | ||||||||||||||||||||||||||||