[libcatmandu-marc-perl] 46/208: gh#34: Deprecate USMARC

Jonas Smedegaard dr at jones.dk
Sat Oct 28 03:42:34 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag upstream/1.19
in repository libcatmandu-marc-perl.

commit 969e4f4a554449d0d35fa5d0b06a6c1b595d6956
Author: Johann Rolschewski <jorol at cpan.org>
Date:   Wed Sep 14 13:26:08 2016 +0200

    gh#34: Deprecate USMARC
---
 Changes                                          |  1 +
 cpanfile                                         |  1 +
 lib/Catmandu/Exporter/MARC.pm                    | 18 ++++++++++----
 lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm           |  2 +-
 lib/Catmandu/Exporter/MARC/{USMARC.pm => ISO.pm} | 10 ++++----
 lib/Catmandu/Exporter/MARC/XML.pm                |  2 +-
 lib/Catmandu/Importer/MARC.pm                    | 16 +++++++++----
 lib/Catmandu/Importer/MARC/{USMARC.pm => ISO.pm} | 10 ++++----
 t/01-importer.t                                  | 19 +++++----------
 t/03-marc_map.t                                  |  4 ++--
 t/05-marc_remove.t                               |  2 +-
 t/06-old-new-internal-syntax.t                   |  2 +-
 t/08-exporter.t                                  | 20 +++-------------
 t/12-marc_set.t                                  |  8 +++----
 t/16-marc-each.t                                 |  2 +-
 t/19-io-string.t                                 |  2 +-
 t/99-deprecate.t                                 | 30 ++++++++++++++++++++++++
 t/{camel.usmarc => camel.mrc}                    |  0
 18 files changed, 88 insertions(+), 61 deletions(-)

diff --git a/Changes b/Changes
index 79a54f4..b59190e 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 Revision history for Catmandu-MARC
 
 {{$NEXT}}
+  - Deprecation notice for USMARC
   - Adding marc_has and marc_has_many fixes
 
 1.00_01  2016-07-14 09:33:22 CEST
diff --git a/cpanfile b/cpanfile
index ae0e652..3192151 100644
--- a/cpanfile
+++ b/cpanfile
@@ -4,6 +4,7 @@ on 'test', sub {
   requires 'Test::Simple', '1.001003';
   requires 'Test::More', '1.001003';
   requires 'Test::Deep', '0';
+  requires 'Test::Warnings', '0';
   requires 'XML::XPath', '1.13';
   requires 'Pod::Simple::HTML', '>=3.23';
   requires 'Test::Pod' , '0';
diff --git a/lib/Catmandu/Exporter/MARC.pm b/lib/Catmandu/Exporter/MARC.pm
index 7d3f761..0df2100 100644
--- a/lib/Catmandu/Exporter/MARC.pm
+++ b/lib/Catmandu/Exporter/MARC.pm
@@ -5,12 +5,12 @@ Catmandu::Exporter::MARC - Exporter for MARC records
 =head1 SYNOPSIS
 
     # From the command line
-    $ catmandu convert MARC --type USMARC to MARC --type XML < /foo/bar.mrc
+    $ catmandu convert MARC --type ISO to MARC --type XML < /foo/bar.mrc
 
     # From Perl
     use Catmandu;
 
-    my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'USMARC');
+    my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'ISO');
     my $exporter = Catmandu->exporter('MARC', file => "marc.xml", type => "XML" );
 
     $exporter->add($importer);
@@ -29,8 +29,8 @@ to a file or the standard output.
 
 Create a new MARC exporter of the given type. Currently we support:
 
-    USMARC    L<Catmandu::Exporter::MARC::USMARC>
-    ISO       alias for USMARC
+    USMARC    alias for ISO, B<deprecated, will be removed in future version>
+    ISO       L<Catmandu::Importer::MARC::ISO>
     XML       L<Catmandu::Exporter::MARC::XML>
     MARCMaker L<Catmandu::Exporter::MARC::MARCMaker>
     MiJ       L<Catmandu::Exporter::MARC::MiJ> (Marc in Json)
