1 package HTTP::Cookies::Netscape;
4 use vars qw(@ISA $VERSION);
9 @ISA=qw(HTTP::Cookies);
13 my($self, $file) = @_;
14 $file ||= $self->{'file'} || return;
16 local $/ = "\n"; # make sure we got standard record separator
18 open(FILE, $file) || return;
20 unless ($magic =~ /^\#(?: Netscape)? HTTP Cookie File/) {
21 warn "$file does not look like a netscape cookies file" if $^W;
25 my $now = time() - $HTTP::Cookies::EPOCH_OFFSET;
30 my($domain,$bool1,$path,$secure, $expires,$key,$val) = split(/\t/, $_);
31 $secure = ($secure eq "TRUE");
32 $self->set_cookie(undef,$key,$val,$path,$domain,undef,
33 0,$secure,$expires-$now, 0);
41 my($self, $file) = @_;
42 $file ||= $self->{'file'} || return;
44 open(FILE, ">$file") || return;
46 # Use old, now broken link to the old cookie spec just in case something
47 # else (not us!) requires the comment block exactly this way.
49 # Netscape HTTP Cookie File
50 # http://www.netscape.com/newsref/std/cookie_spec.html
51 # This is a generated file! Do not edit.
55 my $now = time - $HTTP::Cookies::EPOCH_OFFSET;
57 my($version,$key,$val,$path,$domain,$port,
58 $path_spec,$secure,$expires,$discard,$rest) = @_;
59 return if $discard && !$self->{ignore_discard};
60 $expires = $expires ? $expires - $HTTP::Cookies::EPOCH_OFFSET : 0;
61 return if $now > $expires;
62 $secure = $secure ? "TRUE" : "FALSE";
63 my $bool = $domain =~ /^\./ ? "TRUE" : "FALSE";
64 print FILE join("\t", $domain, $bool, $path, $secure, $expires, $key, $val), "\n";
75 HTTP::Cookies::Netscape - access to Netscape cookies files
80 use HTTP::Cookies::Netscape;
81 $cookie_jar = HTTP::Cookies::Netscape->new(
82 file => "c:/program files/netscape/users/ZombieCharity/cookies.txt",
84 my $browser = LWP::UserAgent->new;
85 $browser->cookie_jar( $cookie_jar );
89 This is a subclass of C<HTTP::Cookies> that reads (and optionally
90 writes) Netscape/Mozilla cookie files.
92 See the documentation for L<HTTP::Cookies>.
96 Please note that the Netscape/Mozilla cookie file format can't store
97 all the information available in the Set-Cookie2 headers, so you will
98 probably lose some information if you save in this format.
100 At time of writing, this module seems to work fine with Mozilla
105 L<HTTP::Cookies::Microsoft>
109 Copyright 2002-2003 Gisle Aas
111 This library is free software; you can redistribute it and/or
112 modify it under the same terms as Perl itself.