X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FSchema%2FTrigger.pm;h=8aa417123a866f3db61d389f00a6cbd7f6422848;hb=8ce5d6158b9fb1e09bda97b1061eea5232c268ad;hp=0e1ba5c556e44916b9f25eaeab11c41c7a3d79b8;hpb=39ad1787864511002290e379638a992db6217815;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Schema/Trigger.pm b/lib/SQL/Translator/Schema/Trigger.pm index 0e1ba5c..8aa4171 100644 --- a/lib/SQL/Translator/Schema/Trigger.pm +++ b/lib/SQL/Translator/Schema/Trigger.pm @@ -1,9 +1,9 @@ package SQL::Translator::Schema::Trigger; # ---------------------------------------------------------------------- -# $Id: Trigger.pm,v 1.2 2003-10-08 17:33:47 kycl4rk Exp $ +# $Id: Trigger.pm,v 1.9 2006-06-07 16:37:33 schiffbruechige Exp $ # ---------------------------------------------------------------------- -# Copyright (C) 2003 Ken Y. Clark +# Copyright (C) 2002-4 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 @@ -48,16 +48,20 @@ C is the trigger object. =cut use strict; -use Class::Base; use SQL::Translator::Utils 'parse_list_arg'; -use base 'Class::Base'; +use base 'SQL::Translator::Schema::Object'; + use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT); -$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/; # ---------------------------------------------------------------------- -sub init { + +__PACKAGE__->_attributes( qw/ + name schema perform_action_when database_event fields table on_table action + order +/); =pod @@ -69,21 +73,6 @@ Object constructor. =cut - my ( $self, $config ) = @_; - - for my $arg ( - qw[ - name perform_action_when database_event fields - on_table action schema - ] - ) { - next unless $config->{ $arg }; - $self->$arg( $config->{ $arg } );# or return; - } - - return $self; -} - # ---------------------------------------------------------------------- sub perform_action_when { @@ -182,22 +171,47 @@ Gets and set which fields to monitor for C. } # ---------------------------------------------------------------------- +sub table { + +=pod + +=head2 table + +Gets or set the table on which the trigger works, as a L object. + $trigger->table($triggered_table); + +=cut + + my ($self, $arg) = @_; + if ( @_ == 2 ) { + $self->error("Table attribute of a ".__PACKAGE__. + " must be a SQL::Translator::Schema::Table") + unless ref $arg and $arg->isa('SQL::Translator::Schema::Table'); + $self->{table} = $arg; + } + return $self->{table}; +} + +# ---------------------------------------------------------------------- sub on_table { =pod =head2 on_table -Gets or set the table name on which the trigger works. - - $trigger->table('foo'); +Gets or set the table name on which the trigger works, as a string. + $trigger->on_table('foo'); =cut - my $self = shift; - my $arg = shift || ''; - $self->{'on_table'} = $arg if $arg; - return $self->{'on_table'}; + my ($self, $arg) = @_; + if ( @_ == 2 ) { + my $table = $self->schema->get_table($arg); + die "Table named $arg doesn't exist" + if !$table; + $self->table($table); + } + return $self->table->name; } # ---------------------------------------------------------------------- @@ -318,6 +332,34 @@ Get or set the trigger's schema object. } # ---------------------------------------------------------------------- +sub equals { + +=pod + +=head2 equals + +Determines if this trigger is the same as another + + my $isIdentical = $trigger1->equals( $trigger2 ); + +=cut + + my $self = shift; + my $other = shift; + my $case_insensitive = shift; + + return 0 unless $self->SUPER::equals($other); + return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name; + #return 0 unless $self->is_valid eq $other->is_valid; + return 0 unless $self->perform_action_when eq $other->perform_action_when; + return 0 unless $self->database_event eq $other->database_event; + return 0 unless $self->on_table eq $other->on_table; + return 0 unless $self->action eq $other->action; + return 0 unless $self->_compare_objects(scalar $self->extra, scalar $other->extra); + return 1; +} + +# ---------------------------------------------------------------------- sub DESTROY { my $self = shift; undef $self->{'schema'}; # destroy cyclical reference