ISBN.pm

filter: Statementstmt 94.4% 68 / 72 Branchbran 83.3% 15 / 18 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 12 / 12 Podpod 100% 5 / 5 totaltotal 86.0% 105 / 122 CC 16 SCAR 18.1
CC
16
Cov
88%
search
12.3
available_drivers
3.0
drivers
3.0
CRAP 6.1
↑ Summary ISBN/Driver.pm »
1 package WWW::Scraper::ISBN;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 our $VERSION = '1.05';
7  
8 #----------------------------------------------------------------------------
9 # Library Modules
10  
11 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use WWW::Scraper::ISBN::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use WWW::Scraper::ISBN::Driver;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 ▶use Module::Pluggable search_path => ['WWW::Scraper::ISBN'];
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 0 ▶eval "use Business::ISBN";
Subroutine BEGIN: called CC=1 SCAR=1.2
18 6 my $business_isbn_loaded = ! $@;
19  
20 #----------------------------------------------------------------------------
21 # Public API
22  
23 # Preloaded methods go here.
24 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
25 2 my $proto = shift;
26 2 ▶ my $class = ref($proto) || $proto;
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
110
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
27  
28 2 my $self = {
29 DRIVERS => []
30 };
31  
32 2 bless ($self, $class);
33 2 return $self;
34 }
35  
36 1 ▶sub available_drivers {
Subroutine available_drivers: called CC=3 SCAR=11.0
Pod documented
37 1 my $self = shift;
38 1 my @plugins = $self->plugins();
39 1 my @drivers;
40 1 for my $plugin (@plugins) {
41 3 ▶ next unless($plugin =~ /_Driver$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $plugin =~ /_Driver$/ 2 1 3
42 1 $plugin =~ s/WWW::Scraper::ISBN::(\w+)_Driver/$1/;
43 1 push @drivers, $plugin;
44 }
45 1 return @drivers;
46 }
47  
48 6 ▶sub drivers {
Subroutine drivers: called CC=3 SCAR=11.0
Pod documented
49 6 my $self = shift;
50 6 ▶ while ($_ = shift) { push @{$self->{DRIVERS}}, $_; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_ = shift()) 2 6 8
51 6 for my $driver ( @{ $self->{DRIVERS} }) {
52 5 require "WWW/Scraper/ISBN/".$driver."_Driver.pm";
53 }
54 6 return @{ $self->{DRIVERS} };
55 }
56  
57 1 ▶sub reset_drivers {
Subroutine reset_drivers: called CC=1 SCAR=0.0
Pod documented
58 1 my $self = shift;
59 1 $self->{DRIVERS} = [];
60 1 return @{ $self->{DRIVERS} };
61 }
62  
63 6 ▶sub search {
Subroutine search: called CC=11 SCAR=25.1
Pod documented
64 6 my ($self,$isbn) = @_;
65  
66 6 ▶ croak("Invalid ISBN specified [].\n") unless($isbn);
Branch: 1 branch
BranchTrueFalseTotal
unless $isbn 1 5 6
67  
68 5 ▶ if($business_isbn_loaded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($business_isbn_loaded) { } 0 5 5
69 # Business::ISBN has strong validation algorithms
70 0 my $isbn_object = Business::ISBN->new($isbn);
71 0 ▶ croak("Invalid ISBN specified [$isbn].\n") unless($isbn_object && $isbn_object->is_valid);
Branch: 1 branch
BranchTrueFalseTotal
unless $isbn_object and $isbn_object->is_valid 0 0 0
Condition0%0/3
$isbn_object and $isbn_object->is_valid
!ll&&!rl&&r
000
MC/DC0%0/2
$isbn_object and $isbn_object->is_valid
$isbn_object $isbn_object->is_valid
Truth table0%0/3
A and B
A= $isbn_objectB= $isbn_object->is_valid
ABresult
0X0
100
111
72 } else {
73 # our fallback just validates it looks like an ISBN
74 5 my $isbn_object = WWW::Scraper::ISBN::Driver->new();
75 5 ▶ croak("Invalid ISBN specified [$isbn].\n") unless($isbn_object && $isbn_object->is_valid($isbn));
Branch: 1 branch
BranchTrueFalseTotal
unless $isbn_object and $isbn_object->is_valid($isbn) 1 4 5
Condition66%2/3
$isbn_object and $isbn_object->is_valid($isbn)
!ll&&!rl&&r
014
MC/DC50%1/2
$isbn_object and $isbn_object->is_valid($isbn)
$isbn_object $isbn_object->is_valid($isbn)
Truth table66%2/3
A and B
A= $isbn_objectB= $isbn_object->is_valid($isbn)
ABresult
0X0
100
111
76 }
77  
78 4 ▶ croak("No search drivers specified.\n")
Branch: 1 branch
BranchTrueFalseTotal
if $self->drivers == 0 1 3 4
79 if( $self->drivers == 0 );
80  
81 3 my $record = WWW::Scraper::ISBN::Record->new();
82 3 $record->isbn($isbn);
83 3 for my $driver_name (@{ $self->{DRIVERS} }) {
84 3 my $driver = "WWW::Scraper::ISBN::${driver_name}_Driver"->new();
85 3 $driver->search($record->isbn);
86 3 ▶ if ($driver->found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($driver->found) 1 2 3
87 1 $record->found("1");
88 1 $record->found_in("$driver_name");
89 1 $record->book($driver->book);
90 1 last;
91 }
92  
93 2 ▶ $record->error($record->error.$driver->error)
Branch: 1 branch
BranchTrueFalseTotal
if $driver->error 1 1 2
94 if ($driver->error);
95 }
96  
97 3 return $record;
98 }
99  
100 6 1;
101  
102 __END__
↑ Summary ISBN/Driver.pm »