| 1 | package TryCatch::Error; | ||
| 2 | |||
| 3 | use MooseX::FollowPBP; | ||
| 4 | use Moose; | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | TryCatch::Error - A simple error base class. | ||
| 9 | |||
| 10 | =head1 VERSION | ||
| 11 | |||
| 12 | Version 0.01 | ||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | our $VERSION = '0.01'; | ||
| 17 | |||
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | This module provides a building block to writing your own error objects, to use with TryCatch (or some similar module). | ||
| 22 | |||
| 23 | It enables you to write things like this, straight away: | ||
| 24 | |||
| 25 | use TryCatch::Error; | ||
| 26 | use TryCatch; | ||
| 27 | |||
| 28 | try { | ||
| 29 | # ... | ||
| 30 | # something that can go horribly wrong | ||
| 31 | if ( $error_condition ) { | ||
| 32 | die TryCatch::Error->new( value => $foo, message => $bar ); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | catch ( TryCatch::Error $e ) { | ||
| 36 | print STDERR 'Ooops: ', $e->get_message, ' with ', $e->get_value; | ||
| 37 | } | ||
| 38 | |||
| 39 | TryCatch::Error can be sub-classed to create your own errors (possibly containing more detail, see t/03-subclassing.t for an example). | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | has 'value' => ( | ||
| 44 | is => 'rw', | ||
| 45 | isa => 'Int', | ||
| 46 | default => 0, | ||
| 47 | ); | ||
| 48 | |||
| 49 | has 'message' => ( | ||
| 50 | is => 'rw', | ||
| 51 | isa => 'Str', | ||
| 52 | default => '', | ||
| 53 | ); | ||
| 54 | |||
| 55 | __PACKAGE__->meta->make_immutable; | ||
| 56 | no Moose; | ||
| 57 | no MooseX::FollowPBP; | ||
| 58 | |||
| 59 | =head1 FUNCTIONS | ||
| 60 | |||
| 61 | =head2 new | ||
| 62 | |||
| 63 | Create a new error object: | ||
| 64 | |||
| 65 | my $e = TryCatch::Error->new( value => $foo, message => bar ); | ||
| 66 | |||
| 67 | =head1 ACCESSORS | ||
| 68 | |||
| 69 | =head2 get_* | ||
| 70 | |||
| 71 | =head2 set_* | ||
| 72 | |||
| 73 | The default TryCatch::Error has 2 attributes, B<value> and B<message>, which are an integer and a string. | ||
| 74 | |||
| 75 | |||
| 76 | =head1 AUTHOR | ||
| 77 | |||
| 78 | Pedro Figueiredo, C<< <me at pedrofigueiredo.org> >> | ||
| 79 | |||
| 80 | =head1 BUGS | ||
| 81 | |||
| 82 | Please report any bugs or feature requests to C<bug-trycatch-error at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=TryCatch-Error>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. | ||
| 83 | |||
| 84 | |||
| 85 | =head1 SUPPORT | ||
| 86 | |||
| 87 | You can find documentation for this module with the perldoc command. | ||
| 88 | |||
| 89 | perldoc TryCatch::Error | ||
| 90 | |||
| 91 | |||
| 92 | You can also look for information at: | ||
| 93 | |||
| 94 | =over 4 | ||
| 95 | |||
| 96 | =item * RT: CPAN's request tracker | ||
| 97 | |||
| 98 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=TryCatch-Error> | ||
| 99 | |||
| 100 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 101 | |||
| 102 | L<http://annocpan.org/dist/TryCatch-Error> | ||
| 103 | |||
| 104 | =item * CPAN Ratings | ||
| 105 | |||
| 106 | L<http://cpanratings.perl.org/d/TryCatch-Error> | ||
| 107 | |||
| 108 | =item * Search CPAN | ||
| 109 | |||
| 110 | L<http://search.cpan.org/dist/TryCatch-Error/> | ||
| 111 | |||
| 112 | =back | ||
| 113 | |||
| 114 | |||
| 115 | =head1 ACKNOWLEDGEMENTS | ||
| 116 | |||
| 117 | =over 4 | ||
| 118 | |||
| 119 | =item * Ash Berlin, the author of TryCatch | ||
| 120 | |||
| 121 | =item * The Moose crew | ||
| 122 | |||
| 123 | =back | ||
| 124 | |||
| 125 | =head1 COPYRIGHT & LICENSE | ||
| 126 | |||
| 127 | Copyright 2009 Pedro Figueiredo, all rights reserved. | ||
| 128 | |||
| 129 | This program is free software; you can redistribute it and/or modify it | ||
| 130 | under the same terms as Perl itself. | ||
| 131 | |||
| 132 | |||
| 133 | =cut | ||
| 134 | |||
| 135 | 45; # End of TryCatch::Error |