Make Schema::Graph only load if "as_graph" is called on a Schema object
Jess Robinson [Tue, 10 Jun 2008 15:34:02 +0000 (15:34 +0000)]
lib/SQL/Translator/Parser/DBI.pm
lib/SQL/Translator/Schema.pm
lib/SQL/Translator/Schema/Graph.pm

index c42730a..53f0a28 100644 (file)
@@ -138,14 +138,6 @@ use Exporter;
 
 use SQL::Translator::Utils qw(debug);
 
-use SQL::Translator::Parser::DBI::MySQL;
-use SQL::Translator::Parser::DBI::SQLServer;
-use SQL::Translator::Parser::DBI::SQLite;
-use SQL::Translator::Parser::DBI::Sybase;
-use SQL::Translator::Parser::DBI::PostgreSQL;
-use SQL::Translator::Parser::DBI::DB2;
-use SQL::Translator::Parser::DBI::Oracle;
-
 use base qw(Exporter);
 @EXPORT = qw(parse);
 
@@ -180,11 +172,7 @@ sub parse {
     my $pkg     = "SQL::Translator::Parser::DBI::$driver";
     my $sub     = $pkg.'::parse';
 
-    #
-    # I can't get this to work.  I seem to have to have the "use"
-    # statements above.
-    #
-#    $tr->load( $pkg );
+    $tr->load( $pkg );
 
     eval {
         no strict 'refs';
index 03e658a..86ceb67 100644 (file)
@@ -54,7 +54,7 @@ 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 'SQL::Translator::Schema::Object';
@@ -74,8 +74,10 @@ sub as_graph {
 Returns the schema as an L<SQL::Translator::Schema::Graph> object.
 
 =cut
+    require  SQL::Translator::Schema::Graph;
 
     my $self = shift;
+
     return SQL::Translator::Schema::Graph->new(
         translator => $self->translator );
 }
index d13c56b..abcf973 100644 (file)
@@ -6,7 +6,7 @@ use Data::Dumper;
 local $Data::Dumper::Maxdepth = 3;
 
 use Log::Log4perl qw(:easy);
-Log::Log4perl->easy_init($ERROR);
+Log::Log4perl->easy_init($ERROR) unless Log::Log4perl->initialized();
 use SQL::Translator::Schema::Graph::Node;
 use SQL::Translator::Schema::Graph::Edge;
 use SQL::Translator::Schema::Graph::Port;