NAME

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

SYNOPSIS

#! C:/Perl/bin/perl
 use Modern::Perl;
 use YAML::Any;
 use Moose::Util qw( with_traits );
 use lib '../lib';

 $| = 1;

 use Data::Walk::Extracted v0.05;
 use Data::Walk::Prune v0.01;

 my  $newclass = with_traits( 'Data::Walk::Extracted', ( 'Data::Walk::Prune' ) );
 my  $edward_scissorhands = $newclass->new( splice_arrays => 1, );
 my  $firstref = Load(
         '---
         Helping:
             - Somelevel
             - MyKey:
                 MiddleKey:
                     LowerKey1: lvalue1
                     LowerKey2:
                         BottomKey1: bvalue1
                         BottomKey2: bvalue2'
     );
 $edward_scissorhands->prune(
         tree_ref    => $firstref, 
         slice_ref   => Load(
             '---
             Helping:
             - Somelevel
             - MyKey:
                 MiddleKey:
                     LowerKey1: []' 
         ),
     );
 say Dump( $firstref );
 
 #######################################
 #     Output of SYNOPSIS
 # 01 ---
 # 02 Helping:
 # 03 - Somelevel
 # 04 - MyKey:
 # 05     MiddleKey:
 # 06       LowerKey2:
 # 07         BottomKey1: bvalue1
 # 08         BottomKey2: bvalue2
 # 09     
 #######################################
 

DESCRIPTION

This Moose::Role contains methods for implementing the method "prune" using Data::Walk::Extracted. By sending a prune data 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.

The 'slice_ref' is passed to the 'primary_ref' in Data::Walk::Extracted and the 'tree_ref' is passed to the 'secondary_ref' in that class. All additional attributes and methods for the class work as described in the documentation.

v0.01

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

This is an object oriented Moose Role and generally behaves that way.

Attributes

Data passed to ->new when creating an instance using a class. 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 appenders as the top keys.

splice_arrays

Definition: when an array element is removed the position can remain as undef or be spliced out of the array. This flag will determine that behavior (1 = splice).
Default True (1)
Range This is a Boolean data type and generally accepts 1 or 0

Methods

change_splice_behavior( $bool )

Definition: this is a way to change the splice_arrays flag
Accepts: a Boolean value
Returns: 1

prune( $passed_ref )

Definition: This will take a "slice_ref" and use it to prune a "tree_ref"
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

BUGS

Data-Walk-Extracted/issues

TODO

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

SUPPORT

jandrew@cpan.org

AUTHOR

Jed Lund
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