@@ -75,7 +75,8 @@ has _exporter_args => (is => 'rwp', writer => '_set_exporter_args');
 
 sub _build_exporter {
     my ($self) = @_;
-    my $type = $self->type eq 'ISO' ? 'USMARC' : $self->type;
+
+    my $type = $self->type;
 
     my $pkg = Catmandu::Util::require_package($type,'Catmandu::Exporter::MARC');
 
@@ -85,6 +86,13 @@ sub _build_exporter {
 sub BUILD {
     my ($self,$args) = @_;
     $self->_set_exporter_args($args);
+
+    # keep USMARC temporary as alias for ISO, remove in future version
+    # print deprecation warning
+    if ($self->{type} eq 'USMARC') {
+        $self->{type} = 'ISO';
+        warn( "deprecated", "Oops! Exporter \"USMARC\" is deprecated. Use \"ISO\" instead." );
+    }
 }
 
 1;
diff --git a/lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm b/lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm
index 41600b5..6803a3b 100644
--- a/lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm
+++ b/lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm
@@ -10,7 +10,7 @@ Catmandu::Exporter::MARC::ALEPHSEQ - Exporter for MARC records to Ex Libris' Ale
     # From Perl
     use Catmandu;
 
-    my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'USMARC');
+    my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'ISO');
     my $exporter = Catmandu->exporter('MARC', file => "marc.txt", type => 'ALEPHSEQ' );
 
     $exporter->add($importer);
diff --git a/lib/Catmandu/Exporter/MARC/USMARC.pm b/lib/Catmandu/Exporter/MARC/ISO.pm
similarity index 85%
rename from lib/Catmandu/Exporter/MARC/USMARC.pm
rename to lib/Catmandu/Exporter/MARC/ISO.pm
index 3df11a8..4779754 100644
--- a/lib/Catmandu/Exporter/MARC/USMARC.pm
+++ b/lib/Catmandu/Exporter/MARC/ISO.pm
@@ -1,17 +1,17 @@
 =head1 NAME
 
-Catmandu::Exporter::MARC::USMARC - Exporter for MARC records to USMARC
+Catmandu::Exporter::MARC::ISO - Exporter for MARC records to ISO
 
 =head1 SYNOPSIS
 
     # From the command line
-    $ catmandu convert MARC --type XML to MARC --type USMARC < /foo/data.mrc
+    $ catmandu convert MARC --type ISO to MARC --type XML < /foo/bar.mrc
 
     # From Perl
     use Catmandu;
 
-    my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'XML');
-    my $exporter = Catmandu->exporter('MARC', file => "marc.xml", type => 'USMARC' );
+    my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'ISO');
+    my $exporter = Catmandu->exporter('MARC', file => "/foo/bar.xml", type => 'XML' );
 
     $exporter->add($importer);
     $exporter->commit;
@@ -52,7 +52,7 @@ L<Catmandu::Counter>, and L<Catmandu::Logger> for a full list of methods.
 L<Catmandu::Exporter>
 
 =cut
-package Catmandu::Exporter::MARC::USMARC;
+package Catmandu::Exporter::MARC::ISO;
 use Catmandu::Sane;
 use Catmandu::Util qw(xml_escape is_different :array :is);
 use Moo;
diff --git a/lib/Catmandu/Exporter/MARC/XML.pm b/lib/Catmandu/Exporter/MARC/XML.pm
index a297ca3..3d3d9c2 100644
--- a/lib/Catmandu/Exporter/MARC/XML.pm
+++ b/lib/Catmandu/Exporter/MARC/XML.pm
@@ -112,7 +112,7 @@ Catmandu::Exporter::MARC::XML - Exporter for MARC records to MARCXML
     # From Perl
     use Catmandu;
 
