Badger
view release on metacpan or search on metacpan
lib/Badger/Base.pm view on Meta::CPAN
use Some::Other::Exception;
our $EXCEPTION = 'Some::Other::Exception';
=head2 fatal($info, $more_info, ...)
This method is used internally to raise a fatal error. It bypasses the
normal error reporting mechanism and dies with a stack backtrace by calling
C<confess()> (see L<Carp>).
The most common reason for a fatal error being raised is calling the
L<message()> method (or either of the L<error_msg()> or L<decline_msg()>
wrapper methods) with a message format that doesn't exist. The stack backtrace
will tell you where in your code you're making the call so you can easily find
and fix it.
=head2 not_implemented($what)
A method of convenience which raises an error indicating that the method
isn't implemented
sub example_method {
shift->not_implemented;
}
Calling the C<example_method()> would result in an error message similar
to this (shown here split across two lines):
your.badger.module error - example_method() is not implemented
for Your::Badger::Module in /path/to/your/script.pl at line 42
Note that it tells you where the C<example_method()> was called from,
not where the method is defined.
The C<not_implemented()> method is typically used in methods defined in a base
classes that subclasses are expected to re-define (a.k.a. pure virtual methods
or abstract methods).
You can pass an argument to be more specific about what it is that
isn't implemented.
sub example_method {
shift->not_implemented('in base class');
}
The argument is added to the generated error message following the
method name. A single space is also added to separate them.
your.badger.module error - example_method() is not implemented in
base class for Your::Badger::Module in ...etc...
=head2 todo($what)
A method of convenience useful during developing to indicate that a method
isn't implemented yet. It raises an error stating that the method is
still TODO.
sub not_yet_working {
shift->todo;
}
The error message generated looks something like this:
your.badger.module error - not_yet_working() is TODO in
Your::Badger::Module at line 42
You can pass an argument to be more specific about what is still TODO.
sub not_yet_working {
my ($self, $x) = @_;
if (ref $x) {
$self->todo('support for references');
}
else {
# do something
}
}
The error message generated would then be:
your.badger.module error - not_yet_working() support for
references is TODO in Your::Badger::Module at line 42
=head2 debug($msg1,$msg2,...)
This method is mixed in from the L<Badger::Debug> module. It provides a simple
way of generating debugging messages which include the source module and line
number where the message was generated.
sub example {
my $self = shift;
$self->debug('entered example()');
# ... some code ...
$self->debug('leaving example()');
}
=head2 debug_msg($message, @args)
This is a wrapper around the L<debug()> and L<message()> methods,
similar to L<warn_msg()>, L<error_msg()> and friends.
our $MESSAGES = {
here => 'You are in %s',
};
sub example {
my $self = shift;
$self->debug_msg(
here => 'a maze of twisty little passages, all alike'
) if DEBUG;
# ... some code ...
$self->debug_msg(
here => 'boat, floating on a sea of purest green'
) if DEBUG;
}
=head2 debug_up($level,$msg1,$msg2,...)
Another debugging method mixed in from L<Badger::Debug>. This is a wrapper
( run in 0.569 second using v1.01-cache-2.11-cpan-364913b4093 )