summaryrefslogtreecommitdiff
path: root/lib/Data/MultiValued/Exceptions.pm
blob: 84d6ffaa11c23bfd2158aea86b3e0de562ebf824 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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;
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 // '<undef>');
 
    return $str;
}
}
 
=head2 C<Data::MultiValued::Exceptions::TagNotFound>
 
Subclass of L</Data::MultiValued::Exceptions::NotFound>, 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<Data::MultiValued::Exceptions::RangeNotFound>
 
Subclass of L</Data::MultiValued::Exceptions::NotFound>, 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<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
 
=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;