All Schema objects now have an extra attribute. Added parsing support (and
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Schema.pm
index beac893..576526a 100644 (file)
@@ -1,9 +1,9 @@
 package SQL::Translator::Schema;
 
 # ----------------------------------------------------------------------
-# $Id: Schema.pm,v 1.12 2003-10-08 18:35:15 phrrngtn 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
@@ -43,21 +43,22 @@ returns the database structure.
 =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.12 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.20 $ =~ /(\d+)\.(\d+)/;
 
 # ----------------------------------------------------------------------
-sub init {
+
+__PACKAGE__->_attributes( qw/name database translator/ );
 
 =pod
 
@@ -65,16 +66,16 @@ sub init {
 
 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);
 }
 
 # ----------------------------------------------------------------------
@@ -111,7 +112,8 @@ not be created.
     }
 
     $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]);
@@ -596,6 +598,18 @@ Get or set the schema's name.  (optional)
     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;