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