| 1 | package Valiant::Util::Exception::MissingMethod; | ||
| 2 | |||
| 3 | use Moo; | ||
| 4 | extends 'Valiant::Util::Exception'; | ||
| 5 | |||
| 6 | has object => (is=>'ro', required=>1); | ||
| 7 | has method => (is=>'ro', required=>1); | ||
| 8 | |||
| 9 | sub _build_message { | ||
| 10 | my ($self) = @_; | ||
| 11 | if(ref $self->method) { | ||
| 12 | my $methods = join ', ', @{$self->method}; | ||
| 13 | return "Object '@{[ ref $self->object ]}' must provide one of the following methods: $methods"; | ||
| 14 | } else { | ||
| 15 | return "Object '@{[ ref $self->object ]}' has no method '@{[ $self->method ]}'."; | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | 1; | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | Valiant::Util::Exception::MissingMethod - Object is missing method | ||
| 24 | |||
| 25 | =head1 SYNOPSIS | ||
| 26 | |||
| 27 | die Valiant::Exception::MissingMethod->new(object=>$self, method=>'if'); | ||
| 28 | |||
| 29 | =head1 DESCRIPTION | ||
| 30 | |||
| 31 | Encapsulates an error when you want to call a method on an object but that object fails | ||
| 32 | to have that method. | ||
| 33 | |||
| 34 | =head1 ATTRIBUTES | ||
| 35 | |||
| 36 | =head2 object | ||
| 37 | |||
| 38 | =head2 method | ||
| 39 | |||
| 40 | The string name of the missing method and a reference to the object that was missing it. If the | ||
| 41 | method attribute is an arrayref than means 'one of these methods' must be provided. | ||
| 42 | |||
| 43 | =head2 message | ||
| 44 | |||
| 45 | The actual exception message | ||
| 46 | |||
| 47 | =head1 SEE ALSO | ||
| 48 | |||
| 49 | L<Valiant> | ||
| 50 | |||
| 51 | =head1 AUTHOR | ||
| 52 | |||
| 53 | See L<Valiant> | ||
| 54 | |||
| 55 | =head1 COPYRIGHT & LICENSE | ||
| 56 | |||
| 57 | See L<Valiant> | ||
| 58 | |||
| 59 | =cut |