| Eidolon documentation | Contained in the Eidolon distribution. |
Eidolon::Core::Exception::Builder - exception builder for Eidolon.
In one of your application files, for example lib/Example/Exceptions.pm
you can write:
use Eidolon::Core::Exception::Builder
(
"MyException" =>
{
"title" => "Something happened."
},
"MyException::Terrible" =>
{
"isa" => "MyException",
"title" => "Something terrble happened."
},
"MyException::Good" =>
{
"isa" => "MyException",
"title" => "Something good happened."
}
);
The Eidolon::Core::Exception::Builder class provides an easy way to create own exceptions. It has no methods that you should call - all work is done during package import.
Creates exception $class with $data settings. $data is a hashref,
containing inheritance information and exception message:
Exception base class.
Exception message.
If no isa information is specified, Eidolon::Core::Exception will be used as a base exception class.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Anton Belousov, <abel@cpan.org>
Copyright (c) 2009, Atma 7, http://www.atma7.com
| Eidolon documentation | Contained in the Eidolon distribution. |
package Eidolon::Core::Exception::Builder; # ============================================================================== # # Eidolon # Copyright (c) 2009, Atma 7 # --- # Eidolon/Core/Exception/Builder.pm - exception builder # # ============================================================================== use warnings; use strict; our $VERSION = "0.02"; # 2009-05-12 06:24:56 # ------------------------------------------------------------------------------ # import($class, $data) # create exceptions classes # ------------------------------------------------------------------------------ sub import { my ($self, $class, $data, $isa, $title, $code); $self = shift; while ($class = shift) { $data = ref $_[0] ? shift : {}; $isa = $data->{"isa"} || "Eidolon::Core::Exception"; $title = $data->{"title"}; # check if base class exists { no strict "refs"; die "Base class doesn't exist: $isa" if (!keys %{"$isa\::"}); } $code = "package $class;\nuse base qw/$isa/;\n"; $code .= "use constant TITLE => '$title';\n" if ($title); eval $code; } } 1; __END__