Skip Menu |

This queue is for tickets about the URI CPAN distribution.

Report information
The Basics
Id: 33220
Status: resolved
Priority: 0/
Queue: URI

People
Owner: Nobody in particular
Requestors: rnorwood [...] redhat.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.35
Fixed in: (no value)



Subject: Test fails with Business::ISBN installed
If Business::ISBN is installed, the follow test failure occurs: t/urn-isbn.......Can't locate object method "country_code" via package "Business::ISBN10" at perl-URI/devel/URI-1.35/blib/lib/URI/urn/isbn.pm line 40. I don't know if the API for Business::ISBN changed, or if the URI test is just broken. This is in Fedora 8/9, found during package review for perl-URI: https://bugzilla.redhat.com/show_bug.cgi?id=226283
From: kousuketakeuchi [...] gmail.com
Business::ISBN is installed,error happend 1st: ------------------------------ t/urn-isbn.........Can't locate object method "country_code" via package "Business::ISBN10" at /root/.cpan/build/URI-1.35/blib/lib/URI/urn/isbn.pm line 40. t/urn-isbn......... Dubious, test returned 2 (wstat 512, 0x200) change source code:URI/urn/isbn.pm ------------------------------ sub isbn_country_code { my $isbn = shift->_isbn || return undef; return $isbn->group_code; #return $isbn->country_code; } < return $isbn->country_code; --- Show quoted text
> return $isbn->group_code; > #return $isbn->country_code;
Business::ISBN is installed,error happend 2nd: ------------------------------ t/urn-isbn.........Can't locate object method "as_ean" via package "Business::ISBN10" at /root/.cpan/build/URI-1.35/blib/lib/URI/urn/isbn.pm line 46. t/urn-isbn......... Dubious, test returned 2 (wstat 512, 0x200) sub isbn_as_ean { my $isbn = shift->_isbn || return undef; return $isbn->as_isbn13->as_string([]); #return $isbn->as_ean; } < return $isbn->as_ean; --- Show quoted text
> return $isbn->as_isbn13->as_string([]); > #return $isbn->as_ean;
On 水曜日 2月 13 12:13:07 2008, rnorwood wrote: Show quoted text
> If Business::ISBN is installed, the follow test failure occurs: > > t/urn-isbn.......Can't locate object method "country_code" via package > "Business::ISBN10" at > perl-URI/devel/URI-1.35/blib/lib/URI/urn/isbn.pm line 40. > > I don't know if the API for Business::ISBN changed, or if the URI test > is just broken. > > This is in Fedora 8/9, found during package review for perl-URI: > > https://bugzilla.redhat.com/show_bug.cgi?id=226283 >
Here's a better patch. The problem is that Business::ISBN 1.x used the unfortunate name "country_code" which changed to the correct name "group_code" in Business::ISBN 2.x. Since the new version of Business::ISBN handles ISBN-13, the EAN support is now just ISBN-13. The trick is to support both major versions of the modules and Perl versions back to 5.004 (declared in Makefile.PL). I've tested this with Business::ISBN 1.84 and 2.03. diff -r -u URI-1.35-dist/URI/urn/isbn.pm URI-1.35-new/URI/urn/isbn.pm --- URI-1.35-dist/URI/urn/isbn.pm 2002-07-06 11:43:14.000000000 -0500 +++ URI-1.35-new/URI/urn/isbn.pm 2008-02-21 18:43:14.000000000 -0600 @@ -4,9 +4,17 @@ @ISA=qw(URI::urn); use strict; -use Business::ISBN (); - +use Carp qw(carp); +BEGIN { + require Business::ISBN; + + local $^W = 0; # don't warn about dev versions, perl5.004 style + warn "Using Business::ISBN version " . Business::ISBN->VERSION . + " which is deprecated.\nUpgrade to Business::ISBN version 2\n" + if Business::ISBN->VERSION < 2; + } + sub _isbn { my $nss = shift; $nss = $nss->nss if ref($nss); @@ -35,14 +43,50 @@ return $isbn->publisher_code; } +BEGIN { +my $group_method = do { + local $^W = 0; # don't warn about dev versions, perl5.004 style + Business::ISBN->VERSION >= 2 ? 'group_code' : 'country_code'; + }; + +sub isbn_group_code { + my $isbn = shift->_isbn || return undef; + return $isbn->$group_method; +} +} + sub isbn_country_code { + my $name = (caller(0))[3]; $name =~ s/.*:://; + carp "$name is DEPRECATED. Use isbn_group_code instead"; + + no strict 'refs'; + &isbn_group_code; +} + +BEGIN { +my $isbn13_method = do { + local $^W = 0; # don't warn about dev versions, perl5.004 style + Business::ISBN->VERSION >= 2 ? 'as_isbn13' : 'as_ean'; + }; + +sub isbn13 { my $isbn = shift->_isbn || return undef; - return $isbn->country_code; + + # Business::ISBN 1.x didn't put hyphens in the EAN, and it was just a string + # Business::ISBN 2.0 doesn't do EAN, but it does ISBN-13 objects + # and it uses the hyphens, so call as_string with an empty anon array + # or, adjust the test and features to say that it comes out with hyphens. + my $thingy = $isbn->$isbn13_method; + return eval { $thingy->can( 'as_string' ) } ? $thingy->as_string([]) : $thingy; +} } sub isbn_as_ean { - my $isbn = shift->_isbn || return undef; - return $isbn->as_ean; + my $name = (caller(0))[3]; $name =~ s/.*:://; + carp "$name is DEPRECATED. Use isbn13 instead"; + + no strict 'refs'; + &isbn13; } sub canonical { diff -r -u URI-1.35-dist/URI.pm URI-1.35-new/URI.pm --- URI-1.35-dist/URI.pm 2004-11-05 08:17:33.000000000 -0600 +++ URI-1.35-new/URI.pm 2008-02-21 18:41:52.000000000 -0600 @@ -907,7 +907,8 @@ Numbers (ISBNs) and is described in RFC 3187. A C<URI> object belonging to this namespace has the following extra methods (if the Business::ISBN module is available): $uri->isbn, -$uri->isbn_publisher_code, $uri->isbn_country_code, $uri->isbn_as_ean. +$uri->isbn_publisher_code, $uri->isbn_group_code (formerly isbn_country_code, +which is still supported by issues a deprecation warning), $uri->isbn_as_ean. =item B<urn>:B<oid>: Only in URI-1.35-new: blib Only in URI-1.35-new: pm_to_blib diff -r -u URI-1.35-dist/t/urn-isbn.t URI-1.35-new/t/urn-isbn.t --- URI-1.35-dist/t/urn-isbn.t 2003-10-03 07:27:18.000000000 -0500 +++ URI-1.35-new/t/urn-isbn.t 2008-02-21 18:21:34.000000000 -0600 @@ -25,13 +25,13 @@ print "not " unless $u->isbn eq "0-395-36341-1"; print "ok 3\n"; -print "not " unless $u->isbn_country_code == 0; +print "not " unless $u->isbn_group_code == 0; print "ok 4\n"; print "not " unless $u->isbn_publisher_code == 395; print "ok 5\n"; -print "not " unless $u->isbn_as_ean eq "9780395363416"; +print "not " unless $u->isbn13 eq "9780395363416"; print "ok 6\n"; print "not " unless $u->nss eq "0395363411";
Patch applied.