Metadata::DB::File::Indexer
The indexer object is a main interface to creating and managing metadata tables about many files. This object does not manage child instances of Metadata::DB::File, code that elsewhere.
# start a database handle my $dbh; my $i = Metadata::DB::File::Indexer->new({ DBH => $dbh }); $i->table_all_reset; # clear everything # You are left to figure out on your own what files to index my @files; $i->files_to_index(\@files); # you should determine what metadata will be stored for each # by overriding Metadata::DB::File::Indexer::_abs_path_to_metadata() no warnings 'redefine'; *Metadata::DB::File::Indexer::_abs_path_to_metadata = \&mysub; sub mysub { my $abs_path = shift; my $meta = {}; #whatever you want return $meta; } $i->run;
If you want to reindex an entire archive you should
1) reset/clear the tables $i->table_all_reset; 2) determine the files you want to index, abs paths my @files; $i->files_to_index_set(\@files); 3) define a method to turn one of the paths to metadata &Metadata::DB::File::Indexer::_abs_path_to_metadata = sub { my $abs_path = shift; my hash = {} ; return $hash; }
What if you only want to reindex a section? Maybe you indexed /home/myself/mp3s but you just want to reindex a subpath...
1) reset that portion $i->tree_clear('/home/myself/mp3s'); 2) determine the files you will index, used File::Find::Rule etc my @files 3) determine how to convert into a metadata hash &Metadata::DB::File::Indexer::_abs_path_to_metadata = sub { my $abs_path = shift; my hash = {} ; return $hash; } 3) set and run $i->files_to_index_set(\@files); $i->run;
required arg is hashref with key DBH to open database handle
my $i = Metadata::DB::File::Indexer({ DBH => $dbh });
you'll have to call for the first time
returns number
arg is array ref with abs paths to files on disk
returns count of files indexed
takes no args runs the indexing procedure
What if you want to store in another table?
Data is stored in two tables, the metadata table, and the files table. to rename these..
(To read more: Metadata::DB::Base and Metadat::DB::File::Base )
arg is string
Before you index, make sure the entries are cleared.. you can do this:
$i->tree_clear('/lowest/common/denominator/base'); $i->run;
If you know will reindex the entire achive tree(everything you want to be in the db), then you can simple reset the metadata and files table:
$i->table_all_reset; $i->run;
Metadata::DB Metadata::DB::Base Metadata::DB::Search Metadata::DB::Analizer Metadata::DB::File Metadata::DB::File::Base
Leo Charre leocharre at cpan dot org
To install Metadata::DB::File, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Metadata::DB::File
CPAN shell
perl -MCPAN -e shell install Metadata::DB::File
For more information on module installation, please visit the detailed CPAN module installation guide.