=cut
-use Moo;
+use Moo 1.000003;
use SQL::Translator::Utils qw(parse_list_arg ex2err throw);
-use SQL::Translator::Types qw(schema_obj);
+use SQL::Translator::Types qw(schema_obj enum);
use List::MoreUtils qw(uniq);
+use Sub::Quote qw(quote_sub);
-with qw(
- SQL::Translator::Schema::Role::BuildArgs
- SQL::Translator::Schema::Role::Extra
- SQL::Translator::Schema::Role::Error
- SQL::Translator::Schema::Role::Compare
-);
-
-use Carp;
-
-our ( $TABLE_COUNT, $VIEW_COUNT );
+extends 'SQL::Translator::Schema::Object';
our $VERSION = '1.59';
has perform_action_when => (
is => 'rw',
- coerce => sub { defined $_[0] ? lc $_[0] : $_[0] },
- isa => sub {
- throw("Invalid argument '$_[0]' to perform_action_when")
- if defined $_[0] and $_[0] !~ m/^(before|after)$/i;
- },
+ coerce => quote_sub(q{ defined $_[0] ? lc $_[0] : $_[0] }),
+ isa => enum([qw(before after)], {
+ msg => "Invalid argument '%s' to perform_action_when",
+ allow_undef => 1,
+ }),
);
around perform_action_when => \&ex2err;
has database_events => (
is => 'rw',
- coerce => sub { [ map { lc } ref $_[0] eq 'ARRAY' ? @{$_[0]} : ($_[0]) ] },
+ coerce => quote_sub(q{ [ map { lc } ref $_[0] eq 'ARRAY' ? @{$_[0]} : ($_[0]) ] }),
isa => sub {
my @args = @{$_[0]};
my %valid = map { $_, 1 } qw[ insert update update_on delete ];
=cut
-has table => ( is => 'rw', isa => schema_obj('Table') );
+has table => ( is => 'rw', isa => schema_obj('Table'), weak_ref => 1 );
around table => \&ex2err;
=cut
-has action => ( is => 'rw', default => sub { '' } );
+has action => ( is => 'rw', default => quote_sub(q{ '' }) );
sub is_valid {
=cut
-has name => ( is => 'rw', default => sub { '' } );
+has name => ( is => 'rw', default => quote_sub(q{ '' }) );
=head2 order
=cut
-has order => ( is => 'rw', default => sub { 0 } );
+has order => ( is => 'rw', default => quote_sub(q{ 0 }) );
around order => sub {
my ( $orig, $self, $arg ) = @_;
has scope => (
is => 'rw',
- isa => sub {
- my ($arg) = @_;
- throw( "Invalid scope '$arg'" )
- if defined $arg and $arg !~ /^(row|statement)$/i;
- },
+ isa => enum([qw(row statement)], {
+ msg => "Invalid scope '%s'", icase => 1, allow_undef => 1,
+ }),
);
around scope => \&ex2err;
=cut
-has schema => (is => 'rw', isa => schema_obj('Schema') );
+has schema => (is => 'rw', isa => schema_obj('Schema'), weak_ref => 1 );
around schema => \&ex2err;
return 1;
};
-sub DESTROY {
- my $self = shift;
- undef $self->{'schema'}; # destroy cyclical reference
-}
-
# Must come after all 'has' declarations
around new => \&ex2err;