NAME
Data::Walk::Graft - A way to say what should be added
SYNOPSIS
#! C:/Perl/bin/perl
use Modern::Perl;
use Moose::Util qw( with_traits );
use Data::Walk::Extracted v0.007;
use Data::Walk::Graft v0.001;
use Data::Walk::Print v0.007;
my $gardener = with_traits(
'Data::Walk::Extracted',
(
'Data::Walk::Graft',
'Data::Walk::Print'
)
)->new();
my $tree_ref = {
Helping =>{
KeyTwo => 'A New Value',
KeyThree => 'Another Value',
OtherKey => 'Something',
},
MyArray =>[
'ValueOne',
'ValueTwo',
'ValueThree',
],
};
$gardener->graft_data(
scion_ref =>{
Helping =>{
OtherKey => 'Something',
},
MyArray =>[
'IGNORE',
{
AnotherKey => 'Chicken_Butt!',
},
'IGNORE',
'IGNORE',
'ValueFive',
],
},
tree_ref => $tree_ref,
);
$gardener->print_data( $tree_ref );
#######################################
# Output of SYNOPSIS
# 01 {
# 02 MyArray => [
# 03 'ValueOne',
# 04 {
# 05 AnotherKey => 'Chicken_Butt!',
# 06 },
# 07 'ValueThree',
# 08 ,
# 09 'ValueFive',
# 10 ],
# 11 Helping => {
# 12 OtherKey => 'Something',
# 13 KeyTwo => 'A New Value',
# 14 KeyThree => 'Another Value',
# 15 },
# 16 },
#######################################
DESCRIPTION
This Moose::Role contains methods for implementing the method "graft_data" using Data::Walk::Extracted. Grafting is accomplished by sending a 'scion_ref' that has additions that need to be made to the 'tree_ref'.
v0.001
- State This code is still in Beta state and therefore is subject to change. I like the basics and will try to add rather than modify whenever possible in the future. The goal of future development will be focused on supporting additional branch types.
- Included ArrayRefs and HashRefs are supported nodes for grafting.
- Excluded Objects and CodeRefs are not currently handled and may cause the code to croak.
Use
One way to join this role with Data::Walk::Extracted is the method 'with_traits' from Moose::Util. Otherwise see Moose::Manual::Roles.
Attributes
Attributes in Data::Walk::Extracted
affect the output.
Methods
graft_data( %args )
- Definition: This will take a 'scion_ref' and use it to prune a 'tree_ref'. Where the 'scion_ref' matches the 'tree_ref' no changes are made. When the 'scion_ref' has something different than that portion of the 'tree_ref' then that portion of the 'scion_ref' replaces that portion of the 'tree_ref'. The word 'IGNORE' can be used for positions in array nodes that are effectivly don't care states for the 'scion_ref'. For example if you wish to change the third element of an array node then placing 'IGNORE' in the first two positions will cause "graft_data" to skip the analysis of those positions (This saves replacating deep references in an array position). If a 'scion_ref' adds a position past the end of an array then all the remaining positions in the 'tree_ref' will be undefined.
- Accepts: a hash ref with the keys 'scion_ref' and 'tree_ref'. The data_refs can contain array_ref nodes, hash_ref nodes, strings, and numbers. If no 'tree_ref' is passed then the 'scion_ref' is passed in it's entirety. If an array position in the 'scion_ref' containing is never evaluated (for example a replacment is done higher in the data tree) then the grafted tree will contain 'IGNORE' in that element of the array not undef. See "TODO" in Data::Walk::Extracted for future support.
- Returns: The $tree_ref with any changes
GLOBAL VARIABLES
- $ENV{Smart_Comments}
-
The module uses Smart::Comments with the '-ENV' option so setting the variable $ENV{Smart_Comments} will turn on smart comment reporting. There are three levels of 'Smartness' called in this module '### #### #####'. See the Smart::Comments documentation for more information.
SUPPORT
TODO
AUTHOR
COPYRIGHT
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
Dependancies
- Data::Walk::Extracted
- Carp
- version
- Moose::Role
- MooseX::Types::Moose
- Smart::Comments - With the -ENV variable set