line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::ISBN::Format; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
79005
|
use strict; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
71
|
|
4
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
59
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
1280
|
use Business::ISBN; |
|
3
|
|
|
|
|
135576
|
|
|
3
|
|
|
|
|
119
|
|
7
|
3
|
|
|
3
|
|
1207
|
use Class::Utils qw(set_params); |
|
3
|
|
|
|
|
73024
|
|
|
3
|
|
|
|
|
49
|
|
8
|
3
|
|
|
3
|
|
185
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
94
|
|
9
|
3
|
|
|
3
|
|
5062
|
use Getopt::Std; |
|
3
|
|
|
|
|
144
|
|
|
3
|
|
|
|
|
921
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.01; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Constructor. |
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
1
|
74
|
my ($class, @params) = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Create object. |
18
|
1
|
|
|
|
|
3
|
my $self = bless {}, $class; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Process parameters. |
21
|
1
|
|
|
|
|
5
|
set_params($self, @params); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Object. |
24
|
1
|
|
|
|
|
8
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Run. |
28
|
|
|
|
|
|
|
sub run { |
29
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Process arguments. |
32
|
0
|
|
|
|
|
|
$self->{'_opts'} = { |
33
|
|
|
|
|
|
|
'h' => 0, |
34
|
|
|
|
|
|
|
}; |
35
|
0
|
0
|
0
|
|
|
|
if (! getopts('h', $self->{'_opts'}) || @ARGV < 1 |
|
|
|
0
|
|
|
|
|
36
|
|
|
|
|
|
|
|| $self->{'_opts'}->{'h'}) { |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
print STDERR "Usage: $0 [-h] [--version] isbn_string\n"; |
39
|
0
|
|
|
|
|
|
print STDERR "\t-h\t\tPrint help.\n"; |
40
|
0
|
|
|
|
|
|
print STDERR "\t--version\tPrint version.\n"; |
41
|
0
|
|
|
|
|
|
print STDERR "\tisbn_string\tISBN string."; |
42
|
0
|
|
|
|
|
|
return 1; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
$self->{'_isbn_string'} = shift @ARGV; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $isbn_obj = Business::ISBN->new($self->{'_isbn_string'}); |
47
|
0
|
0
|
|
|
|
|
if (! $isbn_obj) { |
48
|
0
|
|
|
|
|
|
err "ISBN '$self->{'_isbn_string'}' is bad."; |
49
|
0
|
|
|
|
|
|
return 1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Validation. |
53
|
0
|
0
|
|
|
|
|
if (! $isbn_obj->is_valid) { |
54
|
0
|
|
|
|
|
|
$isbn_obj->fix_checksum; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Check again. |
57
|
0
|
0
|
|
|
|
|
if (! $isbn_obj->is_valid) { |
58
|
0
|
|
|
|
|
|
err "ISBN '$self->{'_isbn_string'}' is not valid."; |
59
|
0
|
|
|
|
|
|
return 1; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Construct output. |
64
|
0
|
|
|
|
|
|
my $isbn_concrete; |
65
|
0
|
0
|
|
|
|
|
if (length $self->{'_isbn_string'} > 10) { |
66
|
0
|
|
|
|
|
|
$isbn_concrete = $isbn_obj->as_isbn13; |
67
|
|
|
|
|
|
|
} else { |
68
|
0
|
|
|
|
|
|
$isbn_concrete = $isbn_obj->as_isbn10; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
print $self->{'_isbn_string'}.' -> '.$isbn_concrete->as_string, "\n"; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |