
Data::Walk::Prune - A way to say what should be removed

#!perl
use Modern::Perl;
use Moose::Util qw( with_traits );
use Data::Walk::Extracted 0.019;
use Data::Walk::Prune 0.011;
use Data::Walk::Print 0.015;
my $edward_scissorhands = with_traits(
'Data::Walk::Extracted',
(
'Data::Walk::Prune',
'Data::Walk::Print',
),
)->new( change_array_size => 1, );#Default
my $firstref = {
Helping => [
'Somelevel',
{
MyKey => {
MiddleKey => {
LowerKey1 => 'low_value1',
LowerKey2 => {
BottomKey1 => 'bvalue1',
BottomKey2 => 'bvalue2',
},
},
},
},
],
};
my $result = $edward_scissorhands->prune_data(
tree_ref => $firstref,
slice_ref => {
Helping => [
undef,
{
MyKey => {
MiddleKey => {
LowerKey1 => {},
},
},
},
],
},
);
$edward_scissorhands->print_data( $result );
######################################################################################
# Output of SYNOPSIS
# 01 {
# 02 Helping => [
# 03 'Somelevel',
# 04 {
# 05 MyKey => {
# 06 MiddleKey => {
# 07 LowerKey2 => {
# 08 BottomKey1 => 'bvalue1',
# 09 BottomKey2 => 'bvalue2',
# 10 },
# 12 },
# 13 },
# 14 },
# 15 ],
# 16 },
######################################################################################

This Moose::Role implements the method prune_data. It takes a tree_ref and a slice_ref and uses Data::Walk::Extracted. To remove portions of the 'tree_ref' defined by the 'slice_ref'. The cut points are defined by an empty hash_ref (no keys) or an empty array_ref (no positions). If the cut indicators are on a branch of the slice_ref that does not exist on the tree_ref then no cut takes place.
This is a Moose::Role. One way to incorporate this role into Data::Walk::Extracted. is MooseX::ShortCut::BuildInstance. or read Moose::Util for more class building information.

Data passed to ->new when creating an instance. For modification of these attributes see "Methods". The ->new function will either accept fat comma lists or a complete hash ref that has the possible attributes as the top keys. Additionally some attributes that have all the following methods; get_$attribute, set_$attribute, has_$attribute, and clear_$attribute, can be passed to prune_data and will be adjusted for just the run of that method call. These are called 'one shot' attributes.
Attributes in Data::Walk::Extracted - also affect the output.

$pruned_tree_ref = $self->prune_data(
tree_ref => $tree_data,
slice_ref => $slice_data,
prune_memory => 0,
);

Because this uses Data::Walk::Extracted the final $tree_ref is a deep cloned where the $slice_ref passed through.

The module uses Smart::Comments if the '-ENV' option is set. The 'use' is encapsulated in an if block triggered by an environmental variable to comfort non-believers. Setting the variable $ENV{Smart_Comments} in a BEGIN block will load and turn on smart comment reporting. There are three levels of 'Smartness' available in this module '###', '####', and '#####'.




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.

