Skip to content

Commit

Permalink
pica_match second argument optional
Browse files Browse the repository at this point in the history
  • Loading branch information
cKlee committed Feb 8, 2018
1 parent 76694d7 commit a12ac1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Catmandu/Fix/Condition/pica_match.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Catmandu::Fix::Has;
with 'Catmandu::Fix::Condition';

has pica_path => (fix_arg => 1);
has value => (fix_arg => 1);
has value => (fix_arg => 1, default => sub {'.*'});

sub emit {
my ($self,$fixer,$label) = @_;
Expand Down Expand Up @@ -50,6 +50,13 @@ Catmandu::Fix::Condition::pica_match - Conditionals on PICA fields
add_field('my.funny.title','true')
end
# pica_match(PICA_PATH)
# checks weather a field exists
if pica_match('001U0')
add_field('my.encode_info','true')
end
=head1 DESCRIPTION
Read our Wiki pages at L<https://github.com/LibreCat/Catmandu/wiki/Fixes>
Expand Down
10 changes: 10 additions & 0 deletions t/07-pica-each.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ my $fixer = Catmandu::Fix->new(fixes => [q|
if pica_match("010@a",'ger')
add_field(is_ger,true)
end
if pica_match("001U0")
add_field(has_encoding,true)
end
if pica_match("001Ua")
add_field(is_bogus,true)
end
end
|]);



my $importer = Catmandu::Importer::PICA->new( file => './t/files/picaplus.dat', type => "PLUS" );
my $record = $fixer->fix($importer->first);

ok exists $record->{record}, 'created a PICA record';
is $record->{is_ger}, 'true', 'created is_ger tag';
is $record->{has_encoding}, 'true', 'created has_encoding tag';
isnt $record->{is_bogus}, 'true', 'not created is_bogus tag';

done_testing;

0 comments on commit a12ac1d

Please sign in to comment.