Skip to content

Commit

Permalink
a bit more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Jun 26, 2009
1 parent bb7fb5a commit 72c6fdb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
40 changes: 38 additions & 2 deletions lib/Throwable.pm
@@ -1,14 +1,50 @@
package Throwable;
use Moose::Role;
# ABSTRACT: a role for classes that can be thrown

=head1 SYNOPSIS
package Redirect;
use Moose;
with 'Throwable';
has url => (is => 'ro');
...then later...
Redirect->throw({ url => $url });
=head1 DESCRIPTION
Throwable is a role for classes that are meant to be thrown as exceptions to
standard program flow. It is very simple and does only two things: saves any
previous value for C<$@> and calls C<die $self>.
=attr previous_exception
This attribute is created automatically, and stores the value of C<$@> when the
Throwable object is created.
=cut

has 'previous_exception' => (
is => 'ro',
default => sub {
is => 'ro',
init_arg => undef,
default => sub {
return unless defined $@ and ref $@ or length $@;
return $@;
},
);

=method throw
Something::Throwable->throw({ attr => $value });
This method will call new, passing all arguments along to new, and will then
use the created object as the only argument to C<die>.
=cut

sub throw {
my ($self, @rest) = @_;
my $throwable = $self->new(@rest);
Expand Down
1 change: 1 addition & 0 deletions lib/Throwable/Error.pm
@@ -1,6 +1,7 @@
package Throwable::Error;
use Moose;
with 'Throwable';
# ABSTRACT: an easy-to-use class for error objects

use overload
q{""} => 'as_string',
Expand Down

0 comments on commit 72c6fdb

Please sign in to comment.