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