
Data::Transformator - transform nested Perl data structures.

From one of the test cases:
use Data::Transformator;
my $tree
= {
e => [
{
e1 => {
},
},
{
e2 => {
},
},
{
e3 => {
},
},
],
};
my $expected_data
= {
e => [
{
e1 => {
},
},
],
};
my $transformation
= Data::Transformator->new
(
name => 'test_transform3',
contents => $tree,
apply_identity_transformation => {
e => [
1,
],
},
);
my $transformed_data = $transformation->transform();
use Data::Comparator qw(data_comparator);
my $differences = data_comparator($transformed_data, $expected_data);
if ($differences->is_empty())
{
print "$0: 3: success\n";
ok(1, '3: success');
}
else
{
print "$0: 3: failed\n";
ok(0, '3: failed');
}

Data::Transformator allows to transform a nested perl data structure -- the source data -- in a new nested perl data structure -- the result data. The source nested data structure can contain perl hashes, arrays and scalars, but should not be self-referential (if I remember well, the existing protection against self-referential data structures in the transformator engine is currently broken).

Running a transformation can be done in two essentially different ways:
It is possible to combine the two above in a single run, but that is currently not tested enough to be sure it works alright, so be very careful with that.
To use Data::Transformator, you have to
Following keys are available to the constructor of Data::Transformator:
Is an array of simple_transformators. Each simple_transformator is a hash with a 'matcher' key that contains a regular expression that is matched with the path of the currently selected element. If there is a match, the selected subtree is put in the end result, under the value of the 'key' element of the simple_transformator (creating a hash in the result if necessary). If there is no 'key' element in the simple_transformator, a 'code' element is looked for, which is a code reference. The code is called to insert an appropriate result.
Is an array of transformators. Each transformator is code reference that gets called as usual.
Contains a nested perl data structure that reflects the structure of the source data. All data of the source that is selected by scalars that evaluate to true in the content of apply_identity_transformation, is inserted in the result. This key is very handy for selecting a set of small portions of data, if the structure of the source is known beforehand.
Take a look at existing examples, e.g. in the unit tests of the transformation engine.

There is a small transformation library embedded in the Data::Transformator. This library currently allows to
The library generates closures that work on the source data.

For the interested reader, please follow these reasoning steps:

Does only work with scalars, hashes and arrays. Support for self-referential structures seems broken at the moment.

Hugo Cornelis, hugo.cornelis@gmail.com
Copyright 2007 Hugo Cornelis.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Data::Merger(3), Data::Comparator(3), Clone(3)