summaryrefslogtreecommitdiff
path: root/lib/Data/MultiValued/Exceptions.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Data/MultiValued/Exceptions.pm')
-rw-r--r--lib/Data/MultiValued/Exceptions.pm111
1 files changed, 111 insertions, 0 deletions
diff --git a/lib/Data/MultiValued/Exceptions.pm b/lib/Data/MultiValued/Exceptions.pm
new file mode 100644
index 0000000..6495780
--- /dev/null
+++ b/lib/Data/MultiValued/Exceptions.pm
@@ -0,0 +1,111 @@
+package Data::MultiValued::Exceptions;
+
+# ABSTRACT: exception classes
+
+=head1 DESCRIPTION
+
+This module defines a few exception classes, using L<Throwable::Error>
+as a base class.
+
+=head1 CLASSES
+
+=head2 C<Data::MultiValued::Exceptions::NotFound>
+
+Base class for "not found" errors. Has a C<value> attribute,
+containing the value that was not found.
+
+=cut
+
+package Data::MultiValued::Exceptions::NotFound;{
+use Moose;
+extends 'Throwable::Error';
+
+has value => (
+ is => 'ro',
+ required => 1,
+);
+
+sub as_string {
+ my ($self) = @_;
+
+ my $str = $self->message . ($self->value // '<undef>');
+ $str .= "\n\n" . $self->stack_trace->as_string;
+
+ return $str;
+}
+}
+
+=head2 C<Data::MultiValued::Exceptions::TagNotFound>
+
+Subclass of L</Data::MultiValued::Exceptions::NotFound>, for
+tags. Stringifies to:
+
+ tag not found: $value
+
+ $stack_trace
+
+=cut
+
+package Data::MultiValued::Exceptions::TagNotFound;{
+use Moose;
+extends 'Data::MultiValued::Exceptions::NotFound';
+
+has '+message' => (
+ default => 'tag not found: ',
+);
+}
+
+=head2 C<Data::MultiValued::Exceptions::RangeNotFound>
+
+Subclass of L</Data::MultiValued::Exceptions::NotFound>, for
+ranges. Stringifies to:
+
+ no range found for value: $value
+
+ $stack_trace
+
+=cut
+
+package Data::MultiValued::Exceptions::RangeNotFound;{
+use Moose;
+extends 'Data::MultiValued::Exceptions::NotFound';
+
+has '+message' => (
+ default => 'no range found for value: ',
+);
+}
+
+=head2 C<Data::MultiValued::Exceptions::BadRange>
+
+Thrown when an invalid range is supplied to a method. An invalid range
+is a range with C<from> greater than C<to>.
+
+Stringifies to:
+
+ invalid range: $from, $to
+
+ $stack_trace
+
+=cut
+
+package Data::MultiValued::Exceptions::BadRange;{
+use Moose;
+extends 'Throwable::Error';
+
+has ['from','to'] => ( is => 'ro', required => 1 );
+has '+message' => (
+ default => 'invalid range: ',
+);
+
+sub as_string {
+ my ($self) = @_;
+
+ my $str = $self->message . $self->from . ', ' . $self->to;
+ $str .= "\n\n" . $self->stack_trace->as_string;
+
+ return $str;
+}
+
+}
+
+1;