Skip to content

Commit

Permalink
Making internal mapping functions to instance functions
Browse files Browse the repository at this point in the history
  • Loading branch information
phochste committed Jul 8, 2016
1 parent d95a5f1 commit cc33d21
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/Inline/marc_add.pm
Expand Up @@ -11,7 +11,7 @@ our $VERSION = '0.219';

sub marc_add {
my ($data,$marc_path,@subfields) = @_;
return Catmandu::MARC::marc_add($data, $marc_path, @subfields);
return Catmandu::MARC->new->marc_add($data, $marc_path, @subfields);
}

=head1 NAME
Expand Down
3 changes: 2 additions & 1 deletion lib/Catmandu/Fix/Inline/marc_map.pm
Expand Up @@ -69,8 +69,9 @@ our $VERSION = '0.219';

sub marc_map {
my ($data,$marc_path,%opts) = @_;
# Set default to nested_arrays for backwards compatibility
$opts{'-nested_arrays'} = 1 unless exists $opts{'-nested_arrays'};
return Catmandu::MARC::marc_map($data,$marc_path,%opts);
return Catmandu::MARC->new->marc_map($data,$marc_path,%opts);
}

1;
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/Inline/marc_remove.pm
Expand Up @@ -11,7 +11,7 @@ our $VERSION = '0.219';

sub marc_remove {
my ($data,$marc_path) = @_;
return Catmandu::MARC::marc_remove($data,$marc_path);
return Catmandu::MARC->new->marc_remove($data,$marc_path);
}

=head1 NAME
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/Inline/marc_set.pm
Expand Up @@ -11,7 +11,7 @@ our $VERSION = '0.219';

sub marc_set {
my ($data,$marc_path,$value) = @_;
return Catmandu::MARC::marc_set($data,$marc_path,$value);
return Catmandu::MARC->new->marc_set($data,$marc_path,$value);
}

=head1 NAME
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/marc_add.pm
Expand Up @@ -17,7 +17,7 @@ sub fix {
my $marc_path = $self->marc_path;
my @subfields = @{$self->subfields};

return Catmandu::MARC::marc_add($data,$marc_path,@subfields);
return Catmandu::MARC->new->marc_add($data,$marc_path,@subfields);
}

=head1 NAME
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/marc_decode_dollar_subfields.pm
Expand Up @@ -14,7 +14,7 @@ has record => (fix_opt => 1);
sub fix {
my ($self,$data) = @_;
my $record_key = $self->record // 'record';
return Catmandu::MARC::marc_decode_dollar_subfields($data, record => $record_key);
return Catmandu::MARC->new->marc_decode_dollar_subfields($data, record => $record_key);
}

=head1 NAME
Expand Down
4 changes: 2 additions & 2 deletions lib/Catmandu/Fix/marc_in_json.pm
Expand Up @@ -20,10 +20,10 @@ sub fix {
my $record_key = $self->record // 'record';

if ($self->reverse) {
return Catmandu::MARC::marc_json_to_record($data, record => $record_key);
return Catmandu::MARC->new->marc_json_to_record($data, record => $record_key);
}
else {
return Catmandu::MARC::marc_record_to_json($data, record => $record_key);
return Catmandu::MARC->new->marc_record_to_json($data, record => $record_key);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/marc_map.pm
Expand Up @@ -35,7 +35,7 @@ sub emit {
my $result = $fixer->generate_var;

my $perl =<<EOF;
if (my ${result} = Catmandu::MARC::marc_map(
if (my ${result} = Catmandu::MARC->new->marc_map(
${var},
${marc_path},
-split => ${split_opt},
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/marc_remove.pm
Expand Up @@ -16,7 +16,7 @@ sub fix {
my ($self,$data) = @_;
my $marc_path = $self->marc_path;
my $record_key = $self->record // 'record';
return Catmandu::MARC::marc_remove($data, $marc_path, record => $record_key);
return Catmandu::MARC->new->marc_remove($data, $marc_path, record => $record_key);
}

=head1 NAME
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/marc_set.pm
Expand Up @@ -18,7 +18,7 @@ sub fix {
my $marc_path = $self->marc_path;
my $value = $self->value;
my $record_key = $self->record;
return Catmandu::MARC::marc_set($data,$marc_path,$value, record => $record_key);
return Catmandu::MARC->new->marc_set($data,$marc_path,$value, record => $record_key);
}

=head1 NAME
Expand Down
2 changes: 1 addition & 1 deletion lib/Catmandu/Fix/marc_xml.pm
Expand Up @@ -14,7 +14,7 @@ has path => (fix_arg => 1);
# Transform a raw MARC array into MARCXML
sub fix {
my ($self, $data) = @_;
my $xml = Catmandu::MARC::marc_xml($data);
my $xml = Catmandu::MARC->new->marc_xml($data);
$data->{$self->path} = $xml;
$data;
}
Expand Down
21 changes: 12 additions & 9 deletions lib/Catmandu/MARC.pm
Expand Up @@ -5,13 +5,16 @@ use Catmandu::Util;
use Catmandu::Exporter::MARC::XML;
use Memoize;
use Carp;
use Moo;

memoize('_compile_marc_path');
#memoize('_compile_marc_path');

our $VERSION = '0.219';

warn 'here';

sub marc_map {
my ($data,$marc_path,%opts) = @_;
my ($self,$data,$marc_path,%opts) = @_;
my $record_key = $opts{record} // 'record';

return undef unless exists $data->{$record_key};
Expand Down Expand Up @@ -140,7 +143,7 @@ sub _extract_subfields {


sub marc_add {
my ($data,$marc_path,@subfields) = @_;
my ($self,$data,$marc_path,@subfields) = @_;

my %subfields = @subfields;
my $record_key = $subfields{'-record'} // 'record';
Expand Down Expand Up @@ -190,7 +193,7 @@ sub marc_add {
}

sub marc_set {
my ($data,$marc_path,$value,%opts) = @_;
my ($self,$data,$marc_path,$value,%opts) = @_;
my $record_key = $opts{record} // 'record';
my $record = $data->{$record_key};

Expand Down Expand Up @@ -237,7 +240,7 @@ sub marc_set {
}

sub marc_remove {
my ($data, $marc_path,%opts) = @_;
my ($self,$data, $marc_path,%opts) = @_;
my $record_key = $opts{record} // 'record';
my $record = $data->{$record_key};

Expand Down Expand Up @@ -287,7 +290,7 @@ sub marc_remove {
}

sub marc_xml {
my ($data) = @_;
my ($self,$data) = @_;

my $xml;
my $exporter = Catmandu::Exporter::MARC::XML->new(file => \$xml , xml_declaration => 0 , collection => 0);
Expand All @@ -298,7 +301,7 @@ sub marc_xml {
}

sub marc_record_to_json {
my ($data,%opts) = @_;
my ($self,$data,%opts) = @_;
my $record_key = $opts{record} // 'record';

if (my $marc = delete $data->{$record_key}) {
Expand Down Expand Up @@ -331,7 +334,7 @@ sub marc_record_to_json {
}

sub marc_json_to_record {
my ($data,%opts) = @_;
my ($self,$data,%opts) = @_;
my $record_key = $opts{record} // 'record';

my $record = [];
Expand Down Expand Up @@ -380,7 +383,7 @@ sub marc_json_to_record {
}

sub marc_decode_dollar_subfields {
my ($data,%opts) = @_;
my ($self,$data,%opts) = @_;
my $record_key = $opts{record} // 'record';
my $old_record = $data->{$record_key};
my $new_record = [];
Expand Down

0 comments on commit cc33d21

Please sign in to comment.