Catmandu::Fix - a Catmandu class used for data crunching
use Catmandu::Fix; my $fixer = Catmandu::Fix->new(fixes => ['upcase("job")','remove_field("test")']); or my $fixer = Catmandu::Fix->new(fixes => ['fix_file.txt']); my $arr = $fixer->fix([ ... ]); my $hash = $fixer->fix({ ... }); my $it = Catmandu::Importer::YAML(file => '...'); $fixer->fix($it)->each(sub { ... });
Catmandu::Fix-es can be use for easy data manipulation by non programmers. Using a small Perl DSL language end-users can use Fix routines to manipulate data objects. A plain text file of fixes can be created to specify all the routines needed to tranform the data into the desired format.
All the Fix routines in Catmandu::Fix use a TT2 type reference to point to values in a Perl Hash. E.g. 'foo.2.bar' is a key 'bar' which is the 3-rd value of the key 'foo'.
A special case is when you want to point to all items in an array. In this case the wildcard '*' can be used. E.g. 'foo.*' points to all the items in the 'foo' array.
For array values there are special wildcards available:
* $append - Add a new item at the end of an array * $prepend - Add a new item at the start of an array * $first - Syntactic sugar for index '0' (the head of the array) * $last - Syntactic sugar for index '-1' (the tail of the array)
E.g.
# Create { mods => { titleInfo => [ { 'title' => 'a title' }] } }; add_field('mods.titleInfo.$append.title', 'a title'); # Create { mods => { titleInfo => [ { 'title' => 'a title' } , { 'title' => 'another title' }] } }; add_field('mods.titleInfo.$append.title', 'another title'); # Create { mods => { titleInfo => [ { 'title' => 'foo' } , { 'title' => 'another title' }] } }; add_field('mods.titleInfo.$first.title', 'foo'); # Create { mods => { titleInfo => [ { 'title' => 'foo' } , { 'title' => 'bar' }] } }; add_field('mods.titleInfo.$last.title', 'bar');
Create a new Catmandu::Fix which will execute every FIX into a consecutive order. A FIX can be the name of a Catmandu::Fix::* routine or the path to a plain text file containing all the fixes to be executed.
Execute all the fixes on a HASH. Returns the fixed HASH.
Execute all the fixes on every element in the ARRAY. Returns an ARRAY of fixes.
Execute all the fixes on every item in an Catmandu::Iterator. Returns a (lazy) iterator on all the fixes.
Executes all the fixes on a generator function. Returns a new generator with fixed data.
Return the current logger.
Catmandu::Fix::add_field
To install Catmandu, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catmandu
CPAN shell
perl -MCPAN -e shell install Catmandu
For more information on module installation, please visit the detailed CPAN module installation guide.