Data-Rx

 view release on metacpan or  search on metacpan

lib/Data/Rx/Failure.pm  view on Meta::CPAN

use v5.12.0;
use warnings;
package Data::Rx::Failure 0.200008;
# ABSTRACT: structured failure report from an Rx checker

#pod =head1 SYNOPSIS
#pod
#pod This is part of a L<Data::Rx::FailureSet>, which is what is thrown when a
#pod schema's C<assert_valid> method finds a problem with the input.  For more
#pod information on it, look at the documentation for L<Data::Rx>.
#pod
#pod =cut

use overload '""' => \&stringify;

sub new {
  my ($class, $arg) = @_;

  my $guts = {
    rx => $arg->{rx},
    struct => [ $arg->{struct} ],
  };

  bless $guts => $class;
}

sub struct { $_[0]->{struct} }

sub contextualize {
  my ($self, $struct) = @_;

  push @{ $self->struct }, $struct;

  if (my $failures = $self->struct->[0]{failures}) {
    $_->contextualize($struct) foreach @$failures;
  }

  return $self;
}

sub value {
  my ($self) = @_;

  return $self->struct->[0]{value};
}

sub error_types {
  my ($self) = @_;

  return @{ $self->struct->[0]{error} };
}

sub error_string {
  my ($self) = @_;

  join ', ', $self->error_types;
}

sub keys {
  my ($self) = @_;

  return @{ $self->struct->[0]{keys} || [] };
}

sub size {
  my ($self) = @_;

  return $self->struct->[0]{size};
}

sub data_path {
  my ($self) = @_;

  map {; map { $_->[0] } @{ $_->{data_path} || [] } }
    reverse @{ $self->struct };
}

sub data_string {
  my ($self) = @_;

  return $self->_path_string('$data', 'data_path');
}

sub check_path {

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.694 second using v1.00-cache-2.02-grep-82fe00e-cpan-f5108d614456 )