NAME

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

SYNOPSIS

#! C:/Perl/bin/perl
use Modern::Perl;
use Moose::Util qw( with_traits );
$| = 1;
use Data::Walk::Extracted v0.007;
use Data::Walk::Prune v0.003;
use Data::Walk::Print v0.007;

my  $newclass = with_traits( 'Data::Walk::Extracted', ( 'Data::Walk::Prune', 'Data::Walk::Print' ) );
my  $edward_scissorhands = $newclass->new( change_array_size => 1, );#Default
my  $firstref = {
        Helping => [
            'Somelevel',
            {
                MyKey => {
                    MiddleKey => {
                        LowerKey1 => 'low_value1',
                        LowerKey2 => {
                            BottomKey1 => 'bvalue1',
                            BottomKey2 => 'bvalue2',
                        },
                    },
                },
            },
        ],
    };
$edward_scissorhands->prune_data(
        tree_ref    => $firstref, 
        slice_ref   => {
            Helping => [
                {
                    MyKey => {
                        MiddleKey => {
                            LowerKey1 => {},
                        },
                    },
                },
            ],
        },
    );
$edward_scissorhands->print_data( $firstref );

#######################################
#     Output of SYNOPSIS
# 01 {
# 02 	Helping => [
# 03 		'Somelevel',
# 04 		{
# 05 			MyKey => {
# 06 				MiddleKey => {
# 07 					LowerKey2 => {
# 08 						BottomKey1 => 'bvalue1',
# 09 						BottomKey2 => 'bvalue2',
# 10 					},
# 11 					LowerKey1 => 'low_value1',
# 12 				},
# 13 			},
# 14 		},
# 15 	],
# 16 },
#######################################

DESCRIPTION

This Moose::Role contains methods for implementing the method "prune_data" using Data::Walk::Extracted. By sending a 'slice_ref' that terminates in an empty hash_ref (no keys) or an empty array_ref (no positions) for the relevant data node reference type then the 'tree_ref' will be pruned at that spot. "prune_data" returns the resulting 'tree_ref' after pruning.

v0.003

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 pruning.
Excluded Objects and CodeRefs are not currently handled and may cause the code to croak.

Use

One way to incorporate this role into Data::Walk::Extracted and then use it is the method 'with_traits' from Moose::Util. Otherwise see Moose::Manual::Roles.

Attributes

Attributes in Data::Walk::Extracted

affect the output.

Methods

prune_data( %args )

Definition: This will take a 'slice_ref' and use it to prune a 'tree_ref'. The code looks for empty hash refs or array refs to show where to cut. If a key has an empty ref value then the key is deleted. If the array position has an empty ref then the array position is deleted/cleared
Accepts: a hash ref with the keys 'slice_ref' and 'tree_ref' (both required). The data_refs can contain array_ref nodes, hash_ref nodes, strings, and numbers. 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

github Data-Walk-Extracted/issues

TODO

Support pruning through CodeRef nodes
Support pruning through Objects / Instances nodes

AUTHOR

jandrew@cpan.org

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

SEE ALSO

Data::Walk
Data::Walker
Data::ModeMerge