Select Git revision
cycled_exp.py
TOC.pm 2.27 KiB
#!/usr/bin/perl
package Tomboy::TOC;
use strict;
use Tomboy::Directory;
sub new
{
my $class= shift;
my $self= {};
bless $self, $class;
$self->set (@_);
$self;
}
sub set
{
my $self= shift;
my %par= @_;
foreach my $par (keys %par) { $self->{$par}= $par{$par}; }
}
=head2 $toc->find($pattern [, $where])
Search TOC for matching $pattern in field specified by $where; if $where is not defined, 'title' is used.
Returns a list of matching TOC entries
=cut
sub find
{
my $self= shift;
my $pattern= shift;
my $where= shift || 'title';
print "find: where=[$where] pattern=[$pattern]\n";
my ($mode, $toc, $rows)= $self->load_toc();
my @res;
foreach my $row (@$rows)
{
next unless ($row->{$where} =~ m#$pattern#i);
# print "row: ", main::Dumper ($row);
push (@res, $row);
}
@res;
}
# Note: there is also a Tomboy::Directoy::scan_dir()
sub scan_dir
{
my $self= shift;
print main::Dumper ($self);
my ($note_dir, $toc_file)= map { $self->{$_} } qw(note_dir toc_file);
$note_dir=~ s#/+$##;
my $tb_d= new Tomboy::Directory ();
# print "tb_d: ", Dumper ($tb_d);
print "scanning [$note_dir]\n";
my ($mode, $toc, $rows)= $self->load_toc();
my $toc_data= $tb_d->scan_dir ($note_dir, $rows, $mode);
# TODO: if verbose or so print "toc_data: ", Dumper ($toc_data);