line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::ISBN; |
2
|
2
|
|
|
2
|
|
85640
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
96
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
1436
|
use Business::ISBN 2.0; |
|
2
|
|
|
|
|
147491
|
|
|
2
|
|
|
|
|
139
|
|
5
|
2
|
|
|
2
|
|
24
|
use Exporter qw(import); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
94
|
|
6
|
2
|
|
|
2
|
|
19
|
use Test::Builder; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1791
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $Test = Test::Builder->new(); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '2.041'; |
11
|
|
|
|
|
|
|
our @EXPORT = qw(isbn_ok isbn_group_ok isbn_country_ok isbn_publisher_ok); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=encoding utf8 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Test::ISBN - Check International Standard Book Numbers |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Test::More tests => 1; |
22
|
|
|
|
|
|
|
use Test::ISBN; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
isbn_ok( $isbn ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This is the 2.x version of Test::ISBN and works with Business::ISBN 2.x. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 Functions |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=over 4 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item isbn_ok( STRING | ISBN ) |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Ok is the STRING is a valid ISBN, in any format that Business::ISBN |
37
|
|
|
|
|
|
|
accepts. This function only checks the checksum. The publisher and |
38
|
|
|
|
|
|
|
country codes might be invalid even though the checksum is valid. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
If the first argument is an ISBN object, it checks that object. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub isbn_ok { |
45
|
11
|
|
|
11
|
1
|
47579
|
my $isbn = shift; |
46
|
|
|
|
|
|
|
|
47
|
11
|
|
|
|
|
37
|
my $object = _get_object( $isbn ); |
48
|
|
|
|
|
|
|
|
49
|
11
|
50
|
|
|
|
4102
|
my $string = ref $isbn ? eval { $isbn->as_string } : $isbn; |
|
0
|
|
|
|
|
0
|
|
50
|
|
|
|
|
|
|
|
51
|
11
|
|
100
|
|
|
65
|
my $ok = ref $object && |
52
|
|
|
|
|
|
|
( $object->is_valid_checksum( $string ) eq Business::ISBN::GOOD_ISBN ); |
53
|
11
|
100
|
|
|
|
639
|
$Test->diag( "The argument [$string] is not a valid ISBN" ) unless $ok; |
54
|
|
|
|
|
|
|
|
55
|
11
|
|
|
|
|
1212
|
$Test->ok( $ok ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item isbn_group_ok( STRING | ISBN, COUNTRY ) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Ok is the STRING is a valid ISBN and its country code is the same as |
61
|
|
|
|
|
|
|
COUNTRY. If the first argument is an ISBN object, it checks that |
62
|
|
|
|
|
|
|
object. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub isbn_group_ok { |
67
|
2
|
|
|
2
|
1
|
6275
|
my $isbn = shift; |
68
|
2
|
|
|
|
|
7
|
my $country = shift; |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
7
|
my $object = _get_object( $isbn ); |
71
|
|
|
|
|
|
|
|
72
|
2
|
50
|
|
|
|
709
|
my $string = ref $isbn ? eval { $isbn->as_string } : $isbn; |
|
0
|
|
|
|
|
0
|
|
73
|
|
|
|
|
|
|
|
74
|
2
|
100
|
|
|
|
15
|
unless( $object->is_valid ) { |
|
|
50
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
$Test->diag("ISBN [$string] is not valid"), |
76
|
|
|
|
|
|
|
$Test->ok(0); |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
0
|
elsif( $object->group_code eq $country ) { |
79
|
1
|
|
|
|
|
34
|
$Test->ok(1); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { |
82
|
1
|
|
|
|
|
13
|
$Test->diag("ISBN [$string] group code is wrong\n", |
83
|
|
|
|
|
|
|
"\tExpected [$country]\n", |
84
|
|
|
|
|
|
|
"\tGot [" . $object->group_code . "]\n" ); |
85
|
1
|
|
|
|
|
421
|
$Test->ok(0); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item isbn_country_ok( STRING | ISBN, COUNTRY ) |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Deprecated. Use isbn_group_ok. This is still exported, though. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
For now it warns and redirects to isbn_group_ok. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
If the first argument is an ISBN object, it checks that |
97
|
|
|
|
|
|
|
object. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub isbn_country_ok { |
102
|
0
|
|
|
0
|
1
|
0
|
$Test->diag( "isbn_country_ok is deprecated. Use isbn_group_ok" ); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
&isbn_group_ok; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item isbn_publisher_ok( STRING | ISBN, PUBLISHER ) |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Ok is the STRING is a valid ISBN and its publisher |
110
|
|
|
|
|
|
|
code is the same as PUBLISHER. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
If the first argument is an ISBN object, it checks that |
113
|
|
|
|
|
|
|
object. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub isbn_publisher_ok { |
118
|
2
|
|
|
2
|
1
|
4159
|
my $isbn = shift; |
119
|
2
|
|
|
|
|
5
|
my $publisher = shift; |
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
|
|
6
|
my $object = _get_object( $isbn ); |
122
|
|
|
|
|
|
|
|
123
|
2
|
50
|
|
|
|
542
|
my $string = ref $isbn ? eval { $isbn->as_string } : $isbn; |
|
0
|
|
|
|
|
0
|
|
124
|
|
|
|
|
|
|
|
125
|
2
|
100
|
|
|
|
9
|
unless( $object->is_valid ) { |
|
|
50
|
|
|
|
|
|
126
|
0
|
|
|
|
|
0
|
$Test->diag("ISBN [$string] is not valid"), |
127
|
|
|
|
|
|
|
$Test->ok(0); |
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
0
|
elsif( $object->publisher_code eq $publisher ) { |
130
|
1
|
|
|
|
|
15
|
$Test->ok(1); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
else { |
133
|
1
|
|
|
|
|
20
|
$Test->diag("ISBN [$string] publisher code is wrong\n", |
134
|
|
|
|
|
|
|
"\tExpected [$publisher]\n", |
135
|
|
|
|
|
|
|
"\tGot [" . $object->publisher_code . "]\n" ); |
136
|
1
|
|
|
|
|
293
|
$Test->ok(0); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub _get_object { |
141
|
15
|
|
|
15
|
|
43
|
my( $arg ) = @_; |
142
|
|
|
|
|
|
|
|
143
|
15
|
|
|
|
|
29
|
my $object = do { |
144
|
15
|
50
|
|
|
|
34
|
if( eval { $arg->isa( 'Business::ISBN' ) } ) { $arg } |
|
15
|
|
|
|
|
148
|
|
|
0
|
|
|
|
|
0
|
|
145
|
15
|
|
|
|
|
70
|
else { Business::ISBN->new( $arg ) } |
146
|
|
|
|
|
|
|
}; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This source is in GitHub: |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
https://github.com/briandfoy/test-isbn |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 AUTHOR |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
brian d foy, C<< >> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Copyright © 2002-2018, brian d foy . All rights reserved. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
166
|
|
|
|
|
|
|
it under the terms of the Artistic License 2.0. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |