Add trigger support to PostgreSQL producer and parser (including trigger scope)
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Schema / Trigger.pm
index b1b95fc..f320fb2 100644 (file)
@@ -1,23 +1,5 @@
 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
@@ -35,6 +17,7 @@ SQL::Translator::Schema::Trigger - SQL::Translator trigger object
     on_table            => 'foo',    # table name
     action              => '...',    # text of trigger
     schema              => $schema,  # Schema object
+    scope               => 'row',    # or statement
   );
 
 =head1 DESCRIPTION
@@ -46,19 +29,20 @@ C<SQL::Translator::Schema::Trigger> is the trigger object.
 =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);
+our ( $TABLE_COUNT, $VIEW_COUNT );
 
-$VERSION = '1.59';
+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
@@ -318,6 +302,31 @@ Get or set the trigger's order.
     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