Why not adopt me?
NAME
Data::Handle::Exception - Super-light Weight Dependency Free Exception base.
VERSION
version 0.01011421
SYNOPSIS
use Data::Handle::Exception;
Data::Handle::Exception->generate_exception(
'Foo::Bar' => 'A Bar error occurred :('
)->throw();
DESCRIPTION
Data::Handle's primary goal is to be somewhat "Infrastructural" in design, much like Package::Stash is, being very low-level, and doing one thing, and doing it well, solving an issue with Perl's native implementation.
The idea is for more complex things to use this, instead of this using more complex things.
As such, a dependency on something like Moose would be overkill, possibly even detrimental to encouraging the use of this module.
So we've scrimped and gone really cheap ( for now at least ) in a few places to skip adding downstream dependencies, so this module is a really really nasty but reasonably straight forward exception class.
The actual Exception classes don't actually have their own sources, they're automatically generated when Data::Handle::Exception is loaded. And we have some really nice backtraces stolen from Carp's code, with some sexy coloured formatting. See L/stringify> for details.
METHODS
new
my @stack;
my $i = Data::Handle::Exception->new( $messageString, \@stack );
throw
Data::Handle::Exception->new( $messageString, \@stack )->throw();
stringify
Turns this stacktrace into a string.
$exception->stringify();
my $str = "hello " . $exception . " world";
If you have a coloured terminal, then Term::ANSIColor is used to highlight lines based on how likely they are to be relevant to diagnosis.
- Green - From Data::Handle and is likely to be "safe", its where the error is being reported from, so its useful informationally, but the problem is probably elsewhere.
- Yellow - Sources we're confident its unlikely to be a source of problems, currently
- White - Everything Else, the place the problem is most likely to be.
generate_exception
my $i = Data::Handle::Exception->generate_exception(
'Foo::Bar' => 'SomeMessage'
);
# $i isa Data::Handle::Exception::Foo::Bar
# Data::Handle::Exception::Foo::Bar isa
# Data::Handle::Exception::Foo
#
# Data::Handle::Exception::Foo isa
# Data::Handle::Exception
#
# $i has a message and a stack-trace
#
$i->throw():
AUTHOR
Kent Fredric <kentnl@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Kent Fredric <kentnl@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.