URI/urn/isbn.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 140 CC 11 SCAR 18.3
CC
11
Cov
0%
_isbn
12.0
BEGIN
12.0
canonical
12.0
CRAP 6.2
1 package URI::urn::isbn; # RFC 3187
2  
3 use strict;
4 use warnings;
5  
6 our $VERSION = '5.40';
7  
8 use parent 'URI::urn';
9  
10 use Carp qw(carp);
11  
12 BEGIN {
13 require Business::ISBN;
14  
15 local $^W = 0; # don't warn about dev versions, perl5.004 style
16 warn "Using Business::ISBN version "
17 . Business::ISBN->VERSION
18 . " which is deprecated.\nUpgrade to Business::ISBN version 3.005\n"
19 if Business::ISBN->VERSION < 3.005;
20 }
21  
22 sub _isbn {
23 my $nss = shift;
24 $nss = $nss->nss if ref($nss);
25 my $isbn = Business::ISBN->new($nss);
26 $isbn = undef if $isbn && !$isbn->is_valid;
27 return $isbn;
28 }
29  
30 sub _nss_isbn {
31 my $self = shift;
32 my $nss = $self->nss(@_);
33 my $isbn = _isbn($nss);
34 $isbn = $isbn->as_string if $isbn;
35 return ($nss, $isbn);
36 }
37  
38 sub isbn {
39 my $self = shift;
40 my $isbn;
41 (undef, $isbn) = $self->_nss_isbn(@_);
42 return $isbn;
43 }
44  
45 sub isbn_publisher_code {
46 my $isbn = shift->_isbn || return undef;
47 return $isbn->publisher_code;
48 }
49  
50 BEGIN {
51 my $group_method = do {
52 local $^W = 0; # don't warn about dev versions, perl5.004 style
53 Business::ISBN->VERSION >= 2 ? 'group_code' : 'country_code';
54 };
55  
56 sub isbn_group_code {
57 my $isbn = shift->_isbn || return undef;
58 return $isbn->$group_method;
59 }
60 }
61  
62 sub isbn_country_code {
63 my $name = (caller(0))[3];
64 $name =~ s/.*:://;
65 carp "$name is DEPRECATED. Use isbn_group_code instead";
66  
67 no strict 'refs';
68 &isbn_group_code;
69 }
70  
71 BEGIN {
72 my $isbn13_method = do {
73 local $^W = 0; # don't warn about dev versions, perl5.004 style
74 Business::ISBN->VERSION >= 2 ? 'as_isbn13' : 'as_ean';
75 };
76  
77 sub isbn13 {
78 my $isbn = shift->_isbn || return undef;
79  
80 # Business::ISBN 1.x didn't put hyphens in the EAN, and it was just a string
81 # Business::ISBN 2.0 doesn't do EAN, but it does ISBN-13 objects
82 # and it uses the hyphens, so call as_string with an empty anon array
83 # or, adjust the test and features to say that it comes out with hyphens.
84 my $thingy = $isbn->$isbn13_method;
85 return
86 eval { $thingy->can('as_string') }
87 ? $thingy->as_string([])
88 : $thingy;
89 }
90 }
91  
92 sub isbn_as_ean {
93 my $name = (caller(0))[3];
94 $name =~ s/.*:://;
95 carp "$name is DEPRECATED. Use isbn13 instead";
96  
97 no strict 'refs';
98 &isbn13;
99 }
100  
101 sub canonical {
102 my $self = shift;
103 my ($nss, $isbn) = $self->_nss_isbn;
104 my $new = $self->SUPER::canonical;
105 return $new unless $nss && $isbn && $nss ne $isbn;
106 $new = $new->clone if $new == $self;
107 $new->nss($isbn);
108 return $new;
109 }
110  
111 1;