Commit | Line | Data |
---|---|---|
45595850 | 1 | package SQL::Translator::Role::Error; |
5f7fd749 | 2 | use Moo::Role; |
68d75205 | 3 | use Sub::Quote qw(quote_sub); |
5f7fd749 | 4 | |
d24c55fe | 5 | has _ERROR => ( |
6 | is => 'rw', | |
7 | accessor => 'error', | |
8 | init_arg => undef, | |
68d75205 | 9 | default => quote_sub(q{ '' }), |
d24c55fe | 10 | ); |
5f7fd749 | 11 | |
12 | around error => sub { | |
13 | my ($orig, $self) = (shift, shift); | |
14 | ||
45287c81 | 15 | # Emulate horrible Class::Base API |
d24c55fe | 16 | unless (ref($self)) { |
17 | my $errref = do { no strict 'refs'; \${"${self}::ERROR"} }; | |
45287c81 | 18 | return $$errref unless @_; |
19 | $$errref = $_[0]; | |
20 | return undef; | |
21 | } | |
22 | ||
5f7fd749 | 23 | return $self->$orig unless @_; |
45287c81 | 24 | $self->$orig(@_); |
5f7fd749 | 25 | return undef; |
26 | }; | |
27 | ||
28 | 1; |