line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Scraper::ISBN; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
357395
|
use strict; |
|
6
|
|
|
|
|
50
|
|
|
6
|
|
|
|
|
178
|
|
4
|
6
|
|
|
6
|
|
29
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
277
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.05'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
9
|
|
|
|
|
|
|
# Library Modules |
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
33
|
use Carp; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
389
|
|
12
|
6
|
|
|
6
|
|
2744
|
use WWW::Scraper::ISBN::Record; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
185
|
|
13
|
6
|
|
|
6
|
|
2657
|
use WWW::Scraper::ISBN::Driver; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
209
|
|
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
6
|
|
2832
|
use Module::Pluggable search_path => ['WWW::Scraper::ISBN']; |
|
6
|
|
|
|
|
65236
|
|
|
6
|
|
|
|
|
42
|
|
16
|
|
|
|
|
|
|
|
17
|
6
|
|
|
6
|
|
984
|
eval "use Business::ISBN"; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
18
|
|
|
|
|
|
|
my $business_isbn_loaded = ! $@; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
# Public API |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Preloaded methods go here. |
24
|
|
|
|
|
|
|
sub new { |
25
|
2
|
|
|
2
|
1
|
691
|
my $proto = shift; |
26
|
2
|
|
66
|
|
|
11
|
my $class = ref($proto) || $proto; |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
7
|
my $self = { |
29
|
|
|
|
|
|
|
DRIVERS => [] |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
5
|
bless ($self, $class); |
33
|
2
|
|
|
|
|
5
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub available_drivers { |
37
|
1
|
|
|
1
|
1
|
328
|
my $self = shift; |
38
|
1
|
|
|
|
|
5
|
my @plugins = $self->plugins(); |
39
|
1
|
|
|
|
|
1929
|
my @drivers; |
40
|
1
|
|
|
|
|
3
|
for my $plugin (@plugins) { |
41
|
3
|
100
|
|
|
|
12
|
next unless($plugin =~ /_Driver$/); |
42
|
1
|
|
|
|
|
7
|
$plugin =~ s/WWW::Scraper::ISBN::(\w+)_Driver/$1/; |
43
|
1
|
|
|
|
|
3
|
push @drivers, $plugin; |
44
|
|
|
|
|
|
|
} |
45
|
1
|
|
|
|
|
5
|
return @drivers; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub drivers { |
49
|
6
|
|
|
6
|
1
|
1917
|
my $self = shift; |
50
|
6
|
|
|
|
|
16
|
while ($_ = shift) { push @{$self->{DRIVERS}}, $_; } |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
51
|
6
|
|
|
|
|
11
|
for my $driver ( @{ $self->{DRIVERS} }) { |
|
6
|
|
|
|
|
14
|
|
52
|
5
|
|
|
|
|
34
|
require "WWW/Scraper/ISBN/".$driver."_Driver.pm"; |
53
|
|
|
|
|
|
|
} |
54
|
6
|
|
|
|
|
11
|
return @{ $self->{DRIVERS} }; |
|
6
|
|
|
|
|
182
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub reset_drivers { |
58
|
1
|
|
|
1
|
1
|
1011
|
my $self = shift; |
59
|
1
|
|
|
|
|
3
|
$self->{DRIVERS} = []; |
60
|
1
|
|
|
|
|
3
|
return @{ $self->{DRIVERS} }; |
|
1
|
|
|
|
|
4
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub search { |
64
|
6
|
|
|
6
|
1
|
3687
|
my ($self,$isbn) = @_; |
65
|
|
|
|
|
|
|
|
66
|
6
|
100
|
|
|
|
101
|
croak("Invalid ISBN specified [].\n") unless($isbn); |
67
|
|
|
|
|
|
|
|
68
|
5
|
50
|
|
|
|
14
|
if($business_isbn_loaded) { |
69
|
|
|
|
|
|
|
# Business::ISBN has strong validation algorithms |
70
|
0
|
|
|
|
|
0
|
my $isbn_object = Business::ISBN->new($isbn); |
71
|
0
|
0
|
0
|
|
|
0
|
croak("Invalid ISBN specified [$isbn].\n") unless($isbn_object && $isbn_object->is_valid); |
72
|
|
|
|
|
|
|
} else { |
73
|
|
|
|
|
|
|
# our fallback just validates it looks like an ISBN |
74
|
5
|
|
|
|
|
20
|
my $isbn_object = WWW::Scraper::ISBN::Driver->new(); |
75
|
5
|
100
|
66
|
|
|
22
|
croak("Invalid ISBN specified [$isbn].\n") unless($isbn_object && $isbn_object->is_valid($isbn)); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
4
|
100
|
|
|
|
11
|
croak("No search drivers specified.\n") |
79
|
|
|
|
|
|
|
if( $self->drivers == 0 ); |
80
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
11
|
my $record = WWW::Scraper::ISBN::Record->new(); |
82
|
3
|
|
|
|
|
9
|
$record->isbn($isbn); |
83
|
3
|
|
|
|
|
6
|
for my $driver_name (@{ $self->{DRIVERS} }) { |
|
3
|
|
|
|
|
8
|
|
84
|
3
|
|
|
|
|
15
|
my $driver = "WWW::Scraper::ISBN::${driver_name}_Driver"->new(); |
85
|
3
|
|
|
|
|
7
|
$driver->search($record->isbn); |
86
|
3
|
100
|
|
|
|
14
|
if ($driver->found) { |
87
|
1
|
|
|
|
|
3
|
$record->found("1"); |
88
|
1
|
|
|
|
|
4
|
$record->found_in("$driver_name"); |
89
|
1
|
|
|
|
|
3
|
$record->book($driver->book); |
90
|
1
|
|
|
|
|
6
|
last; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
2
|
100
|
|
|
|
9
|
$record->error($record->error.$driver->error) |
94
|
|
|
|
|
|
|
if ($driver->error); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
12
|
return $record; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |