Netscape-Cache

 view release on metacpan or  search on metacpan

Cache.pm  view on Meta::CPAN

	  $o->{'URL'}, "\n",
	  $o->{'CACHEFILE'}, "\n",
	  $o->{'LAST_MODIFIED'}, "\n",
	  $o->{'MIME_TYPE'}, "\n";
    }

The TIEHASH interface:

    use Netscape::Cache;

    tie %cache, 'Netscape::Cache';
    foreach (sort keys %cache) { 
	print $cache{$_}->{URL}, "\n";
    }

=head1 DESCRIPTION

The B<Netscape::Cache> module implements an object class for
accessing the filenames and URLs of the cache files used by the
Netscape web browser.

Note: You can also use the undocumented pseudo-URLs C<about:cache>,
C<about:memory-cache> and C<about:global-history> to access your disk
cache, memory cache and global history.

There is also an interface for using tied hashes.

Netscape uses the old Berkeley DB format (version 1.85) for its cache
index C<index.db>. Versions 2 and newer of Berkeley DB are
incompatible with the old format (L<db_intro(3)>), so you have either
to downgrade or to convert the database using B<db_dump185> and
B<db_load>. See L<convert_185_2xx|/convert_185_2xx> for a
(experimental) converter function.

=cut

package Netscape::Cache;
use strict;
use vars qw($Default_Preferences $Default_40_Preferences @Try_Preferences
	    $Default_Cache_Dir @Default_Cache_Index
	    $Debug $Home $OS_Type $VERSION);

use DB_File;

if (defined $DB_File::db_version and $DB_File::db_version > 1) {
    warn "Netscape::Cache works only if Berkeley db version 1 is\n" .
      "installed. Please use the convert_185_2xx function to convert\n" .
	"the cache index to the new db format (see manpage).\n";
}

if ($^O =~ /^((ms)?(win|dos)|os2)/i) {
    $Default_Preferences = 'C:\NETSCAPE\NETSCAPE.INI';
    @Try_Preferences     = qw(D:\NETSCAPE\NETSCAPE.INI
			      C:\INTERNET\NETSCAPE\NETSCAPE.INI
			      D:\INTERNET\NETSCAPE\NETSCAPE.INI
			      C:\PROGRAMS\NETSCAPE\NETSCAPE.INI);
    $Default_Cache_Dir   = 'C:\NETSCAPE\CACHE';
    @Default_Cache_Index = qw(FAT.DB INDEX.DB);
    $OS_Type = 'win';
} else {
    $Home = $ENV{'HOME'} || (getpwuid($>))[7];
    $Default_Preferences    = "$Home/.netscape/preferences";
    @Try_Preferences        = ();
    $Default_40_Preferences = "$Home/.netscape/preferences.js";
    $Default_Cache_Dir      = "$Home/.netscape/cache";
    @Default_Cache_Index    = qw(index.db FAT.DB fat.db Fat.db);
    $OS_Type = 'unix';
}

$Debug = 0;
$VERSION = '0.46';

=head1 CONSTRUCTOR

    $cache = new Netscape::Cache(-cachedir => "$ENV{HOME}/.netscape/cache");

This creates a new instance of the B<Netscape::Cache> object class. The
I<-cachedir> argument is optional. By default, the cache directory setting
is retrieved from C<~/.netscape/preferences>. The index file is normally
named C<index.db> on Unix systems and C<FAT.DB> on Microsoft systems. It may
be changed with the I<-index> argument.

If the Netscape cache index file does not exist, a warning message
will be generated, and the constructor will return C<undef>.

=cut

sub new ($;%) {
    my($pkg, %a) = @_;
    my($try, $indexfile);
    my $cachedir = $a{-cachedir} || get_cache_dir() || $Default_Cache_Dir;
    if ($a{'-index'}) {
	$indexfile =
	  ($a{'-index'} =~ m|^/| ? $a{'-index'} : "$cachedir/$a{'-index'}");
    } else {
	foreach $try (@Default_Cache_Index) {	#try all the names
	    $indexfile = "$cachedir/$try";
	    last if -f $indexfile;		#exit when we find one
	}
    }
    if (-f $indexfile) {
	my %cache;
	my $self = {};
	if (!tie %cache, 'DB_File', $indexfile) {
	    warn
	      "Can't tie <$indexfile>. Maybe you are using version 2.x.x\n",
	      "of the Berkeley DB library?\n";
	    return undef;
	}
	$self->{CACHE}     = \%cache;
	$self->{CACHEDIR}  = $cachedir;
	$self->{CACHEFILE} = $indexfile;
	bless $self, $pkg;
    } else {
	warn "No cache db found. Try to set the cache direcetory with\n" .
	  "-cachedir and the index file with -index.\n";
        undef;
    }
}

sub TIEHASH ($;@) {



( run in 1.994 second using v1.01-cache-2.11-cpan-39bf76dae61 )