Skip to content

Commit

Permalink
add fix include
Browse files Browse the repository at this point in the history
  • Loading branch information
njfranck committed Jul 13, 2015
1 parent 8ac4f54 commit 36802da
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/Catmandu/Fix/include.pm
@@ -0,0 +1,38 @@
package Catmandu::Fix::include;

use Catmandu::Sane;
use Moo;
use Catmandu::Fix;
use Catmandu::Fix::Has;

has path => (fix_arg => 1);
has _fixer => (
is => 'ro',
lazy => 1,
builder => sub {
Catmandu::Fix->new(
fixes => [ $_[0]->path() ]
);
}
);

sub fix {
my ($self,$data) = @_;
$self->_fixer()->fix($data);
}

=head1 NAME
Catmandu::Fix::include - include fixes from another file
=head1 SYNOPSIS
include('/path/to/myfixes.txt')
=head1 SEE ALSO
L<Catmandu::Fix>
=cut

1;
28 changes: 28 additions & 0 deletions t/Catmandu-Fix-include.t
@@ -0,0 +1,28 @@
#!/usr/bin/env perl

use strict;
use warnings;
use Test::More;
use Test::Exception;

my $pkg;
BEGIN {
$pkg = 'Catmandu::Fix::include';
use_ok $pkg;
}

my $object = {};
my $intended_object = {
name => "Franck",
first_name => "Nicolas",
working_place => "University Library of Ghent"
};
my $fix_file = "t/fix-level-1.txt";

is_deeply(
$pkg->new($fix_file)->fix($object),
$intended_object,
"include fix at multiple levels"
);

done_testing 2;
5 changes: 5 additions & 0 deletions t/fix-level-1.txt
@@ -0,0 +1,5 @@
#fixes-level-1
add_field('name','Franck')
add_field('first_name','Nicolas')

include('t/fix-level-2.txt')
1 change: 1 addition & 0 deletions t/fix-level-2.txt
@@ -0,0 +1 @@
add_field('working_place','University Library of Ghent')

0 comments on commit 36802da

Please sign in to comment.