All OO in Perl is done through packages. As all the errors in the Error paradigm are objects, you're going to have to use packages. *shrugs*
Personally, most of my packages look like:
package MyErrors::SomeError;
use Error::Simple;
@ISA = qw(Error::Simple);
1;
(Yes, I know there's no strict, warnings, or whatever. With something this simple, I tend to skip those things.)
Then, when you want to use it, you can just catch that error.
The really neat thing about doing this is that you can create classes of errors. Let's say you have 10 errors that can arise from a database action. Instead of having to handle each one, you can have a base class of MyError::Database and have all your DB errors use it as the base class. MyError::Database would inherit from Error::Simple, thus allowing you to handle all your errors in one place, if you wanted.
That kind of hierarchy is one of the huge benefits of OO, allowing you to specify where in the hierarchy you want to work in.
------ We are the carpenters and bricklayers of the Information Age. The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6 Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified. |