Data-Edit-Struct

 view release on metacpan or  search on metacpan

lib/Data/Edit/Struct.pm  view on Meta::CPAN

package Data::Edit::Struct;

# ABSTRACT: Edit a Perl structure addressed with a Data::DPath path

use strict;
use warnings;

use Exporter 'import';

our $VERSION = '0.07';

use Ref::Util qw[
  is_plain_arrayref is_arrayref
  is_plain_hashref  is_hashref
  is_scalarref is_ref is_coderef
];

use Types::Standard -types;
use Data::Edit::Struct::Types -types;

use custom::failures 'Data::Edit::Struct::failure' => [ qw{
      input::dest
      input::src
      input::param
      internal
      } ];

use List::Util qw[ pairmap ];
use Scalar::Util qw[ refaddr ];
use Params::ValidationCompiler qw[ validation_for ];
use Safe::Isa;

use Data::DPath qw[ dpath dpathr dpathi ];

## no critic(ProhibitSubroutinePrototypes)

# uncomment to run coverage tests, as Safe compartment makes
# Devel::Cover whimper
#
# $Data::DPath::USE_SAFE = 0;

our @EXPORT_OK = qw[ edit ];

#---------------------------------------------------------------------

# Params::ValidationCompiler is used to validate the arguments passed
# to the edit subroutine.  These hashes are used to codify validation
# specifications which are used multiple times.

my %dest = (
    dest  => { type => Context },
    dpath => { type => Str, default => '/' },
);

my %dtype = ( dtype => { type => UseDataAs, default => 'auto' }, );

my %source = (
    src   => { type => Any,       optional => 1 },
    spath => { type => Str,       optional => 1 },
    stype => { type => UseDataAs, default  => 'auto' },
    sxfrm => {
        # ( Enum [] ) | CoderRef rather than Enum[] | CodeRef for
        # Perl < 5.14
        type    => ( Enum [ 'iterate', 'array', 'hash', 'error' ] ) | CodeRef,
        default => 'error'
    },
    sxfrm_args => {
        type    => HashRef,
        default => sub { {} },
    },
    clone => {
        type    => Bool | CodeRef,



( run in 4.031 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )