| Test-Assert documentation | Contained in the Test-Assert distribution. |
Exception::Assertion - Thrown when assertion failed
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' );
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.
Declaration of class attributes as reference to hash.
See Exception::Base for details.
This class provides new attributes. See Exception::Base for other descriptions.
Contains the additional message filled by assertion method.
Contains the message of the exception. This class overrides the default value from Exception::Base class.
The default verbosity for assertion exception is raised to 3. This class overrides the default value from Exception::Base class.
Meta-attribute contains the format of string representation of exception object. This class overrides the default value from Exception::Base class.
Exception::Base, Test::Assertion.
Piotr Roszatycki <dexter@cpan.org>
Copyright (C) 2008, 2009 by Piotr Roszatycki <dexter@cpan.org>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Test-Assert documentation | Contained in the Test-Assert distribution. |
#!/usr/bin/perl -c package Exception::Assertion;
use 5.006; use strict; use warnings; our $VERSION = '0.0504';
# Extend Exception::Base class BEGIN {
my %ATTRS = ();
my @ATTRS_RW = ();
push @ATTRS_RW, 'reason';
$ATTRS{message} = 'Unknown assertion failed';
$ATTRS{verbosity} = 3;
$ATTRS{string_attributes} = [ 'message', 'reason' ];
use Exception::Base 0.21;
Exception::Base->import(
'Exception::Assertion' => {
has => { rw => \@ATTRS_RW },
%ATTRS,
},
);
};
1;