| 1 | package WebService::Libris::Book; | ||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'WebService::Libris'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use WebService::Libris::Utils qw/marc_lang_code_to_iso/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 1 | __PACKAGE__->_make_text_accessor(qw/title date publisher/, ['isbn', 'isbn10']); | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | sub fragments { | ||||||||||||||||||
|
Subroutine
fragments: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 11 | 1 | 'bib', shift->id; | |||||||||||||||||||
| 12 | } | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 0 | ▶ | sub related_books { shift->list_from_dom('frbr_related') } | ||||||||||||||||||
|
Subroutine
related_books: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 15 | 1 | ▶ | sub held_by { shift->list_from_dom('held_by') } | ||||||||||||||||||
|
Subroutine
held_by: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 16 | 1 | ▶ | sub authors_obj { shift->list_from_dom('creator') } | ||||||||||||||||||
|
Subroutine
authors_obj: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | sub authors_text { | ||||||||||||||||||
|
Subroutine
authors_text: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||
| 19 | 1 | my $self = shift; | |||||||||||||||||||
| 20 | 1 | my @authors = grep length, map $_->text, $self->dom->find('creator')->each; | |||||||||||||||||||
| 21 | # XXX: come up with something better | ||||||||||||||||||||
| 22 | 1 | ▶ | if (wantarray) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 23 | 1 | return @authors; | |||||||||||||||||||
| 24 | } elsif (@authors == 1) { | ||||||||||||||||||||
| 25 | 0 | return $authors[0] | |||||||||||||||||||
| 26 | } else { | ||||||||||||||||||||
| 27 | 0 | return join ", ", @authors; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | sub isbns { | ||||||||||||||||||
|
Subroutine
isbns: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||
| 33 | 0 | map $_->text, $self->dom->find('isbn10')->each; | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 2 | ▶ | sub authors_ids { | ||||||||||||||||||
|
Subroutine
authors_ids: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 37 | 2 | my $self = shift; | |||||||||||||||||||
| 38 | 2 | my %seen; | |||||||||||||||||||
| 39 | my @ids = sort | ||||||||||||||||||||
| 40 | 2 | grep { !$seen{$_}++ } | |||||||||||||||||||
| 41 | 2 | map { (split '/', $_)[-1] } | |||||||||||||||||||
| 42 | grep $_, | ||||||||||||||||||||
| 43 | 2 | map { $_->attr('rdf:resource') } | |||||||||||||||||||
| 44 | $self->dom->find('creator')->each; | ||||||||||||||||||||
| 45 | 2 | return @ids; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 2 | ▶ | sub languages_marc { | ||||||||||||||||||
|
Subroutine
languages_marc: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||
| 49 | 2 | my $self = shift; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 2 | my @l = $self->dom->find('language')->each; | |||||||||||||||||||
| 52 | 2 | @l = grep $_, map $_->attr('rdf:resource'), @l; | |||||||||||||||||||
| 53 | 2 | ▶ | return undef unless @l; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 2 | ▶ | map { m{http://purl.org/NET/marccodes/languages/(\w{3})(?:\#lang)?} && "$1" } @l; | ||||||||||||||||||
|
Condition33%1/3
m[http://purl.org/NET/marccodes/languages/(\w{3})(?:\#lang)?]d && "$1"
MC/DC0%0/2
m[http://purl.org/NET/marccodes/languages/(\w{3})(?:\#lang)?]d && "$1"
m[http://purl.org/NET/marccodes/languages/(\w{3})(?:\#lang)?]d
"$1"
Truth table33%1/3
A && B
A= m[http://purl.org/NET/marccodes/languages/(\w{3})(?:\#lang)?]dB= "$1"
| |||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | sub language_marc { | ||||||||||||||||||
|
Subroutine
language_marc: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 59 | 0 | ▶ | (shift->languages_marc)[-1] // () | ||||||||||||||||||
|
Condition0%0/3
((shift())->languages_marc)[-1] // ()
MC/DC0%0/2
((shift())->languages_marc)[-1] // ()
((shift())->languages_marc)[-1]
()
Truth table0%0/3
A // B
A= ((shift())->languages_marc)[-1]B= ()
| |||||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 2 | ▶ | sub languages { | ||||||||||||||||||
|
Subroutine
languages: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||
| 63 | 2 | my $self = shift; | |||||||||||||||||||
| 64 | 2 | my @langs = map marc_lang_code_to_iso($_), $self->languages_marc; | |||||||||||||||||||
| 65 | 2 | for ($self->dom->find('*[lang]')->each) { | |||||||||||||||||||
| 66 | 0 | my $l = $_->attr('xml:lang'); | |||||||||||||||||||
| 67 | 0 | ▶ | push @langs, $l if defined $l; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | 2 | @langs; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 2 | ▶ | sub language { | ||||||||||||||||||
|
Subroutine
language: called CC=5 SCAR=20.9
Pod
documented
| |||||||||||||||||||||
| 73 | 2 | my $self = shift; | |||||||||||||||||||
| 74 | 2 | my @langs = $self->languages; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 2 | ▶ | return undef unless @langs; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 2 | my %c; | |||||||||||||||||||
| 78 | 2 | ++$c{$_} for @langs; | |||||||||||||||||||
| 79 | # just one language | ||||||||||||||||||||
| 80 | 2 | ▶ | return $langs[0] if keys(%c) == 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | @langs = reverse sort { $c{$a} <=> $c{$b} } @langs; | |||||||||||||||||||
| 83 | 0 | ▶ | return $langs[0] if $c{$langs[0]} - $c{$langs[1]} >= 2; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | return undef; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =head1 NAME | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | WebService::Libris::Book - represents a Book in the libris.kb.se webservice | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 SYNOPSIS | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | use WebService::Libris; | ||||||||||||||||||||
| 94 | for my $b (WebService::Libris->search(term => 'Rothfuss')) { | ||||||||||||||||||||
| 95 | # $b is a WebService::Libris::Book object here | ||||||||||||||||||||
| 96 | say $b->title; | ||||||||||||||||||||
| 97 | say $b->isbn; | ||||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =head1 DESCRIPTION | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | C<WebService::Libris::Book> is a subclass of C<WebService::Libris> and | ||||||||||||||||||||
| 103 | inherits all its methods. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | All of the following methods return undef or the empty list if the information is not available. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =head1 METHODS | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =head2 title | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | returns the title of the book | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =head2 date | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | returns the publication date as a string (often just a year) | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | =head2 isbn | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | returns the first ISBN | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head2 isbn | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | returns a list of all ISBNs associated with the current book | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head2 publisher | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | returns the name of the publisher | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =head2 related_books | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | returns a list of related books | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | =head2 held_by | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | returns a list of libraries that hold this book | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | =head2 authors_obj | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | returns a list of L<WebService::Libris::Author> objects which are listed | ||||||||||||||||||||
| 140 | as I<creator> of this book. | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head2 authors_text | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | returns a list of creators of this book, as extracted from the response. | ||||||||||||||||||||
| 145 | This often contains duplicates, or slightly different versions of the | ||||||||||||||||||||
| 146 | same author name, so should be used with care. | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =head2 language_marc | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | Returns the language in the three-letter "MARC" code, or undef if no such | ||||||||||||||||||||
| 151 | code is found. | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =head2 language | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | Some of the book records include a "MARC" language code (same as the | ||||||||||||||||||||
| 156 | Library of Congress uses). This methods tries to extract this code, and returns | ||||||||||||||||||||
| 157 | the equivalent ISO 639 language code (two letters) if the translation is known. | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | It also exracts C<xml:lang> attribute from any tags found in the record. | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | Sometimes there are several different language specifications in a single | ||||||||||||||||||||
| 162 | record. In this case this method does an educated guess which one is correct. | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | =head2 languages | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | Return all language codes mentioned in the description of the C<language> method. No deduplication is done. | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | 1 | 1; | |||||||||||||||||||