$log->logconfess("lookup argument is not suppored any more. rewrite call to lookup_ref") if ($self->{lookup});
$log->logconfess("specify low-level file format module") unless ($self->{module});
- my $module = $self->{module};
- $module =~ s#::#/#g;
- $module .= '.pm';
- $log->debug("require low-level module $self->{module} from $module");
+ my $module_path = $self->{module};
+ $module_path =~ s#::#/#g;
+ $module_path .= '.pm';
+ $log->debug("require low-level module $self->{module} from $module_path");
- require $module;
- #eval $self->{module} .'->import';
+ require $module_path;
# check if required subclasses are implemented
foreach my $subclass (qw/open_db fetch_rec init dump_rec/) {
- my $n = $self->{module} . '::' . $subclass;
- if (! defined &{ $n }) {
- my $missing = "missing $subclass in $self->{module}";
- $self->{$subclass} = sub { $log->logwarn($missing) };
- } else {
- $self->{$subclass} = \&{ $n };
- }
- }
-
- if ($self->{init}) {
- $log->debug("calling init");
- $self->{init}->($self, @_);
+ # FIXME
}
$self->{'encoding'} ||= 'ISO-8859-2';
}
$log->debug("rec_regex: ", Dumper($rec_regex)) if ($rec_regex);
- my ($db, $size) = $self->{open_db}->( $self,
+ my $class = $self->{module} || $log->logconfess("can't get low-level module name!");
+
+ my $ll_db = $class->new(
path => $arg->{path},
# filter => sub {
# my ($l,$f_nr) = @_;
%{ $arg },
);
- unless (defined($db)) {
+ unless (defined($ll_db)) {
$log->logwarn("can't open database $arg->{path}, skipping...");
return;
}
+ my $size = $ll_db->size;
+
unless ($size) {
$log->logwarn("no records in database $arg->{path}, skipping...");
return;
$log->debug("position: $pos\n");
- my $rec = $self->{fetch_rec}->($self, $pos, sub {
+ my $rec = $ll_db->fetch_rec($pos, sub {
my ($l,$f_nr) = @_;
# return unless defined($l);
# return $l unless ($rec_regex && $f_nr);
if ($self->{stats}) {
# fetch clean record with regexpes applied for statistics
- my $rec = $self->{fetch_rec}->($self, $pos);
+ my $rec = $ll_db->fetch_rec($pos);
foreach my $fld (keys %{ $rec }) {
$self->{_stats}->{fld}->{ $fld }++;
use WebPAC::Input;
use Biblio::Isis 0.23;
+use base qw/WebPAC::Common/;
=head1 NAME
=head1 VERSION
-Version 0.07
+Version 0.08
=cut
-our $VERSION = '0.07';
+our $VERSION = '0.08';
=head1 SYNOPSIS
Open CDS/ISIS, WinISIS or IsisMarc database using C<Biblio::Isis>
and read all records to memory.
- my $isis = new WebPAC::Input::ISIS();
- $isis->open( path => '/path/to/ISIS/ISIS' );
+ my $isis = new WebPAC::Input::ISIS(
+ path => '/path/to/ISIS/ISIS',
+ );
=head1 FUNCTIONS
-=head2 open_db
+=head2 new
-Returns handle to database and size in records
+Returns new low-level input API object
- my ($db,$size) = $isis->open_db(
+ my $isis = new WebPAC::Input::ISIS(
path => '/path/to/LIBRI'
filter => sub {
my ($l,$field_nr) = @_;
=cut
-sub open_db {
- my $self = shift;
+sub new {
+ my $class = shift;
+ my $self = {@_};
+ bless($self, $class);
my $arg = {@_};
hash_filter => $arg->{filter} ? sub { return $arg->{filter}->(@_); } : undef,
) or $log->logdie("can't find database $arg->{path}");
- my $size = $isis_db->count;
-
$self->{_isis_db} = $isis_db;
- return ($isis_db, $size);
+ $self ? return $self : return undef;
}
=head2 fetch_rec
Return record with ID C<$mfn> from database
- my $rec = $self->fetch_rec( $mfn, $filter_coderef);
+ my $rec = $isis->fetch_rec( $mfn, $filter_coderef);
=cut
Return dump of record ID C<$mfn> from database
- my $rec = $self->dump_rec( $db, $mfn );
+ my $rec = $isis->dump_rec( $db, $mfn );
=cut
return $self->{_isis_db}->to_ascii( $mfn );
}
+=head2 size
+
+Return number of records in database
+
+ my $size = $isis->size;
+
+=cut
+
+sub size {
+ my $self = shift;
+ return $self->{_isis_db}->count;
+}
+
=head1 AUTHOR
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
use strict;
use MARC::Fast 0.03;
+use base qw/WebPAC::Common/;
=head1 NAME
=head1 VERSION
-Version 0.05
+Version 0.06
=cut
-our $VERSION = '0.05';
+our $VERSION = '0.06';
=head1 SYNOPSIS
Open USMARC, Unimarc or any other file format that has same internal
structure using C<MARC::Fast>.
- my $marc = new WebPAC::Input::MARC();
- $marc->open( path => '/path/to/marc.iso' );
+ my $marc = new WebPAC::Input::MARC(
+ path => '/path/to/marc.iso'
+ );
=head1 FUNCTIONS
-=head2 open_db
+=head2 new
-Returns handle to database and size in records
+Returns new low-level input API object
- my ($db,$size) = $open_db(
+ my $marc = new WebPAC::Input::MARC(
path => '/path/to/marc.iso',
filter => \&code_ref,
}
=cut
-sub open_db {
- my $self = shift;
+sub new {
+ my $class = shift;
+ my $self = {@_};
+ bless($self, $class);
my $arg = {@_};
$self->{_marc_size} = $db_size;
$self->{_marc_db} = $db;
- return ($db, $db_size);
+ $self ? return $self : return undef;
}
=head2 fetch_rec
}
}
-=head1 PROPERTIES
+=head2 size
-=head2 _marc_size
+Return number of records in database
-Store size of MARC database
+ my $size = $isis->size;
- print $self->{_marc_size};
+=cut
+sub size {
+ my $self = shift;
+ return $self->{_marc_size};
+}
=head1 AUTHOR