package Data::MultiValued::Exceptions; # ABSTRACT: exception classes =head1 DESCRIPTION This module defines a few exception classes, using L as a base class. =head1 CLASSES =head2 C Base class for "not found" errors. Has a C attribute, containing the value that was not found. =cut package Data::MultiValued::Exceptions::NotFound;{ use Moose; with 'Throwable'; use overload q{""} => 'as_string', fallback => 1; has message => ( is => 'ro', required => 1, ); has value => ( is => 'ro', required => 1, ); sub as_string { my ($self) = @_; my $str = $self->message . ($self->value // ''); return $str; } } =head2 C Subclass of L, for tags. Stringifies to: tag not found: $value =cut package Data::MultiValued::Exceptions::TagNotFound;{ use Moose; extends 'Data::MultiValued::Exceptions::NotFound'; has '+message' => ( default => 'tag not found: ', ); } =head2 C Subclass of L, for ranges. Stringifies to: no range found for value: $value =cut package Data::MultiValued::Exceptions::RangeNotFound;{ use Moose; extends 'Data::MultiValued::Exceptions::NotFound'; has '+message' => ( default => 'no range found for value: ', ); } =head2 C Thrown when an invalid range is supplied to a method. An invalid range is a range with C greater than C. Stringifies to: invalid range: $from, $to =cut package Data::MultiValued::Exceptions::BadRange;{ use Moose; with 'Throwable'; use overload q{""} => 'as_string', fallback => 1; has ['from','to'] => ( is => 'ro', required => 1 ); sub as_string { my ($self) = @_; my $str = 'invalid range: ' . $self->from . ', ' . $self->to; return $str; } } 1;