-
Notifications
You must be signed in to change notification settings - Fork 31
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
Showing
8 changed files
with
125 additions
and
7 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
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
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,53 @@ | ||
package Catmandu::Fix::library; | ||
|
||
use Moo; | ||
use namespace::clean; | ||
use Catmandu::Fix::Has; | ||
|
||
with 'Catmandu::Fix::Base'; | ||
|
||
has module => (fix_arg => 1); | ||
|
||
sub BUILD { | ||
my ($self, $args) = @_; | ||
|
||
my $pkg = Catmandu::Util::require_package($args->{module}); | ||
|
||
for my $module ($pkg->manifest) { | ||
$module =~ s{^$pkg\::}{}; | ||
my $orig = $pkg . '::' . $module; | ||
my $alias = 'Catmandu::Fix::' . $module; | ||
Catmandu::Util::alias_package($orig,$alias); | ||
} | ||
} | ||
|
||
sub emit { | ||
my ($self, $fixer, $label) = @_; | ||
"last ${label};"; | ||
} | ||
|
||
1; | ||
|
||
__END__ | ||
=pod | ||
=head1 NAME | ||
Catmandu::Fix::library - import fixes, conditions and binds from an external library | ||
=head1 SYNOPSIS | ||
# Import fixes methods from an external library | ||
library("foobar") | ||
# Use the methods from the 'foobar' library | ||
foobar_method1() | ||
foobar_method2() | ||
... | ||
=head1 SEE ALSO | ||
L<Catmandu::Fix> | ||
=cut |
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
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,29 @@ | ||
#!/usr/bin/env perl | ||
use lib 't/lib'; | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Test::Exception; | ||
use Catmandu; | ||
use utf8; | ||
|
||
my $pkg; | ||
|
||
BEGIN { | ||
$pkg = 'Catmandu::Fix::library'; | ||
use_ok $pkg; | ||
} | ||
|
||
{ | ||
is_deeply $pkg->new('T::Foo::Bar')->fix({}), {},"added an external fix method"; | ||
} | ||
|
||
{ | ||
my $fixer = Catmandu->fixer('library("T::Foo::Bar"); test(); if is_42(n) add_field(con,ok) end'); | ||
|
||
ok $fixer , 'got a fixer'; | ||
|
||
is_deeply $fixer->fix({n => '42'}) , { test => 'ok' , con => 'ok' , n => 42} , 'got the expected results'; | ||
} | ||
|
||
done_testing 4; |
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,11 @@ | ||
package T::Foo::Bar; | ||
use Moo; | ||
|
||
sub manifest { | ||
qw( | ||
T::Foo::Bar::test | ||
T::Foo::Bar::Condition::is_42 | ||
); | ||
} | ||
|
||
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,18 @@ | ||
package T::Foo::Bar::Condition::is_42; | ||
|
||
use Catmandu::Sane; | ||
|
||
use Moo; | ||
use namespace::clean; | ||
use Catmandu::Fix::Has; | ||
|
||
has path => (fix_arg => 1); | ||
|
||
with 'Catmandu::Fix::Condition::SimpleAllTest'; | ||
|
||
sub emit_test { | ||
my ($self, $var) = @_; | ||
"(${var} == 42)"; | ||
} | ||
|
||
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,12 @@ | ||
package T::Foo::Bar::test; | ||
use Moo; | ||
|
||
sub fix { | ||
my ($self,$data) = @_; | ||
|
||
$data->{test} = 'ok'; | ||
|
||
$data; | ||
} | ||
|
||
1; |