| 1 | package CallBackery::Exception; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | CallBackery::Exception - a simple exception class | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use CallBackery::Exception qw(mkerror); | ||
| 10 | |||
| 11 | eval { die error(22,'Bad Error'); } | ||
| 12 | if ($@){ | ||
| 13 | print "Code: '.$@->code()." Message: ".$@->message()."\n" | ||
| 14 | print "$@\n"; #stringified error | ||
| 15 | } | ||
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | An error object. | ||
| 20 | |||
| 21 | Maybe use L<Mojo::Exception> instead. | ||
| 22 | |||
| 23 | =over | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | 19 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 28 | 19 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | |||
| 30 | 19 | ▶ | use Exporter 'import'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 31 | 19 | ▶ | use vars qw(@EXPORT_OK); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 32 | 19 | @EXPORT_OK = qw(mkerror); | |
| 33 | |||
| 34 | 19 | ▶ | use overload ('""' => 'stringify'); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 35 | |||
| 36 | |||
| 37 | 19 | ▶ | use Mojo::Base -base; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 38 | 19 | has 'code'; | |
| 39 | 19 | has 'message'; | |
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | =item B<mkerror>(I<code>,I<message>) | ||
| 44 | |||
| 45 | Create an nq::Exception object, setting code and message properties in the process. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | 12 | ▶ | sub mkerror { |
|
Subroutine
mkerror: called CC=1 SCAR=0.0
Pod
documented
| |||
| 50 | 12 | my $code = shift; | |
| 51 | 12 | my $message = shift; | |
| 52 | # use caller() to determin where this is happening | ||
| 53 | # somehow construct the error code from the line number ....?? | ||
| 54 | 12 | return (__PACKAGE__->new(code=>$code,message=>$message)); | |
| 55 | } | ||
| 56 | |||
| 57 | =item B<stringify> | ||
| 58 | |||
| 59 | error stringification handler | ||
| 60 | |||
| 61 | =cut | ||
| 62 | |||
| 63 | 15 | ▶ | sub stringify { |
|
Subroutine
stringify: called CC=1 SCAR=0.0
Pod
documented
| |||
| 64 | 15 | my $self = shift; | |
| 65 | 15 | return "ERROR ".$self->code().": ".$self->message()."\n"; | |
| 66 | } | ||
| 67 | |||
| 68 | 19 | 1; | |
| 69 | __END__ | ||