<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Specio::Exception;

use strict;
use warnings;

use overload
    q{""}    =&gt; 'as_string',
    fallback =&gt; 1;

our $VERSION = '0.42';

use Devel::StackTrace;
use Scalar::Util qw( blessed );
use Specio::OO;

{
    my $attrs = {
        message =&gt; {
            isa      =&gt; 'Str',
            required =&gt; 1,
        },
        type =&gt; {
            does     =&gt; 'Specio::Constraint::Role::Interface',
            required =&gt; 1,
        },
        value =&gt; {
            required =&gt; 1,
        },
        stack_trace =&gt; {
            init_arg =&gt; undef,
        },
    };

    ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
    sub _attrs {
        return $attrs;
    }
}

sub BUILD {
    my $self = shift;

    $self-&gt;{stack_trace}
        = Devel::StackTrace-&gt;new( ignore_package =&gt; __PACKAGE__ );

    return;
}

sub as_string {
    my $self = shift;

    my $str = $self-&gt;message;
    $str .= "\n\n" . $self-&gt;stack_trace-&gt;as_string;

    return $str;
}

sub throw {
    my $self = shift;

    die $self if blessed $self;

    die $self-&gt;new(@_);
}

__PACKAGE__-&gt;_ooify;

1;

# ABSTRACT: An exception class for type constraint failures

__END__

=pod

=encoding UTF-8

=head1 NAME

Specio::Exception - An exception class for type constraint failures

=head1 VERSION

version 0.42

=head1 SYNOPSIS

  use Try::Tiny;

  try {
      $type-&gt;validate_or_die($value);
  }
  catch {
      if ( $_-&gt;isa('Specio::Exception') ) {
          print $_-&gt;message, "\n";
          print $_-&gt;type-&gt;name, "\n";
          print $_-&gt;value, "\n";
      }
  };

=head1 DESCRIPTION

This exception class is thrown by Specio when a type check fails. It emulates
the L&lt;Throwable::Error&gt; API, but doesn't use that module to avoid adding a
dependency on L&lt;Moo&gt;.

=for Pod::Coverage BUILD throw

=head1 API

This class provides the following methods:

=head2 $exception-&gt;message

The error message associated with the exception.

=head2 $exception-&gt;stack_trace

A L&lt;Devel::StackTrace&gt; object for the exception.

=head2 $exception-&gt;type

The type constraint object against which the value failed.

=head2 $exception-&gt;value

The value that failed the type check.

=head2 $exception-&gt;as_string

The exception as a string. This includes the method and the stack trace.

=head1 OVERLOADING

This class overloads stringification to call the C&lt;as_string&gt; method.

=head1 SUPPORT

Bugs may be submitted at L&lt;https://github.com/houseabsolute/Specio/issues&gt;.

I am also usually active on IRC as 'autarch' on C&lt;irc://irc.perl.org&gt;.

=head1 SOURCE

The source code repository for Specio can be found at L&lt;https://github.com/houseabsolute/Specio&gt;.

=head1 AUTHOR

Dave Rolsky &lt;autarch@urth.org&gt;

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 - 2017 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)

The full text of the license can be found in the
F&lt;LICENSE&gt; file included with this distribution.

=cut
</pre></body></html>