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