package SQL::Translator::Schema::Constraint;
# ----------------------------------------------------------------------
-# $Id: Constraint.pm,v 1.2 2003-05-05 04:32:39 kycl4rk Exp $
+# $Id: Constraint.pm,v 1.3 2003-05-09 17:06:11 kycl4rk Exp $
# ----------------------------------------------------------------------
# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
#
use strict;
use Class::Base;
use SQL::Translator::Schema::Constants;
+use SQL::Translator::Utils 'parse_list_arg';
use base 'Class::Base';
use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT);
=cut
my ( $self, $config ) = @_;
-# match_type on_delete_do on_update_do
- my @fields = qw[ name type fields reference_fields reference_table table ];
+ my @fields = qw[
+ table name type fields reference_fields reference_table
+ match_type on_delete on_update
+ ];
for my $arg ( @fields ) {
next unless $config->{ $arg };
=cut
my $self = shift;
- my $fields = UNIVERSAL::isa( $_[0], 'ARRAY' )
- ? shift : [ map { s/^\s+|\s+$//g; $_ } map { split /,/ } @_ ];
+ my $fields = parse_list_arg( @_ );
if ( @$fields ) {
my ( %unique, @unique );
}
# ----------------------------------------------------------------------
+sub match_type {
+
+=pod
+
+=head2 match_type
+
+Get or set the constraint's match_type. Only valid values are "full"
+or "partial."
+
+ my $match_type = $constraint->match_type('FULL');
+
+=cut
+
+ my $self = shift;
+
+ if ( my $arg = lc shift ) {
+ return $self->error("Invalid match type: $arg")
+ unless $arg eq 'full' || $arg eq 'partial';
+ $self->{'match_type'} = $arg;
+ }
+
+ return $self->{'match_type'} || '';
+}
+
+# ----------------------------------------------------------------------
sub name {
=pod
=cut
my $self = shift;
- my $fields = UNIVERSAL::isa( $_[0], 'ARRAY' )
- ? shift : [ map { s/^\s+|\s+$//g; $_ } map { split /,/ } @_ ];
+ my $fields = parse_list_arg( @_ );
if ( @$fields ) {
$self->{'reference_fields'} = $fields;
=cut
my $self = shift;
- my $options = UNIVERSAL::isa( $_[0], 'ARRAY' )
- ? shift : [ map { s/^\s+|\s+$//g; $_ } map { split /,/ } @_ ];
+ my $options = parse_list_arg( @_ );
push @{ $self->{'options'} }, @$options;
}
}
+# ----------------------------------------------------------------------
+sub DESTROY {
+ my $self = shift;
+ undef $self->{'table'}; # destroy cyclical reference
+}
+
1;
# ----------------------------------------------------------------------