-    my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'USMARC');
+    my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'ISO');
     my $exporter = Catmandu->exporter('MARC', file => "marc.xml", type => 'XML' );
 
     $exporter->add($importer);
diff --git a/lib/Catmandu/Importer/MARC.pm b/lib/Catmandu/Importer/MARC.pm
index 6582cba..ce24010 100644
--- a/lib/Catmandu/Importer/MARC.pm
+++ b/lib/Catmandu/Importer/MARC.pm
@@ -70,8 +70,8 @@ Read more about processing data with Catmandu on the wiki: L<https://github.com/
 
 Create a new MARC importer of the given type. Currently we support:
 
-    USMARC    L<Catmandu::Importer::MARC::USMARC>
-    ISO       alias for USMARC
+    USMARC    alias for ISO, B<deprecated, will be removed in future version>
+    ISO       L<Catmandu::Importer::MARC::ISO>
     MicroLIF  L<Catmandu::Importer::MARC::MicroLIF>
     MARCMaker L<Catmandu::Importer::MARC::MARCMaker>
     MiJ       L<Catmandu::Importer::MARC::MiJ>
@@ -117,7 +117,7 @@ use Moo;
 
 our $VERSION = '1.00_01';
 
-has type           => (is => 'ro' , default => sub { 'USMARC' });
+has type           => (is => 'ro' , default => sub { 'ISO' });
 has _importer      => (is => 'ro' , lazy => 1 , builder => '_build_importer' , handles => ['generator']);
 has _importer_args => (is => 'rwp', writer => '_set_importer_args');
 
