dotReader

 view release on metacpan or  search on metacpan

lib/dtRdr/Library.pm  view on Meta::CPAN

=cut

sub get_metadata {
  my $self = shift;
  if(defined $self->{metadata}) {
    return @{$self->{metadata}};
  }
  else { # this wasn't even returning a value!
    do('./util/BREAK_THIS') or die;
    $self->_fetch_all_metadata();
  }
}

=head2 get_book_info

Return a list of book info objects.

  my @infos = $lib->get_book_info;

=cut

sub get_book_info {
  my $self = shift;
  return @{$self->book_data};
}

=head2 open_book

Return a book object matching a given key/value lookup pair.

  $lib->open_book(intid => $id);

or

  $lib->open_book(title => $title);

or

  $lib->open_book(book_id => $book_id);

=cut

sub open_book {
  my $self = shift;
  (@_ % 2) and croak('odd number of elements in argument list');
  my (%args) = @_;
  my @valid = qw(intid title book_id);
  my ($key) = grep({exists($args{$_})} @valid);
  $key or croak('no valid key (',
    join(', ', @valid), ') in arguments: (', join(',', keys(%args)), ')');

  my @books = $self->find_book_by($key, $args{$key});
  @books or die "no books matching $key eq $args{$key}";
  (@books == 1) or die "too many books @books";
  my $B = $books[0];
  # this will get us by until config is operable
  # (and shouldn't break after it works either)
  require dtRdr::Plugins::Book;
  dtRdr::Plugins::Book->init();

  # requires that config sets type -> class prefs
  my $book_class = dtRdr::Plugins::Book->class_for_type($B->type);
  $book_class or die "cannot get a plugin for $B->{type}";
  0 and warn "book class: $book_class";
  my $book_object = $book_class->new();

  # TODO add abstraction somewhere in here
  #      (e.g. it might be http://, absolute, etc)
  my $uri = $self->directory . '/' . $B->uri;
  # NOTE:  Do not be tempted to (-e $uri) here, let the book die.
  0 and warn "book is $uri";
  $book_object->load_uri($uri);

  # XXX does it need the library?
  # $book_object->set('library', $self);

  return($book_object);
} # end subroutine open_book definition
########################################################################

=head2 find_book_by

Virtual:  find a book for a given $key/$value match.

  $info = $lib->find_book_by($key, $value);

=cut

sub find_book_by { my $self = shift; $self->NOT_IMPLEMENTED(@_); }

=head2 add_metadata

Add the C<metadata> object to the C<book>, stored in the library

=cut

sub add_metadata { my $self = shift; $self->NOT_IMPLEMENTED(@_); }

=head2 delete_metadata

Remove the C<metadata> from the specified C<book>, as it's stored in
the library.

  $lib->delete_metadata($book, $metadata);

=cut

sub delete_metadata { my $self = shift; $self->NOT_IMPLEMENTED(@_); }

=head2 add_book

=cut

sub add_book { my $self = shift; $self->NOT_IMPLEMENTED(@_); }

=head2 remove_book

Remove the book.

All metadata for the book will be deleted from the library.



( run in 2.019 seconds using v1.01-cache-2.11-cpan-8f98c5d2c55 )