File Coverage

blib/lib/WWW/Scraper/ISBN/TWEslitebooks_Driver.pm
Criterion Covered Total %
statement 31 48 64.5
branch 0 2 0.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 41 60 68.3


line stmt bran cond sub pod time code
1             # ex:ts=8
2              
3             package WWW::Scraper::ISBN::TWEslitebooks_Driver;
4              
5 1     1   1058 use strict;
  1         2  
  1         42  
6 1     1   5 use warnings;
  1         1  
  1         37  
7              
8 1     1   6 use vars qw($VERSION @ISA);
  1         11  
  1         78  
9             $VERSION = '0.02';
10              
11             #--------------------------------------------------------------------------
12              
13             =head1 NAME
14              
15             WWW::Scraper::ISBN::TWEslitebooks_Driver - Search driver for TWEslitebooks' online catalog.
16              
17             =head1 SYNOPSIS
18              
19             See parent class documentation (L)
20              
21             =head1 DESCRIPTION
22              
23             Searches for book information from the TWEslitebooks' online catalog.
24              
25             =cut
26              
27             #--------------------------------------------------------------------------
28              
29             ###########################################################################
30             #Library Modules #
31             ###########################################################################
32              
33 1     1   5 use WWW::Scraper::ISBN::Driver;
  1         2  
  1         23  
34 1     1   1678 use WWW::Mechanize;
  1         205932  
  1         46  
35 1     1   1281 use Template::Extract;
  1         738  
  1         28  
36 1     1   861 use Text::Iconv;
  1         3306  
  1         179  
37              
38             ###########################################################################
39             #Constants #
40             ###########################################################################
41              
42 1     1   10 use constant ESLITEBOOKS => 'http://www.eslitebooks.com';
  1         3  
  1         506  
43              
44             #--------------------------------------------------------------------------
45              
46             ###########################################################################
47             #Inheritence #
48             ###########################################################################
49              
50             @ISA = qw(WWW::Scraper::ISBN::Driver);
51              
52             ###########################################################################
53             #Interface Functions #
54             ###########################################################################
55              
56             =head1 METHODS
57              
58             =over 4
59              
60             =item C
61              
62             Creates a query string, then passes the appropriate form fields to the Eslitebooks
63             server.
64              
65             The returned page should be the correct catalog page for that ISBN. If not the
66             function returns zero and allows the next driver in the chain to have a go. If
67             a valid page is returned, the following fields are returned via the book hash:
68              
69             isbn
70             ean
71             title
72             author
73             pages
74             book_link
75             image_link
76             pubdate
77             publisher
78             price_list
79             price_sell
80              
81             The book_link and image_link refer back to the Eslitebooks website.
82              
83             =back
84              
85             =cut
86              
87             sub search {
88 1     1 1 1422 my $self = shift;
89 1         3 my $isbn = shift;
90 1         10 $self->found(0);
91 1         28 $self->book(undef);
92              
93 1         17 my $mechanize = WWW::Mechanize->new();
94 1         18592 $mechanize->get(ESLITEBOOKS);
95              
96 1         2777473 $mechanize->submit_form(
97             form_name => 'frmbas',
98             fields => {
99             query => $isbn,
100             },
101             );
102              
103 0           my $book_link = $mechanize->uri;
104              
105 0           my $conv = Text::Iconv->new("utf-8", "big5");
106 0           my $content = $mechanize->content();
107 0           $content =~ /( 108 0           $content = $conv->convert($1);
109              
110 0           my $template = <
111             112            
113