@@ -125,7 +125,8 @@ with 'Catmandu::Importer';
 
 sub _build_importer {
     my ($self) = @_;
-    my $type = $self->type eq 'ISO' ? 'USMARC' : $self->type;
+
+    my $type = $self->type;
 
     $type = 'Record' if exists $self->_importer_args->{records};
 
@@ -137,6 +138,13 @@ sub _build_importer {
 sub BUILD {
     my ($self,$args) = @_;
     $self->_set_importer_args($args);
+
+    # keep USMARC temporary as alias for ISO, remove in future version
+    # print deprecation warning
+    if ($self->{type} eq 'USMARC') {
+        $self->{type} = 'ISO';
+        warn( "deprecated", "Oops! Importer \"USMARC\" is deprecated. Use \"ISO\" instead." );
+    }
 }
 
 
diff --git a/lib/Catmandu/Importer/MARC/USMARC.pm b/lib/Catmandu/Importer/MARC/ISO.pm
similarity index 91%
rename from lib/Catmandu/Importer/MARC/USMARC.pm
rename to lib/Catmandu/Importer/MARC/ISO.pm
index 03f0191..0b497aa 100644
--- a/lib/Catmandu/Importer/MARC/USMARC.pm
+++ b/lib/Catmandu/Importer/MARC/ISO.pm
@@ -1,17 +1,17 @@
 =head1 NAME
 
-Catmandu::Importer::MARC::USMARC - Package that imports USMARC records
+Catmandu::Importer::MARC::ISO - Package that imports ISO MARC records
 
 =head1 SYNOPSIS
 
-    # From the command line (USMARC is the default importer for MARC)
-    $ catmandu convert MARC --fix "marc_map('245a','title')" < /foo/data.mrc
+    # From the command line (ISO is the default importer for MARC)
+    $ catmandu convert MARC --fix "marc_map('245a','title')" < /foo/bar.mrc
 
     # From perl
     use Catmandu;
 
     # import records from file
-    my $importer = Catmandu->importer('MARC',file => '/foo/data.mrc');
+    my $importer = Catmandu->importer('MARC',file => '/foo/bar.mrc');
     my $fixer    = Catmandu->fixer("marc_map('245a','title')");
 
     $importer->each(sub {
@@ -64,7 +64,7 @@ L<Catmandu::Importer>,
 L<Catmandu::Iterable>
 
 =cut
-package Catmandu::Importer::MARC::USMARC;
+package Catmandu::Importer::MARC::ISO;
 use Catmandu::Sane;
 use Moo;
 use MARC::File::USMARC;
diff --git a/t/01-importer.t b/t/01-importer.t
index d8200ca..7b1909a 100644
--- a/t/01-importer.t
+++ b/t/01-importer.t
@@ -5,11 +5,11 @@ use warnings;
 
 use Catmandu::Importer::MARC;
 use MARC::File::USMARC;
-use Test::Simple tests => 10;
+use Test::Simple tests => 9;
 
 my $importer = Catmandu::Importer::MARC->new(
-    file => 't/camel.usmarc',
-    type => "USMARC"
+    file => 't/camel.mrc',
+    type => "ISO"
 );
 my $records = $importer->to_array();
 
@@ -19,7 +19,7 @@ ok( $records->[0]->{'record'}->[1][-1] eq 'fol05731351 ', 'got subfield' );
 ok( $records->[0]->{'_id'} eq $records->[0]->{'record'}->[1][-1],
     '_id matches record id' );
 
-my $file = MARC::File::USMARC->in('t/camel.usmarc');
+my $file = MARC::File::USMARC->in('t/camel.mrc');
 my @marc_objects;
 while ( my $marc = $file->next() ) {
     push( @marc_objects, $marc );
@@ -37,16 +37,9 @@ ok( $records->[0]->{'_id'} eq $records->[0]->{'record'}->[1][-1],
 
 # Test that the ID can be formed like '260c' (not a useful field in real life!)
 $importer = Catmandu::Importer::MARC->new(
-    file => 't/camel.usmarc',
-    type => "USMARC",
+    file => 't/camel.mrc',
+    type => "ISO",
     id   => '260c',
 );
 $records = $importer->to_array();
 ok( $records->[0]->{'_id'} eq '2000.', 'got _id from subfield' );
-
-# ISO as alias for USMARC
-$importer
-    = Catmandu::Importer::MARC->new( file => 't/camel.usmarc', type => "ISO",
-    );
-$records = $importer->to_array();
-ok( @$records == 10, 'type ISO' );
diff --git a/t/03-marc_map.t b/t/03-marc_map.t
index 7ee9c1b..fe2a4e2 100644
--- a/t/03-marc_map.t
+++ b/t/03-marc_map.t
@@ -11,7 +11,7 @@ use Catmandu::Importer::MARC;
 use Catmandu::Fix;
 
 my $fixer = Catmandu::Fix->new(fixes => ['t/test.fix']);
-my $importer = Catmandu::Importer::MARC->new( file => 't/camel.usmarc', type => "USMARC" );
+my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
 my $records = $fixer->fix($importer)->to_array;
 
 is $records->[0]->{my}{id}, 'fol05731351 ', q|fix: marc_map('001','my.id');|;
@@ -23,7 +23,7 @@ is_deeply
     ['ActivePerl with ASP and ADO /', 'Tobias Martinsson.'],
     q|fix: marc_map('245','my.split.title','-split', 1);|;
 
-# field 666 does not exist in camel.usmarc
+# field 666 does not exist in camel.mrc
 # the '$append' fix creates $my->{'references'} hash key with empty array ref as value
 ok !$records->[0]->{'my'}{'references'}, q|fix: marc_map('666', 'my.references.$append');|;
 
diff --git a/t/05-marc_remove.t b/t/05-marc_remove.t
index 40799e3..8998894 100644
--- a/t/05-marc_remove.t
+++ b/t/05-marc_remove.t
@@ -17,7 +17,7 @@ my $fixer = Catmandu::Fix->new(fixes => [
                 q|marc_remove('082[1,1]a')|,
                 q|marc_remove('050[,0]ab')|,
                 ]);
-my $importer = Catmandu::Importer::MARC->new( file => 't/camel.usmarc', type => "USMARC" );
+my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
 my $record = $importer->first;
 
 my $title  = marc_map($record,'245');
diff --git a/t/06-old-new-internal-syntax.t b/t/06-old-new-internal-syntax.t
index 7dc938e..08f123f 100644
--- a/t/06-old-new-internal-syntax.t
+++ b/t/06-old-new-internal-syntax.t
@@ -16,7 +16,7 @@ ok(defined($records->[1]->{title}), "1 has title");
 is($records->[0]->{title},'ActivePerl with ASP and ADO /',"0 has correct title");
 is($records->[1]->{title},'ActivePerl with ASP and ADO /',"1 has correct title");
 
-$importer = Catmandu::Importer::MARC->new( file => 't/camel.usmarc', type => "USMARC" );
+$importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
 $records = $fixer->fix($importer)->to_array;
 
 ok(defined($records->[0]->{title}), "1 has title");
diff --git a/t/08-exporter.t b/t/08-exporter.t
index e6ceb5b..69daa0e 100644
--- a/t/08-exporter.t
+++ b/t/08-exporter.t
@@ -5,13 +5,13 @@ use warnings;
 
 use Catmandu::Exporter::MARC;
 use XML::XPath;
-use Test::Simple tests => 26;
+use Test::Simple tests => 24;
 
 my $xml = undef;
 
 my $exporter = Catmandu::Exporter::MARC->new(file => \$xml, type=> 'XML' , collection => 0);
 
-ok($exporter, "create exporter RAW");
+ok($exporter, "create exporter XML");
 
 $exporter->add({
   record => [
@@ -113,18 +113,4 @@ $exporter->add({
 
 ok($xml =~ /^000000001/, 'test id');
 ok($xml =~ /000000001 100   L \$\$aDavis, Miles\$\$cTest/, 'test subfields');
-ok($xml !~ /000000001 500/, 'test skip empty subfields');
-
-$xml = '';
-$exporter = Catmandu::Exporter::MARC->new(file => \$xml, type=> 'ISO');
-
-ok($exporter, "create exporter ISO/USMARC");
-
-$exporter->add({
-  _id => '1' ,
-  record => [
-            ['001', undef, undef, '_', 'rec001'],
-            ['100', ' ', ' ', 'a', 'Davis, Miles' , 'c' , 'Test'],
-        ]
-});
-ok($xml =~ /^00080     2200049   4500001000700000100002300007
rec001
  aDavis, MilescTest

$/, 'test ISO/USMARC');
+ok($xml !~ /000000001 500/, 'test skip empty subfields');
\ No newline at end of file
diff --git a/t/12-marc_set.t b/t/12-marc_set.t
index b346f0b..85ae949 100644
--- a/t/12-marc_set.t
+++ b/t/12-marc_set.t
@@ -11,7 +11,7 @@ use Catmandu::Importer::MARC;
 use Catmandu::Fix;
 
 my $fixer = Catmandu::Fix->new(fixes => [q|marc_set('LDR/0-3','XXX')|,q|marc_map('LDR','leader')|]);
-my $importer = Catmandu::Importer::MARC->new( file => 't/camel.usmarc', type => "USMARC" );
+my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
 my $record = $fixer->fix($importer->first);
 
 like $record->{leader}, qr/^XXX/, q|fix: marc_set('LDR/0-3','XXX');|;
@@ -19,7 +19,7 @@ like $record->{leader}, qr/^XXX/, q|fix: marc_set('LDR/0-3','XXX');|;
 #---
 {
 	$fixer = Catmandu::Fix->new(fixes => [q|marc_set('100x','XXX')|,q|marc_map('100x','test')|]);
-	$importer = Catmandu::Importer::MARC->new( file => 't/camel.usmarc', type => "USMARC" );
+	$importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
 	$record = $fixer->fix($importer->first);
 
 	like $record->{test}, qr/^XXX$/, q|fix: marc_set('100x','XXX');|;
@@ -28,7 +28,7 @@ like $record->{leader}, qr/^XXX/, q|fix: marc_set('LDR/0-3','XXX');|;
 #---
 {
 	$fixer = Catmandu::Fix->new(fixes => [q|marc_set('100[1]a','XXX')|,q|marc_map('100a','test')|]);
-	$importer = Catmandu::Importer::MARC->new( file => 't/camel.usmarc', type => "USMARC" );
+	$importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
 	$record = $fixer->fix($importer->first);
 
 	like $record->{test}, qr/^XXX$/, q|fix: marc_set('100[1]a','XXX');|;
@@ -41,7 +41,7 @@ like $record->{leader}, qr/^XXX/, q|fix: marc_set('LDR/0-3','XXX');|;
 		q|marc_set('100[1]a','$.my.deep.field')|,
 		q|marc_map('100a','test')|
 	]);
-	$importer = Catmandu::Importer::MARC->new( file => 't/camel.usmarc', type => "USMARC" );
+	$importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
 	$record = $fixer->fix($importer->first);
 
 	like $record->{test}, qr/^XXX$/, q|fix: marc_set('100[1]a','$.my.deep.field'');|;
diff --git a/t/16-marc-each.t b/t/16-marc-each.t
index 90659d4..6ca2460 100644
--- a/t/16-marc-each.t
+++ b/t/16-marc-each.t
@@ -33,7 +33,7 @@ my $fixer = Catmandu::Fix->new(fixes => [q|
 	marc_map("245",title)
 |]);
 
-my $importer = Catmandu::Importer::MARC->new( file => 't/camel.usmarc', type => "USMARC" );
+my $importer = Catmandu::Importer::MARC->new( file => 't/camel.mrc', type => "ISO" );
 
 $fixer->fix($importer)->each(sub {
 	my $record = $_[0];
diff --git a/t/19-io-string.t b/t/19-io-string.t
index e6fb960..a791387 100644
--- a/t/19-io-string.t
+++ b/t/19-io-string.t
@@ -11,7 +11,7 @@ my $data = join("",<DATA>);
 
 my $importer = Catmandu::Importer::MARC->new(
     file => \$data,
-    type => "USMARC"
+    type => "ISO"
 );
 my $records = $importer->to_array();
 
diff --git a/t/99-deprecate.t b/t/99-deprecate.t
new file mode 100644
index 0000000..cc05143
--- /dev/null
+++ b/t/99-deprecate.t
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Warnings ':all';
+
+use Catmandu::Importer::MARC;
+use Catmandu::Exporter::MARC;
+
+# USMARC as alias for ISO
+my $importer;
+like( warning { $importer = Catmandu::Importer::MARC->new( file => "t/camel.mrc", type => "USMARC" ) }, qr/is deprecated/i, 'deprecation warning importer');
+ok($importer, "create importer USMARC");
+my $records = $importer->to_array();
+ok( @$records == 10, "import records" );
+
+my $xml = '';
+my $exporter;
+like( warning { $exporter = Catmandu::Exporter::MARC->new( file => \$xml, type => "USMARC" ) }, qr/is deprecated/i, 'deprecation warning exporter');
+ok($exporter, "create exporter USMARC");
+$exporter->add({
+  _id => '1' ,
+  record => [
+            ['001', undef, undef, '_', 'rec001'],
+            ['100', ' ', ' ', 'a', 'Davis, Miles' , 'c' , 'Test'],
+        ]
+});
+ok($xml =~ /^00080     2200049   4500001000700000100002300007
rec001
  aDavis, MilescTest

$/, "export records");
+
+done_testing();
\ No newline at end of file
diff --git a/t/camel.usmarc b/t/camel.mrc
similarity index 100%
rename from t/camel.usmarc
rename to t/camel.mrc

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-marc-perl.git



More information about the Pkg-perl-cvs-commits mailing list