Oryx::DBM::Util - Oryx DBM utilities


Oryx documentation Contained in the Oryx distribution.

Index


Code Index:

NAME

Top

Oryx::DBM::Util - Oryx DBM utilities

DESCRIPTION

Top

The following methods are defined to manipulate a DBM::Deep database schema.

METHODS

Top

table_exists( $dbm, $table )

Returns a true value if the table named $table exists within $dbm.

table_create( $dbm, $table )

Creates a table named $table in $dbm.

table_drop( $dbm, $table )

Drops the table named $table in $dbm.

AUTHORS

Top

Richard Hundt <richard NO SPAM AT protea-systems.com>

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Oryx documentation Contained in the Oryx distribution.

package Oryx::DBM::Util;

use File::Spec;
use DBM::Deep;

sub new {
    my $class = shift;
    return bless { }, $class;
}

sub table_exists {
    my ($self, $dbm, $table) = @_;
    return -e File::Spec->catfile($dbm->datapath, $table);
}

sub table_create {
    my ($self, $dbm, $table) = @_;
    my $filename = File::Spec->catfile($dbm->datapath, $table);
    $dbm->catalog->put( $table, {
	file      => $filename,
	type      => DBM::Deep::TYPE_ARRAY,
        autoflush => 1,
	locking => 1,
    });
}

sub table_drop {
    my ($self, $dbm, $table) = @_;
    my $meta = $dbm->catalog->get( $table );
    return unless $meta; # not defined for link tables
    unlink $meta->{file};
    $dbm->catalog->delete( $table );
}

1;
__END__