LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
176 stars 31 forks source link

Allow arbitrary code as fixes #107

Closed nichtich closed 9 years ago

nichtich commented 9 years ago

Catmandu::Fixable only supports instances of Catmandu::Fix, so one has to create a new Fix for any code that fixes items:

{ 
    package MyFix;
    use parent 'Catmandu::Fix';
     sub fix {
          my ($self, $data) = @_;
          $data->{my} = "something";
          $data;
    }
}
my $myfix = MyFix->new(fixes => []);
exporter('YAML', fix => $myfix);

This should be easier, e.g.

my $myfix = sub { $_[0]->{my} = "something"; $_[0] };
exporter('YAML', fix => ['Code', code => $myfix ] );
exporter('YAML', fix => $myfix ); # short form
nichtich commented 9 years ago

Implemented in the dev branch.

vpeil commented 9 years ago

released in 0.9207