package SQL::Translator::Schema;
# ----------------------------------------------------------------------
-# $Id: Schema.pm,v 1.10 2003-10-08 17:35:18 kycl4rk Exp $
+# $Id: Schema.pm,v 1.20 2004-11-05 13:19:31 grommit Exp $
# ----------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>
+# 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
=cut
use strict;
-use Class::Base;
use SQL::Translator::Schema::Constants;
use SQL::Translator::Schema::Procedure;
use SQL::Translator::Schema::Table;
use SQL::Translator::Schema::Trigger;
use SQL::Translator::Schema::View;
+use SQL::Translator::Schema::Graph;
use SQL::Translator::Utils 'parse_list_arg';
-use base 'Class::Base';
+use base 'SQL::Translator::Schema::Object';
use vars qw[ $VERSION $TABLE_ORDER $VIEW_ORDER $TRIGGER_ORDER $PROC_ORDER ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/;
# ----------------------------------------------------------------------
-sub init {
+
+__PACKAGE__->_attributes( qw/name database translator/ );
=pod
Object constructor.
- my $schema = SQL::Translator->new(
+ my $schema = SQL::Translator::Schema->new(
name => 'Foo',
database => 'MySQL',
);
=cut
- my ( $self, $config ) = @_;
- $self->params( $config, qw[ name database ] ) || return undef;
- return $self;
+sub as_graph {
+ my($self) = @_;
+ return SQL::Translator::Schema::Graph->new(translator => $self->translator);
}
# ----------------------------------------------------------------------
}
$table->order( ++$TABLE_ORDER );
- my $table_name = $table->name or return $self->error('No table name');
+ # We know we have a name as the Table->new above errors if none given.
+ my $table_name = $table->name;
if ( defined $self->{'tables'}{ $table_name } ) {
return $self->error(qq[Can't create table: "$table_name" exists]);
return $self->{'name'} || '';
}
+=head2 translator
+
+get the SQL::Translator instance that instatiated me
+
+=cut
+
+sub translator {
+ my $self = shift;
+ $self->{'translator'} = shift if @_;
+ return $self->{'translator'};
+}
+
# ----------------------------------------------------------------------
sub DESTROY {
my $self = shift;