Bumping version to 1.60
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Schema / Trigger.pm
index 419effd..4eecdf3 100644 (file)
@@ -29,22 +29,13 @@ C<SQL::Translator::Schema::Trigger> is the trigger object.
 =cut
 
 use Moo;
-use SQL::Translator::Utils qw(parse_list_arg ex2err throw);
-use SQL::Translator::Types qw(schema_obj);
-use List::MoreUtils qw(uniq);
-
-with qw(
-  SQL::Translator::Schema::Role::BuildArgs
-  SQL::Translator::Schema::Role::Extra
-  SQL::Translator::Schema::Role::Error
-  SQL::Translator::Schema::Role::Compare
-);
-
-use Carp;
+use SQL::Translator::Utils qw(parse_list_arg ex2err throw uniq);
+use SQL::Translator::Types qw(schema_obj enum);
+use Sub::Quote qw(quote_sub);
 
-our ( $TABLE_COUNT, $VIEW_COUNT );
+extends 'SQL::Translator::Schema::Object';
 
-our $VERSION = '1.59';
+our $VERSION = '1.60';
 
 =head2 new
 
@@ -80,11 +71,11 @@ C<database_event>.
 
 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;
@@ -114,7 +105,7 @@ Gets or sets the events that triggers the trigger.
 
 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 ];
@@ -181,7 +172,7 @@ Gets or set the table on which the trigger works, as a L<SQL::Translator::Schema
 
 =cut
 
-has table => ( is => 'rw', isa => schema_obj('Table') );
+has table => ( is => 'rw', isa => schema_obj('Table'), weak_ref => 1 );
 
 around table => \&ex2err;
 
@@ -221,7 +212,7 @@ Gets or set the action of the trigger.
 
 =cut
 
-has action => ( is => 'rw', default => sub { '' } );
+has action => ( is => 'rw', default => quote_sub(q{ '' }) );
 
 sub is_valid {
 
@@ -257,7 +248,7 @@ Get or set the trigger's name.
 
 =cut
 
-has name => ( is => 'rw', default => sub { '' } );
+has name => ( is => 'rw', default => quote_sub(q{ '' }) );
 
 =head2 order
 
@@ -267,7 +258,7 @@ Get or set the trigger's 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 ) = @_;
@@ -289,11 +280,9 @@ Get or set the trigger's scope (row or statement).
 
 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;
@@ -308,7 +297,7 @@ Get or set the trigger's schema object.
 
 =cut
 
-has schema => (is => 'rw', isa => schema_obj('Schema') );
+has schema => (is => 'rw', isa => schema_obj('Schema'), weak_ref => 1 );
 
 around schema => \&ex2err;
 
@@ -393,11 +382,6 @@ around equals => sub {
     return 1;
 };
 
-sub DESTROY {
-    my $self = shift;
-    undef $self->{'schema'}; # destroy cyclical reference
-}
-
 # Must come after all 'has' declarations
 around new => \&ex2err;