Lines 28-33
use C4::Branch qw(GetBranchesCount);
Link Here
|
28 |
use Memoize; |
28 |
use Memoize; |
29 |
use DateTime; |
29 |
use DateTime; |
30 |
use DateTime::Format::MySQL; |
30 |
use DateTime::Format::MySQL; |
|
|
31 |
use Business::ISBN; |
31 |
use autouse 'Data::Dumper' => qw(Dumper); |
32 |
use autouse 'Data::Dumper' => qw(Dumper); |
32 |
|
33 |
|
33 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); |
34 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $DEBUG); |
Lines 71-76
BEGIN {
Link Here
|
71 |
&GetNormalizedOCLCNumber |
72 |
&GetNormalizedOCLCNumber |
72 |
&xml_escape |
73 |
&xml_escape |
73 |
|
74 |
|
|
|
75 |
&GetVariationsOfISBN |
76 |
&GetVariationsOfISBNs |
77 |
&NormalizeISBN |
78 |
|
74 |
$DEBUG |
79 |
$DEBUG |
75 |
); |
80 |
); |
76 |
$DEBUG = 0; |
81 |
$DEBUG = 0; |
Lines 1492-1506
sub _normalize_match_point {
Link Here
|
1492 |
} |
1497 |
} |
1493 |
|
1498 |
|
1494 |
sub _isbn_cleanup { |
1499 |
sub _isbn_cleanup { |
1495 |
require Business::ISBN; |
1500 |
my ($isbn) = @_; |
1496 |
my $isbn = Business::ISBN->new( $_[0] ); |
1501 |
return NormalizeISBN( |
1497 |
if ( $isbn ) { |
1502 |
{ |
1498 |
$isbn = $isbn->as_isbn10 if $isbn->type eq 'ISBN13'; |
1503 |
isbn => $isbn, |
1499 |
if (defined $isbn) { |
1504 |
format => 'ISBN-10', |
1500 |
return $isbn->as_string([]); |
1505 |
strip_hyphens => 1, |
1501 |
} |
1506 |
} |
|
|
1507 |
); |
1508 |
} |
1509 |
|
1510 |
=head2 NormalizedISBN |
1511 |
|
1512 |
my $isbns = NormalizedISBN({ |
1513 |
isbn => $isbn, |
1514 |
strip_hyphens => [0,1], |
1515 |
format => ['ISBN-10', 'ISBN-13'] |
1516 |
}); |
1517 |
|
1518 |
Returns an isbn validated by Business::ISBN. |
1519 |
Optionally strips hyphens and/or forces the isbn |
1520 |
to be of the specified format. |
1521 |
|
1522 |
If the string cannot be validated as an isbn, |
1523 |
it returns nothing. |
1524 |
|
1525 |
=cut |
1526 |
|
1527 |
sub NormalizeISBN { |
1528 |
my ($params) = @_; |
1529 |
|
1530 |
my $string = $params->{isbn}; |
1531 |
my $strip_hyphens = $params->{strip_hyphens}; |
1532 |
my $format = $params->{format}; |
1533 |
|
1534 |
my $isbn = Business::ISBN->new($string); |
1535 |
|
1536 |
if ( $isbn && $isbn->error != Business::ISBN::BAD_ISBN ) { |
1537 |
|
1538 |
if ( $format eq 'ISBN-10' ) { |
1539 |
$isbn = $isbn->as_isbn10(); |
1540 |
} |
1541 |
elsif ( $format eq 'ISBN-13' ) { |
1542 |
$isbn = $isbn->as_isbn13(); |
1543 |
} |
1544 |
|
1545 |
if ($strip_hyphens) { |
1546 |
$string = $isbn->as_string( [] ); |
1547 |
} else { |
1548 |
$string = $isbn->as_string(); |
1549 |
} |
1550 |
|
1551 |
return $string; |
1502 |
} |
1552 |
} |
1503 |
return; |
1553 |
} |
|
|
1554 |
|
1555 |
=head2 GetVariationsOfISBN |
1556 |
|
1557 |
my @isbns = GetVariationsOfISBN( $isbn ); |
1558 |
|
1559 |
Returns a list of varations of the given isbn in |
1560 |
both ISBN-10 and ISBN-13 formats, with and without |
1561 |
hyphens. |
1562 |
|
1563 |
In a scalar context, the isbns are returned as a |
1564 |
string delimited by ' | '. |
1565 |
|
1566 |
=cut |
1567 |
|
1568 |
sub GetVariationsOfISBN { |
1569 |
my ($isbn) = @_; |
1570 |
|
1571 |
my @isbns; |
1572 |
|
1573 |
push( @isbns, NormalizeISBN({ isbn => $isbn }) ); |
1574 |
push( @isbns, NormalizeISBN({ isbn => $isbn, format => 'ISBN-10' }) ); |
1575 |
push( @isbns, NormalizeISBN({ isbn => $isbn, format => 'ISBN-13' }) ); |
1576 |
push( @isbns, NormalizeISBN({ isbn => $isbn, format => 'ISBN-10', strip_hyphens => 1 }) ); |
1577 |
push( @isbns, NormalizeISBN({ isbn => $isbn, format => 'ISBN-13', strip_hyphens => 1 }) ); |
1578 |
|
1579 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1580 |
} |
1581 |
|
1582 |
=head2 GetVariationsOfISBNs |
1583 |
|
1584 |
my @isbns = GetVariationsOfISBNs( @isbns ); |
1585 |
|
1586 |
Returns a list of varations of the given isbns in |
1587 |
both ISBN-10 and ISBN-13 formats, with and without |
1588 |
hyphens. |
1589 |
|
1590 |
In a scalar context, the isbns are returned as a |
1591 |
string delimited by ' | '. |
1592 |
|
1593 |
=cut |
1594 |
|
1595 |
sub GetVariationsOfISBNs { |
1596 |
my (@isbns) = @_; |
1597 |
|
1598 |
@isbns = map { GetVariationsOfISBN( $_ ) } @isbns; |
1599 |
|
1600 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1504 |
} |
1601 |
} |
1505 |
|
1602 |
|
1506 |
1; |
1603 |
1; |