Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
njfranck
committed
Jul 13, 2015
1 parent
8ac4f54
commit 36802da
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#fixes-level-1 | ||
add_field('name','Franck') | ||
add_field('first_name','Nicolas') | ||
|
||
include('t/fix-level-2.txt') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_field('working_place','University Library of Ghent') |