package SQL::Translator::Schema::Trigger;
-# ----------------------------------------------------------------------
-# Copyright (C) 2002-2009 SQLFairy Authors
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; version 2.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307 USA
-# -------------------------------------------------------------------
-
=pod
=head1 NAME
on_table => 'foo', # table name
action => '...', # text of trigger
schema => $schema, # Schema object
+ scope => 'row', # or statement
);
=head1 DESCRIPTION
=cut
use strict;
+use warnings;
use SQL::Translator::Utils 'parse_list_arg';
use base 'SQL::Translator::Schema::Object';
use Carp;
-use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT);
-
-$VERSION = '1.59';
+our ( $TABLE_COUNT, $VIEW_COUNT );
-# ----------------------------------------------------------------------
+our $VERSION = '1.59';
__PACKAGE__->_attributes( qw/
name schema perform_action_when database_events database_event
- fields table on_table action order
+ fields table on_table action order scope
/);
=pod
=cut
-# ----------------------------------------------------------------------
sub perform_action_when {
=pod
return $self->{'perform_action_when'};
}
-# ----------------------------------------------------------------------
sub database_event {
=pod
return $self->database_events( @_ );
}
-# ----------------------------------------------------------------------
sub database_events {
=pod
: $self->{'database_events'};
}
-# ----------------------------------------------------------------------
sub fields {
=pod
return wantarray ? @{ $self->{'fields'} || [] } : $self->{'fields'};
}
-# ----------------------------------------------------------------------
sub table {
=pod
return $self->{table};
}
-# ----------------------------------------------------------------------
sub on_table {
=pod
return $self->table->name;
}
-# ----------------------------------------------------------------------
sub action {
=pod
return $self->{'action'};
}
-# ----------------------------------------------------------------------
sub is_valid {
=pod
return 1;
}
-# ----------------------------------------------------------------------
sub name {
=pod
return $self->{'name'} || '';
}
-# ----------------------------------------------------------------------
sub order {
=pod
return $self->{'order'} || 0;
}
-# ----------------------------------------------------------------------
+
+sub scope {
+
+=pod
+
+=head2 scope
+
+Get or set the trigger's scope (row or statement).
+
+ my $scope = $trigger->scope('statement');
+
+=cut
+
+ my ( $self, $arg ) = @_;
+
+ if ( defined $arg ) {
+ return $self->error( "Invalid scope '$arg'" )
+ unless $arg =~ /^(row|statement)$/i;
+
+ $self->{scope} = $arg;
+ }
+
+ return $self->{scope} || '';
+}
+
sub schema {
=pod
return $self->{'schema'};
}
-# ----------------------------------------------------------------------
sub compare_arrays {
=pod
return 1;
}
-# ----------------------------------------------------------------------
sub equals {
=pod
return 1;
}
-# ----------------------------------------------------------------------
sub DESTROY {
my $self = shift;
undef $self->{'schema'}; # destroy cyclical reference
1;
-# ----------------------------------------------------------------------
-
=pod
=head1 AUTHORS