File Coverage

blib/lib/WWW/Scraper/ISBN/ISBNnu_Driver.pm
Criterion Covered Total %
statement 12 61 19.6
branch 0 12 0.0
condition 0 12 0.0
subroutine 4 6 66.6
pod 2 2 100.0
total 18 93 19.3


line stmt bran cond sub pod time code
1             package WWW::Scraper::ISBN::ISBNnu_Driver;
2              
3 5     5   296255 use strict;
  5         37  
  5         150  
4 5     5   38 use warnings;
  5         11  
  5         306  
5              
6             our $VERSION = '0.25';
7              
8             #--------------------------------------------------------------------------
9              
10             ###########################################################################
11             # Inheritence
12              
13 5     5   31 use base qw(WWW::Scraper::ISBN::Driver);
  5         12  
  5         2691  
14              
15             ###########################################################################
16             # Modules
17              
18 5     5   9077 use WWW::Mechanize;
  5         775323  
  5         4377  
19              
20             ###########################################################################
21             # Variables
22              
23             my $IN2MM = 0.0393700787; # number of inches in a millimetre (mm)
24             my $LB2G = 0.00220462; # number of pounds (lbs) in a gram
25             my $OZ2G = 0.035274; # number of ounces (oz) in a gram
26              
27             #--------------------------------------------------------------------------
28              
29             ###########################################################################
30             # Public Interface
31              
32             sub trim {
33 0     0 1   my ($self,$value) = @_;
34              
35 0 0         return '' unless(defined $value);
36              
37 0           $value =~ s/^\s+//; # trim leading whitespace
38 0           $value =~ s/\s+$//; # trim trailing whitespace
39 0           $value =~ s/\n//g; # trim newlines?
40 0           $value =~ s/ +/ /g; # trim extra middle space
41 0           $value =~ s/<[^>]+>//g; # remove tags
42              
43 0           return $value;
44             }
45            
46             sub search {
47 0     0 1   my ($self,$isbn) = @_;
48 0           my %data;
49            
50 0           $self->found(0);
51 0           $self->book(undef);
52              
53 0           my $post_url = "https://isbn.nu/".$isbn;
54 0           my $mech = WWW::Mechanize->new();
55 0           $mech->agent_alias( 'Linux Mozilla' );
56 0           $mech->add_header( 'Accept-Encoding' => undef );
57              
58 0           eval { $mech->get( $post_url ) };
  0            
59 0 0 0       return $self->handler("isbn.nu website appears to be unavailable.")
      0        
60             if($@ || !$mech->success() || !$mech->content());
61              
62 0           my $html = $mech->content();
63 0           my ($title) = $html =~ /([^<]+)<\/title>/; </td> </tr> <tr> <td class="h" > <a name="64">64</a> </td> <td class="c0" > <a href="#67"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $data{title} = $self->trim($title); </td> </tr> <tr> <td class="h" > <a name="65">65</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="66">66</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> return $self->handler("Failed to find that book on the isbn.nu website.") </td> </tr> <tr> <td class="h" > <a name="67">67</a> </td> <td class="c0" > <a href="#69"> 0 </a> </td> <td class="c0" > <a href="blib-lib-WWW-Scraper-ISBN-ISBNnu_Driver-pm--branch.html#67-1"> 0 </a> </td> <td class="c0" > <a href="blib-lib-WWW-Scraper-ISBN-ISBNnu_Driver-pm--condition.html#67-1"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> if (!$data{title} || $data{title} eq "No Title Found"); </td> </tr> <tr> <td class="h" > <a name="68">68</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="69">69</a> </td> <td class="c0" > <a href="#70"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{publisher}) = $html =~ m!<span class="bi_col_title">Publisher</span>\s*<span class="bi_col_value">([^<]+)</span>\s*</div>!si; </td> </tr> <tr> <td class="h" > <a name="70">70</a> </td> <td class="c0" > <a href="#71"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{pubdate}) = $html =~ m!<span class="bi_col_title">Publication date</span>\s*<span class="bi_col_value">([^<]+)</span>\s*</div>!si; </td> </tr> <tr> <td class="h" > <a name="71">71</a> </td> <td class="c0" > <a href="#72"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{pages}) = $html =~ m!<span class="bi_col_title">Pages</span>\s*<span class="bi_col_value">([0-9]+)</span>\s*</div>!si; </td> </tr> <tr> <td class="h" > <a name="72">72</a> </td> <td class="c0" > <a href="#73"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{edition}) = $html =~ m!<span class="bi_col_title">Edition</span>\s*<span class="bi_col_value">([^<]+)</span>\s*</div>!si; </td> </tr> <tr> <td class="h" > <a name="73">73</a> </td> <td class="c0" > <a href="#74"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{volume}) = $html =~ m!<span class="bi_col_title">Volume</span>\s*<span class="bi_col_value">([^<]+)</span>\s*</div>!si; </td> </tr> <tr> <td class="h" > <a name="74">74</a> </td> <td class="c0" > <a href="#75"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{binding}) = $html =~ m!<span class="bi_col_title">Binding</span>\s*<span class="bi_col_value">([^<]+)</span>\s*</div>!si; </td> </tr> <tr> <td class="h" > <a name="75">75</a> </td> <td class="c0" > <a href="#76"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{isbn13}) = $html =~ m!<span class="bi_col_title">ISBN-13</span>\s*<span class="bi_col_value">([0-9]+)</span>\s*</div>!si; </td> </tr> <tr> <td class="h" > <a name="76">76</a> </td> <td class="c0" > <a href="#77"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{isbn10}) = $html =~ m!<span class="bi_col_title">ISBN-10</span>\s*<span class="bi_col_value">([0-9X]+)</span>\s*</div>!si; </td> </tr> <tr> <td class="h" > <a name="77">77</a> </td> <td class="c0" > <a href="#78"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{weight}) = $html =~ m!<span class="bi_col_title">Weight</span>\s*<span class="bi_col_value">([0-9\.]+) lbs.</span>\s*</div>!si; </td> </tr> <tr> <td class="h" > <a name="78">78</a> </td> <td class="c0" > <a href="#79"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{author}) = $html =~ m!<div class="d_descriptive">By\s*(.*?)\s*</div>!; </td> </tr> <tr> <td class="h" > <a name="79">79</a> </td> <td class="c0" > <a href="#80"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{description})= $html =~ m!<div class="bi_annotation_text"><div class="bi_anno_text_head">Summary</div>([^<]+)<!; </td> </tr> <tr> <td class="h" > <a name="80">80</a> </td> <td class="c0" > <a href="#82"> 0 </a> </td> <td class="c0" > <a href="blib-lib-WWW-Scraper-ISBN-ISBNnu_Driver-pm--branch.html#80-1"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{description})= $html =~ m!<div class="bi_wide bi_annotation_text"><a name="amazondesc"></a><b>Amazon.com description:</b> <b>Product Description</b>:([^<]+)<! unless($data{description}); </td> </tr> <tr> <td class="h" > <a name="81">81</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="82">82</a> </td> <td class="c0" > <a href="#84"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $data{$_} = $self->trim($data{$_}) for(qw(publisher pubdate binding author description)); </td> </tr> <tr> <td class="h" > <a name="83">83</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="84">84</a> </td> <td class="c0" > <a href="#85"> 0 </a> </td> <td class="c0" > <a href="blib-lib-WWW-Scraper-ISBN-ISBNnu_Driver-pm--branch.html#84-1"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> if($data{weight}) { </td> </tr> <tr> <td class="h" > <a name="85">85</a> </td> <td class="c0" > <a href="#88"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $data{weight} = int($data{weight} / $LB2G); </td> </tr> <tr> <td class="h" > <a name="86">86</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> } </td> </tr> <tr> <td class="h" > <a name="87">87</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="88">88</a> </td> <td class="c0" > <a href="#89"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> my @size = $html =~ m!<span class="bi_col_title">Dimensions</span>\s*<span class="bi_col_value">([0-9\.]+) by ([0-9\.]+) by ([0-9\.]+) in.</span>\s*</div>!; </td> </tr> <tr> <td class="h" > <a name="89">89</a> </td> <td class="c0" > <a href="#90"> 0 </a> </td> <td class="c0" > <a href="blib-lib-WWW-Scraper-ISBN-ISBNnu_Driver-pm--branch.html#89-1"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> if(@size) { </td> </tr> <tr> <td class="h" > <a name="90">90</a> </td> <td class="c0" > <a href="#91"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> ($data{depth},$data{width},$data{height}) = sort @size; </td> </tr> <tr> <td class="h" > <a name="91">91</a> </td> <td class="c0" > <a href="#96"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $data{$_} = int($data{$_} / $IN2MM) for(qw( height width depth )); </td> </tr> <tr> <td class="h" > <a name="92">92</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> } </td> </tr> <tr> <td class="h" > <a name="93">93</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="94">94</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> #print STDERR "#html=".Dumper(\%data)."\n"; </td> </tr> <tr> <td class="h" > <a name="95">95</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="96">96</a> </td> <td class="c0" > <a href="#98"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $data{book_link} = $mech->uri(); </td> </tr> <tr> <td class="h" > <a name="97">97</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="98">98</a> </td> <td class="c0" > <a href="#99"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $data{ean13} = $data{isbn13}; </td> </tr> <tr> <td class="h" > <a name="99">99</a> </td> <td class="c0" > <a href="#100"> 0 </a> </td> <td >   </td> <td class="c0" > <a href="blib-lib-WWW-Scraper-ISBN-ISBNnu_Driver-pm--condition.html#99-1"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $data{isbn} = $data{isbn13} || $isbn; </td> </tr> <tr> <td class="h" > <a name="100">100</a> </td> <td class="c0" > <a href="#102"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $data{html} = $html; </td> </tr> <tr> <td class="h" > <a name="101">101</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="102">102</a> </td> <td class="c0" > <a href="#104"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $self->book(\%data); </td> </tr> <tr> <td class="h" > <a name="103">103</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="104">104</a> </td> <td class="c0" > <a href="#105"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> $self->found(1); </td> </tr> <tr> <td class="h" > <a name="105">105</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> return $self->book; </td> </tr> <tr> <td class="h" > <a name="106">106</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> } </td> </tr> <tr> <td class="h" > <a name="107">107</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="108">108</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 1; </td> </tr> <tr> <td class="h" > <a name="109">109</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="110">110</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> __END__ </td> </tr> </table> </body> </html>