| 1 | package App::ISBN::Format; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Business::ISBN; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Class::Utils qw(set_params); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Getopt::Std; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | our $VERSION = 0.03; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # Constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | my ($class, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # Create object. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # Process parameters. | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | set_params($self, @params); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # Object. | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # Run. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=8 SCAR=21.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # Process arguments. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | $self->{'_opts'} = { | |||||||||||||||||||||||||||||||||||||||||
| 33 | 'h' => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | ▶ | if (! getopts('h', $self->{'_opts'}) || @ARGV < 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not &getopts("h", $self->{"_opts"}) or @ARGV < 1 or $self->{"_opts"}{"h"}
not &getopts("h", $self->{"_opts"}) or @ARGV < 1
MC/DC33%1/3
not &getopts("h", $self->{"_opts"}) or @ARGV < 1 or $self->{"_opts"}{"h"}
not &getopts("h", $self->{"_opts"})
@ARGV < 1
$self->{"_opts"}{"h"}
Truth table50%2/4
not(A) or B or C
A= not &getopts("h", $self->{"_opts"})B= @ARGV < 1C= $self->{"_opts"}{"h"}
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | || $self->{'_opts'}->{'h'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | print STDERR "Usage: $0 [-h] [--version] isbn_string\n"; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | print STDERR "\t-h\t\tPrint help.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | print STDERR "\t--version\tPrint version.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | print STDERR "\tisbn_string\tISBN string.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | $self->{'_isbn_string'} = shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | my $isbn_obj = Business::ISBN->new($self->{'_isbn_string'}); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | if (! $isbn_obj) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | err "ISBN '$self->{'_isbn_string'}' is bad."; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # Validation. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | ▶ | if (! $isbn_obj->is_valid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | $isbn_obj->fix_checksum; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # Check again. | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if (! $isbn_obj->is_valid) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | err "ISBN '$self->{'_isbn_string'}' is not valid."; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # Construct output. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | my $isbn_concrete; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | my $isbn_without_dash = $self->{'_isbn_string'}; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | $isbn_without_dash =~ s/-//msg; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | ▶ | if (length $isbn_without_dash > 10) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | $isbn_concrete = $isbn_obj->as_isbn13; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $isbn_concrete = $isbn_obj->as_isbn10; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | print $self->{'_isbn_string'}.' -> '.$isbn_concrete->as_string, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||||||||||||||||