Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make things more robust; Book->publisher

  • Loading branch information...
commit adc41a6a156a9c71c04a1d9c77570cd2529184ff 1 parent 6980af5
@moritz authored
Showing with 17 additions and 11 deletions.
  1. +15 −9 lib/WebService/Libris/Book.pm
  2. +2 −2 lib/WebService/Libris/FileCache.pm
View
24 lib/WebService/Libris/Book.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use 5.010;
-__PACKAGE__->_make_text_accessor(qw/title date/, ['isbn', 'isbn10']);
+__PACKAGE__->_make_text_accessor(qw/title date publisher/, ['isbn', 'isbn10']);
sub fragments {
'bib', shift->id;
@@ -42,14 +42,16 @@ sub authors_ids {
sub language_marc {
my $self = shift;
- my $l = $self->dom->at('language');
- return unless $l;
- $l = $l->attrs->{'rdf:resource'};
- if ($l =~ m{http://purl.org/NET/marccodes/languages/(\w{3})(?:\#lang)?}) {
- return "$1";
- } else {
- return undef;
- }
+
+ my @l = $self->dom->find('language')->each;
+ @l = grep $_, map $_->attrs->{'rdf:resource'}, @l;
+ return undef unless @l;
+
+ @l = map { m{http://purl.org/NET/marccodes/languages/(\w{3})(?:\#lang)?} && "$1" } @l;
+ # somehow the last language code seems to be more reliable than the first
+ # one - no idea why
+ return $l[-1] if @l;
+ undef;
}
sub language {
@@ -93,6 +95,10 @@ returns the publication date as a string (often just a year)
returns the ISBN
+=head2 publisher
+
+returns the name of the publisher
+
=head2 related_books
returns a collection of related books
View
4 lib/WebService/Libris/FileCache.pm
@@ -19,9 +19,9 @@ sub _filename {
sub get {
my ($self, $key) = @_;
my $filename = $self->_filename($key);
- return unless open my $h, '<', $filename;
+ return undef unless open my $h, '<', $filename;
my $contents = do { local $/; <$h> };
- return unless length $contents;
+ return undef unless length $contents;
Mojo::DOM->new(xml => 1, charset => 'UTF-8')->parse($contents);
}
Please sign in to comment.
Something went wrong with that request. Please try again.