40319e4afdbb347dbf98bdf87c919707288bd4d1
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Role / Error.pm
1 package SQL::Translator::Role::Error;
2 use Moo::Role;
3
4 has _ERROR => (
5     is => 'rw',
6     accessor => 'error',
7     init_arg => undef,
8     default => sub { '' },
9 );
10
11 around error => sub {
12     my ($orig, $self) = (shift, shift);
13
14     # Emulate horrible Class::Base API
15     unless (ref($self)) {
16         my $errref = do { no strict 'refs'; \${"${self}::ERROR"} };
17         return $$errref unless @_;
18         $$errref = $_[0];
19         return undef;
20     }
21
22     return $self->$orig unless @_;
23     $self->$orig(@_);
24     return undef;
25 };
26
27 1;