NAME

Metadata::DB

SYNOPSIS

use Metadata::DB;

my $dbh;
my $o = new Metadata::DB($dbh);
$o->load;
$o->set( name => 'jack' );
$o->set( age  =>  14 );
$o->id(4);
$o->save;


my $o2 = new Metadata::DB($dbh);
$o2->id(4);
$o2->load;
$o2->get( 'name' );
$o2->set( 'age' => 44 );

Loading metadata from db

via constructor

If you pass the id to the constructor, it will attempt to load from db.

my $o = new Metadata::DB({ DBH => $dbh, id => 'james' });
via methods

You can directly tell it what the id will be , and then request to load.

my $o = new Metadata::DB({ DBH => $dbh });
$o->id('james');
$o->load;
checking for record
my $o = new Metadata::DB({ DBH => $dbh });
$o->id('james');
$o->load; # you must call load
$o->id_exists;

DESCRIPTION

Inherits Metadata::Base and all its methods.

new()

Argument is hash ref with at least a DBH argument, which is a database handle.

my $o = Metadata::DB->new({ DBH = $dbh });

Optional argument is 'id'.

id()

Perl setget method. Arg is number.

id_exists()

Returns boolean. If the id is in the database, that is- if the record by this id has any entries in the metadata table, this returns true.

entries_count()

Returns number of entries for this id.

set()

Works like Metadata::Base::set()

$o->set( name => 'Jack' );

elements()

See Metadata::Base.

add()

Works like set(), only you can provide many entries.

$o->add(
   name => 'this',
   age => 4,
);

write(), save()

Save to db. You call this to create a new record as well. Returns id.

load(), read()

Will attempt to load from db. YOU MUST CALL load() to check what is in the database.

loaded()

Returns boolean If load() was triggered or called or not.

get_all()

Returns hashref with all meta. Will attempt to load from db.

get()

See Metadata::Base.

$o->get('name');

CAVEATS

WARNING Calling save() before load() will delete all record metadata previously saved.

Delete ALL metadata with id 5 and save only 'name marc'.

my $m = Metadata::DB->new({ DBH => $dbh, id => 5 });
$m->set( name=> 'marc' );
$m->save;

After, this will NOT load the metadata 'name marc':

my $m = Metadata::DB->new({ DBH => $dbh, id => 5 });
$m->get( 'name' );

This example WILL load the metadata:

my $m3= Metadata::DB->new({ DBH => $dbh, id => 5 });
$m->load;
$m->get( 'name' );

This example will NOT delete metadata and will add instead:

my $m = Metadata::DB->new({ DBH => $dbh, id => 5 });
$m->load;
$m->set( age => 25 );
$m->save;

Why? Why not just override get and get all to take care of this? Wny not just call load() automatically?? Because that's up to you. You MAY want to NOT do this cpu intensive operation. Maybe you want to insert a million entries really quickly, thus you dont want to load every time, maybe you already know there is nothing in there.

SEE ALSO

Metadata::Base Metadata::DB::Base Metadata::DB::Indexer Metadata::DB::Analizer Metadata::DB::WUI

AUTHOR

Leo Charre leocharre at cpan dot org

1 POD Error

The following errors were encountered while parsing the POD:

Around line 167:

You forgot a '=back' before '=head1'