Lines 28-33
use C4::Branch qw(GetBranchesCount);
Link Here
|
28 |
use Koha::DateUtils qw(dt_from_string); |
28 |
use Koha::DateUtils qw(dt_from_string); |
29 |
use Memoize; |
29 |
use Memoize; |
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 70-75
BEGIN {
Link Here
|
70 |
&GetNormalizedOCLCNumber |
71 |
&GetNormalizedOCLCNumber |
71 |
&xml_escape |
72 |
&xml_escape |
72 |
|
73 |
|
|
|
74 |
&GetVariationsOfISBN |
75 |
&GetVariationsOfISBNs |
76 |
&NormalizeISBN |
77 |
|
73 |
$DEBUG |
78 |
$DEBUG |
74 |
); |
79 |
); |
75 |
$DEBUG = 0; |
80 |
$DEBUG = 0; |
Lines 1475-1489
sub _normalize_match_point {
Link Here
|
1475 |
} |
1480 |
} |
1476 |
|
1481 |
|
1477 |
sub _isbn_cleanup { |
1482 |
sub _isbn_cleanup { |
1478 |
require Business::ISBN; |
1483 |
my ($isbn) = @_; |
1479 |
my $isbn = Business::ISBN->new( $_[0] ); |
1484 |
return NormalizeISBN( |
1480 |
if ( $isbn ) { |
1485 |
{ |
1481 |
$isbn = $isbn->as_isbn10 if $isbn->type eq 'ISBN13'; |
1486 |
isbn => $isbn, |
1482 |
if (defined $isbn) { |
1487 |
format => 'ISBN-10', |
1483 |
return $isbn->as_string([]); |
1488 |
strip_hyphens => 1, |
1484 |
} |
1489 |
} |
|
|
1490 |
); |
1491 |
} |
1492 |
|
1493 |
=head2 NormalizedISBN |
1494 |
|
1495 |
my $isbns = NormalizedISBN({ |
1496 |
isbn => $isbn, |
1497 |
strip_hyphens => [0,1], |
1498 |
format => ['ISBN-10', 'ISBN-13'] |
1499 |
}); |
1500 |
|
1501 |
Returns an isbn validated by Business::ISBN. |
1502 |
Optionally strips hyphens and/or forces the isbn |
1503 |
to be of the specified format. |
1504 |
|
1505 |
If the string cannot be validated as an isbn, |
1506 |
it returns nothing. |
1507 |
|
1508 |
=cut |
1509 |
|
1510 |
sub NormalizeISBN { |
1511 |
my ($params) = @_; |
1512 |
|
1513 |
my $string = $params->{isbn}; |
1514 |
my $strip_hyphens = $params->{strip_hyphens}; |
1515 |
my $format = $params->{format}; |
1516 |
|
1517 |
my $isbn = Business::ISBN->new($string); |
1518 |
|
1519 |
if ( $isbn && $isbn->error != Business::ISBN::BAD_ISBN ) { |
1520 |
|
1521 |
if ( $format eq 'ISBN-10' ) { |
1522 |
$isbn = $isbn->as_isbn10(); |
1523 |
} |
1524 |
elsif ( $format eq 'ISBN-13' ) { |
1525 |
$isbn = $isbn->as_isbn13(); |
1526 |
} |
1527 |
|
1528 |
if ($strip_hyphens) { |
1529 |
$string = $isbn->as_string( [] ); |
1530 |
} else { |
1531 |
$string = $isbn->as_string(); |
1532 |
} |
1533 |
|
1534 |
return $string; |
1485 |
} |
1535 |
} |
1486 |
return; |
1536 |
} |
|
|
1537 |
|
1538 |
=head2 GetVariationsOfISBN |
1539 |
|
1540 |
my @isbns = GetVariationsOfISBN( $isbn ); |
1541 |
|
1542 |
Returns a list of varations of the given isbn in |
1543 |
both ISBN-10 and ISBN-13 formats, with and without |
1544 |
hyphens. |
1545 |
|
1546 |
In a scalar context, the isbns are returned as a |
1547 |
string delimited by ' | '. |
1548 |
|
1549 |
=cut |
1550 |
|
1551 |
sub GetVariationsOfISBN { |
1552 |
my ($isbn) = @_; |
1553 |
|
1554 |
my @isbns; |
1555 |
|
1556 |
push( @isbns, NormalizeISBN({ isbn => $isbn }) ); |
1557 |
push( @isbns, NormalizeISBN({ isbn => $isbn, format => 'ISBN-10' }) ); |
1558 |
push( @isbns, NormalizeISBN({ isbn => $isbn, format => 'ISBN-13' }) ); |
1559 |
push( @isbns, NormalizeISBN({ isbn => $isbn, format => 'ISBN-10', strip_hyphens => 1 }) ); |
1560 |
push( @isbns, NormalizeISBN({ isbn => $isbn, format => 'ISBN-13', strip_hyphens => 1 }) ); |
1561 |
|
1562 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1563 |
} |
1564 |
|
1565 |
=head2 GetVariationsOfISBNs |
1566 |
|
1567 |
my @isbns = GetVariationsOfISBNs( @isbns ); |
1568 |
|
1569 |
Returns a list of varations of the given isbns in |
1570 |
both ISBN-10 and ISBN-13 formats, with and without |
1571 |
hyphens. |
1572 |
|
1573 |
In a scalar context, the isbns are returned as a |
1574 |
string delimited by ' | '. |
1575 |
|
1576 |
=cut |
1577 |
|
1578 |
sub GetVariationsOfISBNs { |
1579 |
my (@isbns) = @_; |
1580 |
|
1581 |
@isbns = map { GetVariationsOfISBN( $_ ) } @isbns; |
1582 |
|
1583 |
return wantarray ? @isbns : join( " | ", @isbns ); |
1487 |
} |
1584 |
} |
1488 |
|
1585 |
|
1489 |
1; |
1586 |
1; |