Exception::Assertion - Thrown when assertion failed


Test-Assert documentation  | view source Contained in the Test-Assert distribution.

Index


NAME

Top

Exception::Assertion - Thrown when assertion failed

SYNOPSIS

Top

  use Exception::Assertion;

  sub assert_foo {
      my $self = eval { $_[0]->isa(__PACKAGE__) } ? shift : __PACKAGE__;
      my ($condition, $message) = @_;
      Exception::Assertion->throw(
          message => $message,
          reason  => 'foo failed',
      ) unless $condition;
  }

  assert_foo( 0, 'assert_foo failed' );

DESCRIPTION

Top

This class extends standard Exception::Base and is thrown when assertion is failed. It contains additional attribute reason which represents detailed message about reason of failed assertion. The exception has also raised verbosity.

INHERITANCE

Top

CONSTANTS

Top

ATTRS : HashRef

Declaration of class attributes as reference to hash.

See Exception::Base for details.

ATTRIBUTES

Top

This class provides new attributes. See Exception::Base for other descriptions.

reason : Str

Contains the additional message filled by assertion method.

message : Str = "Unknown assertion failed"

Contains the message of the exception. This class overrides the default value from Exception::Base class.

verbosity : Int = 3

The default verbosity for assertion exception is raised to 3. This class overrides the default value from Exception::Base class.

string_attributes : ArrayRef[Str] = ["message", "reason"]

Meta-attribute contains the format of string representation of exception object. This class overrides the default value from Exception::Base class.

SEE ALSO

Top

Exception::Base, Test::Assertion.

AUTHOR

Top

Piotr Roszatycki <dexter@cpan.org>

COPYRIGHT

Top


Test-Assert documentation  | view source Contained in the Test-Assert distribution.