HTML::Index::Store::DataDumper - subclass of


HTML-Index documentation Contained in the HTML-Index distribution.

Index


Code Index:

NAME

Top

HTML::Index::Store::DataDumper - subclass of HTML::Index::Store using Data::Dumper.

SYNOPSIS

Top

    my $store = HTML::Index::Store::DataDumper->new( 
        DB => $path_to_data_dumper_file_directory
    );

DESCRIPTION

Top

This module is a subclass of the HTML::Index::Store module, that uses Data::Dumper files to store the inverted index.

SEE ALSO

Top

HTML::Index =item HTML::Index::Store

AUTHOR

Top

Ave Wrigley <Ave.Wrigley@itn.co.uk>

COPYRIGHT

Top


HTML-Index documentation Contained in the HTML-Index distribution.

package HTML::Index::Store::DataDumper;

#------------------------------------------------------------------------------
#
# Modules
#
#------------------------------------------------------------------------------

use Data::Dumper;
use File::Path;
use Carp;

require HTML::Index::Store;
use vars qw( @ISA );
@ISA = qw( HTML::Index::Store );

#------------------------------------------------------------------------------
#
# Initialization public method
#
#------------------------------------------------------------------------------

sub init
{
    my $self = shift;

    croak "No DB\n" unless defined $self->{DB};
    $self->{MODE} ||= 'rw';
    unless ( -d $self->{DB} )
    {
        mkpath( $self->{DB} ) or croak "can't mkpath ", $self->{DB}, ": $!\n";
    }
    $self->SUPER::init();
    return $self;
}

sub create_table
{
    my $self = shift;
    my $table = shift;

    my $path = $self->{DB} . "/$table.pl";
    if ( -e $path )
    {
        if ( $self->{REFRESH} ) { unlink( $path ); }
        else { $self->{$table} = do $path; }
    }
    $self->{PATH}{$table} = $path;
}

#------------------------------------------------------------------------------
#
# Destructor
#
#------------------------------------------------------------------------------

sub DESTROY
{
    my $self = shift;

    return unless $self->{MODE} =~ /w/;
    for my $table ( keys %{$self->{PATH}} )
    {
        my $hash = $self->{$table};
        my $path = $self->{PATH}{$table};
        open( FH, ">$path" ) or die "Can't write to $path\n";
        print FH Dumper( $hash );
        close( FH );
    }
}

#------------------------------------------------------------------------------
#
# True
#
#------------------------------------------------------------------------------

1;

__END__