1 package SQL::Translator::Role::Error;
5 SQL::Translator::Role::Error - Error setter/getter for objects and classes
9 In the class consuming the role:
13 with qw(SQL::Translator::Role::Error);
17 return $self->error("Something failed")
18 unless $some_condition;
22 In code using the class:
24 Foo->foo or die Foo->error;
26 $foo->foo or die $foo->error;
30 This L<Moo::Role> provides a method for getting and setting error on a
36 use Sub::Quote qw(quote_sub);
42 default => quote_sub(q{ '' }),
47 =head2 $object_or_class->error([$message])
49 If called with an argument, sets the error message and returns undef,
50 otherwise returns the message.
52 As an implementation detail, for compatibility with L<Class::Base>, the
53 message is stored in C<< $object->{_ERROR} >> or C<< $Class::ERROR >>,
54 depending on whether the invocant is an object.
59 my ($orig, $self) = (shift, shift);
61 # Emulate horrible Class::Base API
63 my $errref = do { no strict 'refs'; \${"${self}::ERROR"} };
64 return $$errref unless @_;
69 return $self->$orig unless @_;
80 L<Class::Base/Error Handling>