| 1 | package WWW::Scraper::ISBN::ISBNdb_Driver; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 7 | our $VERSION = '0.10'; | |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | #-------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | ########################################################################### | ||||||||||||||||||||||||||||||||||
| 11 | # Inheritence | ||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 7 | ▶ | use base qw(WWW::Scraper::ISBN::Driver); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | ########################################################################### | ||||||||||||||||||||||||||||||||||
| 16 | # Modules | ||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | 7 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | ########################################################################### | ||||||||||||||||||||||||||||||||||
| 24 | # Variables | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 7 | our $ACCESS_KEY = undef; | |||||||||||||||||||||||||||||||||
| 27 | 7 | our $user_agent = new LWP::UserAgent(); | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 7 | my $API_VERSION = 'v1'; | |||||||||||||||||||||||||||||||||
| 30 | 7 | my $IN2MM = 0.0393700787; # number of inches in a millimetre (mm) | |||||||||||||||||||||||||||||||||
| 31 | 7 | my $LB2G = 0.00220462; # number of pounds (lbs) in a gram | |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | 7 | my %editions = ( | |||||||||||||||||||||||||||||||||
| 34 | '(pbk.)' => 'Paperback', | ||||||||||||||||||||||||||||||||||
| 35 | '(electronic bk.)' => 'eBook' | ||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | 7 | my %api_paths = ( | |||||||||||||||||||||||||||||||||
| 39 | 'v1' => { format => 'http://isbndb.com/api/%s.xml?access_key=%s&index1=%s&results=%s&value1=%s', fields => [ qw( search_type access_key search_field results_type search_param ) ] }, | ||||||||||||||||||||||||||||||||||
| 40 | 'v2' => { format => 'http://isbndb.com/api/v2/xml/%s/%s/%s', fields => [ qw( access_key search_type search_param ) ] } | ||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | #-------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | WWW::Scraper::ISBN::ISBNdb_Driver - Search driver for the isbndb.com online book catalog | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | use WWW::Scraper::ISBN; | ||||||||||||||||||||||||||||||||||
| 52 | my $scraper = new WWW::Scraper::ISBN(); | ||||||||||||||||||||||||||||||||||
| 53 | $scraper->drivers( qw/ ISBNdb / ); | ||||||||||||||||||||||||||||||||||
| 54 | $WWW::Scraper::ISBN::ISBNdb_Driver::ACCESS_KEY = 'xxxx'; # Your isbndb.com access key | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | my $isbn = '0596101058'; | ||||||||||||||||||||||||||||||||||
| 57 | my $result = $scraper->search( $isbn ); | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | if( $result->found ) { | ||||||||||||||||||||||||||||||||||
| 60 | my $book = $result->book; | ||||||||||||||||||||||||||||||||||
| 61 | print "ISBN: ", $book->{isbn}, "\n"; | ||||||||||||||||||||||||||||||||||
| 62 | print "Title: ", $book->{title}, "\n"; | ||||||||||||||||||||||||||||||||||
| 63 | print "Author: ", $book->{author}, "\n"; | ||||||||||||||||||||||||||||||||||
| 64 | print "Publisher: ", $book->{publisher}, "\n"; | ||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | This is a WWW::Scraper::ISBN driver that pulls data from | ||||||||||||||||||||||||||||||||||
| 70 | L<http://www.isbndb.com>. Consult L<WWW::Scraper::ISBN> for usage | ||||||||||||||||||||||||||||||||||
| 71 | details. | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | #-------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | ########################################################################### | ||||||||||||||||||||||||||||||||||
| 78 | # Public Interface | ||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | sub search { | ||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my( $self, $isbn ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
search: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->found(0); | |||||||||||||||||||||||||||||||||
| 83 | 0 | $self->book(undef); | |||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 0 | my %book; | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if($API_VERSION eq 'v1') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | 0 | my( $details, $details_url ) = $self->_fetch( 'books', 'isbn' => $isbn, 'details' ); | |||||||||||||||||||||||||||||||||
| 88 | 0 | my( $authors, $authors_url ) = $self->_fetch( 'books', 'isbn' => $isbn, 'authors' ); | |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return unless $details && $self->_contains_book_data($details); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$details and $self->_contains_book_data($details)
MC/DC0%0/2
$details and $self->_contains_book_data($details)
$details
$self->_contains_book_data($details)
Truth table0%0/3
A and B
A= $detailsB= $self->_contains_book_data($details)
| |||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 0 | %book = ( | |||||||||||||||||||||||||||||||||
| 93 | book_link => $details_url, | ||||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->_get_pubdata(\%book,$details); | |||||||||||||||||||||||||||||||||
| 97 | 0 | $self->_get_details(\%book,$details); | |||||||||||||||||||||||||||||||||
| 98 | 0 | $self->_get_authors(\%book,$authors); | |||||||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||||||||
| 100 | 0 | my( $details, $details_url ) = $self->_fetch( 'book', 'isbn' => $isbn, 'details' ); | |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return unless $details && $self->_contains_book_data($details); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$details and $self->_contains_book_data($details)
MC/DC0%0/2
$details and $self->_contains_book_data($details)
$details
$self->_contains_book_data($details)
Truth table0%0/3
A and B
A= $detailsB= $self->_contains_book_data($details)
| |||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||
| 104 | 0 | %book = ( | |||||||||||||||||||||||||||||||||
| 105 | book_link => $details_url, | ||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->_get_details_v2(\%book,$details); | |||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->_trim(\%book); | |||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->book(\%book); | |||||||||||||||||||||||||||||||||
| 114 | 0 | $self->found(1); | |||||||||||||||||||||||||||||||||
| 115 | 0 | return $self->book; | |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | ########################################################################### | ||||||||||||||||||||||||||||||||||
| 119 | # Private Interface | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | sub _contains_book_data { | ||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my( $self, $doc ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_contains_book_data: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return $doc->getElementsByTagName('BookData')->size > 0 if($API_VERSION eq 'v1'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 124 | 0 | return $doc->getElementsByTagName('data')->size > 0; | |||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | #<ISBNdb server_time="2013-08-31T08:52:38Z"> | ||||||||||||||||||||||||||||||||||
| 128 | #<BookList total_results="1" page_size="10" page_number="1" shown_results="1"> | ||||||||||||||||||||||||||||||||||
| 129 | #<BookData book_id="learning_perl_a03" isbn="0596101058" isbn13="9780596101053"> | ||||||||||||||||||||||||||||||||||
| 130 | #<Title>Learning Perl</Title> | ||||||||||||||||||||||||||||||||||
| 131 | #<TitleLong></TitleLong> | ||||||||||||||||||||||||||||||||||
| 132 | #<AuthorsText>Randal L. Schwartz, Tom Phoenix and brian d foy</AuthorsText> | ||||||||||||||||||||||||||||||||||
| 133 | #<PublisherText publisher_id="oreilly">Sebastopol, CA : O\'Reilly, c2005.</PublisherText> | ||||||||||||||||||||||||||||||||||
| 134 | #<Authors> | ||||||||||||||||||||||||||||||||||
| 135 | #<Person person_id="schwartz_randal_l">Schwartz, Randal L.</Person> | ||||||||||||||||||||||||||||||||||
| 136 | #<Person person_id="tom_phoenix">Tom Phoenix</Person> | ||||||||||||||||||||||||||||||||||
| 137 | #<Person person_id="brian_d_foy">brian d foy</Person> | ||||||||||||||||||||||||||||||||||
| 138 | #</Authors> | ||||||||||||||||||||||||||||||||||
| 139 | #</BookData> | ||||||||||||||||||||||||||||||||||
| 140 | #</BookList> | ||||||||||||||||||||||||||||||||||
| 141 | #</ISBNdb> | ||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | sub _get_authors { | ||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | my( $self, $book, $authors ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_authors: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 145 | 0 | my $people = $authors->findnodes('//Authors/Person'); | |||||||||||||||||||||||||||||||||
| 146 | 0 | my @people; | |||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | for( my $i = 0; $i < $people->size; $i++ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 148 | 0 | my $person = $people->get_node($i); | |||||||||||||||||||||||||||||||||
| 149 | 0 | push @people, $person->to_literal; | |||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | 0 | my $str = join '; ', @people; | |||||||||||||||||||||||||||||||||
| 153 | 0 | $str =~ s/^\s+//; | |||||||||||||||||||||||||||||||||
| 154 | 0 | $str =~ s/\s+$//; | |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 0 | $book->{author} = $str; | |||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | sub _get_pubdata { | ||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my( $self, $book, $doc ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_pubdata: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | 0 | my $pubtext = $doc->findnodes('//PublisherText')->to_literal; | |||||||||||||||||||||||||||||||||
| 163 | 0 | my $details = $doc->findnodes('//Details/@edition_info')->to_literal; | |||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | 0 | my $year = ''; | |||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if( $pubtext =~ /(\d{4})/ ) { $year = $1 } | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 167 | 0 | elsif( $details =~ /(\d{4})/ ) { $year = $1 } | |||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | $book->{pubdate} = $year || ''; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$year || ''
MC/DC0%0/1
$year || ''
$year
Truth table0%0/2
A
A= $year
| |||||||||||||||||||||||||||||||||||
| 170 | 0 | $book->{publisher} = ''; | |||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 0 | my $pub_id = ($doc->findnodes('//PublisherText/@publisher_id'))[0]->to_literal; | |||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if($pub_id) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 175 | 0 | my $publisher = $self->_fetch( 'publishers', 'publisher_id', $pub_id, 'details' ); | |||||||||||||||||||||||||||||||||
| 176 | 0 | my $data = ($publisher->findnodes('//PublisherData'))[0]; | |||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | 0 | $book->{publisher} = ($data->findnodes('//Name'))[0]->to_literal; | |||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | #<ISBNdb server_time="2013-08-31T08:52:38Z"> | ||||||||||||||||||||||||||||||||||
| 183 | #<BookList total_results="1" page_size="10" page_number="1" shown_results="1"> | ||||||||||||||||||||||||||||||||||
| 184 | #<BookData book_id="learning_perl_a03" isbn="0596101058" isbn13="9780596101053"> | ||||||||||||||||||||||||||||||||||
| 185 | #<Title>Learning Perl</Title> | ||||||||||||||||||||||||||||||||||
| 186 | #<TitleLong></TitleLong> | ||||||||||||||||||||||||||||||||||
| 187 | #<AuthorsText>Randal L. Schwartz, Tom Phoenix and brian d foy</AuthorsText> | ||||||||||||||||||||||||||||||||||
| 188 | #<PublisherText publisher_id="oreilly">Sebastopol, CA : O\'Reilly, c2005.</PublisherText> | ||||||||||||||||||||||||||||||||||
| 189 | #<Details change_time="2009-04-23T07:13:51Z" price_time="2013-01-01T19:03:44Z" edition_info="(pbk.)" language="eng" physical_description_text="283 p. : ill. ; 24 cm." lcc_number="" dewey_decimal_normalized="5.133" dewey_decimal="005.133" /> | ||||||||||||||||||||||||||||||||||
| 190 | #</BookData> | ||||||||||||||||||||||||||||||||||
| 191 | #</BookList> | ||||||||||||||||||||||||||||||||||
| 192 | #</ISBNdb> | ||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||
| 194 | sub _get_details { | ||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my( $self, $book, $doc ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_details: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||
| 197 | 0 | my $isbn10 = $doc->findnodes('//BookData/@isbn')->to_literal; | |||||||||||||||||||||||||||||||||
| 198 | 0 | my $isbn13 = $doc->findnodes('//BookData/@isbn13')->to_literal; | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | 0 | $book->{isbn} = $isbn13; | |||||||||||||||||||||||||||||||||
| 201 | 0 | $book->{ean13} = $isbn13; | |||||||||||||||||||||||||||||||||
| 202 | 0 | $book->{isbn13} = $isbn13; | |||||||||||||||||||||||||||||||||
| 203 | 0 | $book->{isbn10} = $isbn10; | |||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | 0 | my $long_title = eval { ($doc->findnodes('//TitleLong'))[0]->to_literal }; | |||||||||||||||||||||||||||||||||
| 206 | 0 | my $short_title = eval { ($doc->findnodes('//Title'))[0]->to_literal }; | |||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | $book->{title} = $long_title || $short_title; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$long_title || $short_title
MC/DC0%0/2
$long_title || $short_title
$long_title
$short_title
Truth table0%0/3
A || B
A= $long_titleB= $short_title
| |||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | 0 | my $edition = $doc->findnodes('//Details/@edition_info')->to_literal; | |||||||||||||||||||||||||||||||||
| 210 | 0 | my $desc = $doc->findnodes('//Details/@physical_description_text')->to_literal; | |||||||||||||||||||||||||||||||||
| 211 | 0 | my $dewey = $doc->findnodes('//Details/@dewey_decimal')->to_literal; | |||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | 0 | my ($binding,$date) = $edition =~ /([^;]+);(.*)/; | |||||||||||||||||||||||||||||||||
| 214 | 0 | my (@size) = $desc =~ /([\d\.]+)"x([\d\.]+)"x([\d\.]+)"/; | |||||||||||||||||||||||||||||||||
| 215 | 0 | my ($weight) = $desc =~ /([\d\.]+) lbs?/; | |||||||||||||||||||||||||||||||||
| 216 | 0 | my ($pages) = $desc =~ /(\d) pages/; | |||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | ($pages) = $desc =~ /(\d+) p\./ unless($pages); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 0 | my ($height,$width,$depth) = sort {$b <=> $a} @size; | |||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | $book->{height} = int($height / $IN2MM) if($height); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | $book->{width} = int($width / $IN2MM) if($width); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | $book->{depth} = int($depth / $IN2MM) if($depth); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | $book->{weight} = int($weight / $LB2G) if($weight); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | $book->{pubdate} = $date if($date); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | $book->{binding} = $editions{$edition} || $binding || $edition; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$editions{$edition} || $binding || $edition
$editions{$edition} or $binding
MC/DC0%0/3
$editions{$edition} || $binding || $edition
$editions{$edition}
$binding
$edition
Truth table0%0/4
A or B || C
A= $editions{$edition}B= $bindingC= $edition
| |||||||||||||||||||||||||||||||||||
| 227 | 0 | $book->{pages} = $pages; | |||||||||||||||||||||||||||||||||
| 228 | 0 | $book->{dewey} = "$dewey"; | |||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||
| 231 | # <isbndb> | ||||||||||||||||||||||||||||||||||
| 232 | # <data> | ||||||||||||||||||||||||||||||||||
| 233 | # <author_data> | ||||||||||||||||||||||||||||||||||
| 234 | # <id>schwartz_randal_l</id> | ||||||||||||||||||||||||||||||||||
| 235 | # <name>Schwartz, Randal L.</name> | ||||||||||||||||||||||||||||||||||
| 236 | # </author_data> | ||||||||||||||||||||||||||||||||||
| 237 | # <author_data> | ||||||||||||||||||||||||||||||||||
| 238 | # <id>tom_phoenix</id> | ||||||||||||||||||||||||||||||||||
| 239 | # <name>Tom Phoenix</name> | ||||||||||||||||||||||||||||||||||
| 240 | # </author_data> | ||||||||||||||||||||||||||||||||||
| 241 | # <author_data> | ||||||||||||||||||||||||||||||||||
| 242 | # <id>brian_d_foy</id> | ||||||||||||||||||||||||||||||||||
| 243 | # <name>brian d foy</name> | ||||||||||||||||||||||||||||||||||
| 244 | # </author_data> | ||||||||||||||||||||||||||||||||||
| 245 | # <awards_text></awards_text> | ||||||||||||||||||||||||||||||||||
| 246 | # <book_id>learning_perl_a04</book_id> | ||||||||||||||||||||||||||||||||||
| 247 | # <dewey_decimal>005</dewey_decimal> | ||||||||||||||||||||||||||||||||||
| 248 | # <dewey_normal>5</dewey_normal> | ||||||||||||||||||||||||||||||||||
| 249 | # <edition_info>Paperback; 2005-07-01</edition_info> | ||||||||||||||||||||||||||||||||||
| 250 | # <isbn10>1600330207</isbn10> | ||||||||||||||||||||||||||||||||||
| 251 | # <isbn13>9781600330209</isbn13> | ||||||||||||||||||||||||||||||||||
| 252 | # <language></language> | ||||||||||||||||||||||||||||||||||
| 253 | # <lcc_number></lcc_number> | ||||||||||||||||||||||||||||||||||
| 254 | # <marc_enc_level>~</marc_enc_level> | ||||||||||||||||||||||||||||||||||
| 255 | # <notes></notes> | ||||||||||||||||||||||||||||||||||
| 256 | # <physical_description_text>7.0"x9.2"x0.9"; 1.3 lb; 704 pages</physical_description_text> | ||||||||||||||||||||||||||||||||||
| 257 | # <publisher_id>oreilly_media</publisher_id> | ||||||||||||||||||||||||||||||||||
| 258 | # <publisher_name>O\'Reilly Media</publisher_name> | ||||||||||||||||||||||||||||||||||
| 259 | # <publisher_text>O\'Reilly Media</publisher_text> | ||||||||||||||||||||||||||||||||||
| 260 | # <subject_ids>computers_internet_programming_introductory_beginning_genera</subject_ids> | ||||||||||||||||||||||||||||||||||
| 261 | # <subject_ids>computers_internet_programming_languages_tools_general</subject_ids> | ||||||||||||||||||||||||||||||||||
| 262 | # <subject_ids>computers_internet_programming_general</subject_ids> | ||||||||||||||||||||||||||||||||||
| 263 | # <subject_ids>computers_internet_web_development_programming_general</subject_ids> | ||||||||||||||||||||||||||||||||||
| 264 | # <summary>"Learning Perl, better known as "the Llama book," starts the programmer on the way to mastery. Written by three prominent members of the Perl community who each have several years of experience teaching Perl around the world, this edition has been updated to account for all the recent changes to the language up to Perl 5.8. Perl is the language for people who want to get work done. It started as a tool for Unix system administrators who needed something powerful for small tasks. Since then, Perl has blossomed into a full-featured programming language used for web programming, database manipulation, XML processing, and system administration--on practically all platforms--while remaining the favorite tool for the small daily tasks it was designed for. You might start using Perl because you need it, but you\'ll continue to use it because you love it. Informed by their years of success at teaching Perl as consultants, the authors have re-engineered the Llama to better match the pace and scope appropriate for readers getting started with Perl, while retaining the detailed discussion, thorough examples, and eclectic wit for which the Llama is famous. The book includes new exercises and solutions so you can practice what you\'ve learned while it\'s still fresh in your mind. Here are just some of the topics covered: Perl variable types subroutines file operations regular expressions text processing strings and sorting process management using third party modules If you ask Perl programmers today what book they relied on most when they were learning Perl, you\'ll find that an overwhelming majority will point to the Llama. With good reason. Other books mayteach you to program in Perl, but this book will turn you into a Perl programmer.</summary> | ||||||||||||||||||||||||||||||||||
| 265 | # <title>Learning Perl</title> | ||||||||||||||||||||||||||||||||||
| 266 | # <title_latin>Learning Perl</title_latin> | ||||||||||||||||||||||||||||||||||
| 267 | # <title_long>Learning Perl (4th Edition)</title_long> | ||||||||||||||||||||||||||||||||||
| 268 | # <urls_text></urls_text> | ||||||||||||||||||||||||||||||||||
| 269 | # </data> | ||||||||||||||||||||||||||||||||||
| 270 | # <index_searched>isbn</index_searched> | ||||||||||||||||||||||||||||||||||
| 271 | # </isbndb> | ||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||
| 273 | sub _get_details_v2 { | ||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | my( $self, $book, $doc ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_details_v2: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||
| 276 | 0 | my $people = $doc->findnodes('//data/author_data/name'); | |||||||||||||||||||||||||||||||||
| 277 | 0 | my @people; | |||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | for( my $i = 0; $i < $people->size; $i++ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 279 | 0 | my $person = $people->get_node($i); | |||||||||||||||||||||||||||||||||
| 280 | 0 | push @people, $person->to_literal; | |||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||
| 283 | 0 | my $str = join '; ', @people; | |||||||||||||||||||||||||||||||||
| 284 | 0 | $str =~ s/^\s+//; | |||||||||||||||||||||||||||||||||
| 285 | 0 | $str =~ s/\s+$//; | |||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||
| 287 | 0 | $book->{author} = $str; | |||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||
| 289 | 0 | $book->{publisher} = ($doc->findnodes('//data/publisher_name'))[0]->to_literal; | |||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||
| 291 | 0 | my $isbn10 = $doc->findnodes('//data/isbn10')->to_literal; | |||||||||||||||||||||||||||||||||
| 292 | 0 | my $isbn13 = $doc->findnodes('//data/isbn13')->to_literal; | |||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||
| 294 | 0 | $book->{isbn} = $isbn13; | |||||||||||||||||||||||||||||||||
| 295 | 0 | $book->{ean13} = $isbn13; | |||||||||||||||||||||||||||||||||
| 296 | 0 | $book->{isbn13} = $isbn13; | |||||||||||||||||||||||||||||||||
| 297 | 0 | $book->{isbn10} = $isbn10; | |||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | 0 | my $long_title = eval { ($doc->findnodes('//data/title_long'))[0]->to_literal }; | |||||||||||||||||||||||||||||||||
| 300 | 0 | my $short_title = eval { ($doc->findnodes('//data/title'))[0]->to_literal }; | |||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | $book->{title} = $long_title || $short_title; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$long_title || $short_title
MC/DC0%0/2
$long_title || $short_title
$long_title
$short_title
Truth table0%0/3
A || B
A= $long_titleB= $short_title
| |||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||
| 303 | 0 | my $pubtext = $doc->findnodes('//data/publisher_text')->to_literal; | |||||||||||||||||||||||||||||||||
| 304 | 0 | my $edition = $doc->findnodes('//data/edition_info')->to_literal; | |||||||||||||||||||||||||||||||||
| 305 | 0 | my $desc = $doc->findnodes('//data/physical_description_text')->to_literal; | |||||||||||||||||||||||||||||||||
| 306 | 0 | my $dewey = $doc->findnodes('//data/dewey_decimal')->to_literal; | |||||||||||||||||||||||||||||||||
| 307 | 0 | my $summary = $doc->findnodes('//data/summary')->to_literal; | |||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||
| 309 | 0 | my ($binding,$date) = $edition =~ /([^;]+);(.*)/; | |||||||||||||||||||||||||||||||||
| 310 | 0 | my (@size) = $desc =~ /([\d\.]+)"x([\d\.]+)"x([\d\.]+)"/; | |||||||||||||||||||||||||||||||||
| 311 | 0 | my ($weight) = $desc =~ /([\d\.]+) lbs?/; | |||||||||||||||||||||||||||||||||
| 312 | 0 | my ($pages) = $desc =~ /(\d+) pages/; | |||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | ($pages) = $desc =~ /(\d+) p\./ unless($pages); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if( !$date && $pubtext =~ /(\d{4})/ ) { $date = $1 } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $date and $pubtext =~ /(\d{4})/
MC/DC0%0/2
not $date and $pubtext =~ /(\d{4})/
not $date
$pubtext =~ /(\d{4})/
Truth table0%0/3
not(A) and B
A= not $dateB= $pubtext =~ /(\d{4})/
| |||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if( !$date && $edition =~ /(\d{4})/ ) { $date = $1 } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $date and $edition =~ /(\d{4})/
MC/DC0%0/2
not $date and $edition =~ /(\d{4})/
not $date
$edition =~ /(\d{4})/
Truth table0%0/3
not(A) and B
A= not $dateB= $edition =~ /(\d{4})/
| |||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||
| 318 | 0 | my ($height,$width,$depth) = sort {$b <=> $a} @size; | |||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | $book->{height} = int($height / $IN2MM) if($height); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | $book->{width} = int($width / $IN2MM) if($width); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $book->{depth} = int($depth / $IN2MM) if($depth); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | $book->{weight} = int($weight / $LB2G) if($weight); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | $book->{pubdate} = $date if($date); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | $book->{binding} = $editions{$edition} || $binding || $edition; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$editions{$edition} || $binding || $edition
$editions{$edition} or $binding
MC/DC0%0/3
$editions{$edition} || $binding || $edition
$editions{$edition}
$binding
$edition
Truth table0%0/4
A or B || C
A= $editions{$edition}B= $bindingC= $edition
| |||||||||||||||||||||||||||||||||||
| 326 | 0 | $book->{pages} = $pages; | |||||||||||||||||||||||||||||||||
| 327 | 0 | $book->{dewey} = "$dewey"; | |||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||
| 329 | 0 | $book->{description} = $summary; | |||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||
| 332 | #-------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | sub _trim { | ||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | my( $self, $book ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_trim: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||
| 337 | 0 | for my $key (keys %$book) { | |||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | next unless($book->{$key}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 339 | 0 | $book->{$key} =~ s/^\s+//s; # remove leading spaces | |||||||||||||||||||||||||||||||||
| 340 | 0 | $book->{$key} =~ s/\s+$//s; # remove trailing spaces | |||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | sub _fetch { | ||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | my( $self, @args ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_fetch: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 346 | 0 | my $parser = new XML::LibXML(); | |||||||||||||||||||||||||||||||||
| 347 | 0 | my $url = $self->_url( @args ); | |||||||||||||||||||||||||||||||||
| 348 | 0 | my $xml = $self->_fetch_data($url); | |||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | return unless($xml && $xml !~ /^<!DOCTYPE html>/); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$xml and not $xml =~ /^<!DOCTYPE html>/
MC/DC0%0/2
$xml and not $xml =~ /^<!DOCTYPE html>/
$xml
not $xml =~ /^<!DOCTYPE html>/
Truth table0%0/3
A and not(B)
A= $xmlB= not $xml =~ /^<!DOCTYPE html>/
| |||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||
| 351 | 0 | my $doc = $parser->parse_string( $xml ); | |||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | return wantarray ? ( $doc, $url ) : $doc; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||
| 355 | sub _fetch_data { | ||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | my( $self, $url ) = @_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_fetch_data: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 357 | 0 | my $res = $user_agent->get($url); | |||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | return unless $res->is_success; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 359 | # use Data::Dumper; | ||||||||||||||||||||||||||||||||||
| 360 | # print STDERR "# data=" . Dumper($res); | ||||||||||||||||||||||||||||||||||
| 361 | 0 | return $res->content; | |||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||
| 364 | sub _url { | ||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
_url: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||
| 367 | 0 | my $access_key = $self->_get_key(); | |||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | croak "no access key provided" unless $access_key; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||
| 370 | 0 | my %hash = ( access_key => $access_key ); | |||||||||||||||||||||||||||||||||
| 371 | 0 | ($hash{search_type}, $hash{search_field}, $hash{search_param}, $hash{results_type}) = @_; | |||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||
| 373 | 0 | my @values = map { $hash{$_} } @{ $api_paths{$API_VERSION}{fields} }; | |||||||||||||||||||||||||||||||||
| 374 | 0 | my $url = sprintf $api_paths{$API_VERSION}{format}, @values; | |||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||
| 376 | # print STDERR "# url=$url\n"; | ||||||||||||||||||||||||||||||||||
| 377 | 0 | return $url; | |||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||
| 380 | sub _get_key { | ||||||||||||||||||||||||||||||||||
| 381 | 2 | ▶ | return $ACCESS_KEY if($ACCESS_KEY); | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_key: called CC=7 SCAR=30.7
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||
| 383 | 2 | ▶ | if($ENV{ISBNDB_ACCESS_KEY}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 384 | 0 | $ACCESS_KEY = $ENV{ISBNDB_ACCESS_KEY}; | |||||||||||||||||||||||||||||||||
| 385 | 0 | return $ACCESS_KEY; | |||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||
| 388 | 2 | for my $dir ( ".", $ENV{HOME}, '~' ) { | |||||||||||||||||||||||||||||||||
| 389 | 6 | my $file = join( '/', $dir, ".isbndb" ); | |||||||||||||||||||||||||||||||||
| 390 | 6 | ▶ | next unless -e $file; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | my $fh = IO::File->new($file,'r') or next; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 393 | 0 | my $key; | |||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | $key .= $_ while(<$fh>); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 395 | 0 | $key =~ s/\s+//gs; | |||||||||||||||||||||||||||||||||
| 396 | 0 | $fh->close; | |||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||
| 398 | 0 | $ACCESS_KEY = $key; | |||||||||||||||||||||||||||||||||
| 399 | 0 | return $ACCESS_KEY; | |||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | sub _api_version { | ||||||||||||||||||||||||||||||||||
| 404 | 1 | ▶ | my $version = shift; | ||||||||||||||||||||||||||||||||
|
Subroutine
_api_version: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||
| 405 | 1 | ▶ | $API_VERSION = $version if($version && $api_paths{$version}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$version and $api_paths{$version}
MC/DC0%0/2
$version and $api_paths{$version}
$version
$api_paths{$version}
Truth table33%1/3
A and B
A= $versionB= $api_paths{$version}
| |||||||||||||||||||||||||||||||||||
| 406 | 1 | return $API_VERSION; | |||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||
| 409 | 7 | 1; | |||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | __END__ | ||||||||||||||||||||||||||||||||||