Fix broken POD links found by App::PodLinkChecker
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Producer / TT / Table.pm
index 57cd16b..799ca54 100644 (file)
@@ -1,25 +1,5 @@
 package SQL::Translator::Producer::TT::Table;
 
-# -------------------------------------------------------------------
-# $Id: Table.pm,v 1.3 2004-08-19 20:58:05 grommit Exp $
-# -------------------------------------------------------------------
-# 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
-# published by the Free Software Foundation; version 2.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307  USA
-# -------------------------------------------------------------------
-
 =pod
 
 =head1 NAME
@@ -68,10 +48,10 @@ allows you to write the result for each table to a separate file.
 It needs one additional producer_arg of C<tt_table> which is the file
 name of the template to use.  This template will be passed a template
 var of C<table>, which is the current
-L<SQL::Translator::Producer::Table> table we are producing, which you
-can then use to walk the schema via the methods documented in that
-module. You also get L<schema> as a shortcut to the
-L<SQL::Translator::Producer::Schema> for the table and C<translator>,
+L<SQL::Translator::Schema::Table> table we are producing,
+which you can then use to walk the schema via the methods documented
+in that module. You also get C<schema> as a shortcut to the
+L<SQL::Translator::Schema> for the table and C<translator>,
 the L<SQL::Translator> object for this parse in case you want to get
 access to any of the options etc set here.
 
@@ -85,7 +65,7 @@ Here's a brief example of what the template could look like:
 
 See F<t/data/template/table.tt> for a more complete example.
 
-You can also set any of the options used to initiallize the Template
+You can also set any of the options used to initialize the Template
 object by adding them to your producer_args. See Template Toolkit docs
 for details of the options.
 
@@ -102,7 +82,7 @@ If you set C<mk_files> and its additional options the producer will
 write a separate file for each table in the schema. This is useful for
 producing things like HTML documentation where every table gets its
 own page (you could also use TTSchema producer to add an index page).
-Its also particulary good for code generation where you want to
+It's also particularly good for code generation where you want to
 produce a class file per table.
 
 =head1 OPTIONS
@@ -143,12 +123,12 @@ where we want to write our output. One of "skip", "die", "replace",
 B<replace> - Over-write the existing file with the new one, clobbering
 anything already there.
 
-B<skip> - Leave the origional file as it was and don't write the new
+B<skip> - Leave the original file as it was and don't write the new
 version anywhere.
 
 B<die> - Die with an existing file error.
 
-B<insert> - Insert the generated output into the file bewteen a set of
+B<insert> - Insert the generated output into the file between a set of
 special comments (defined by the following options.) Any code between
 the comments will be overwritten (ie the results from a previous
 produce) but the rest of the file is left alone (your custom code).
@@ -173,12 +153,11 @@ whitespace either side, to be recognised.
 
 =cut
 
-# -------------------------------------------------------------------
-
 use strict;
+use warnings;
 
-use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/;
+our ( $DEBUG, @EXPORT_OK );
+our $VERSION = '1.59';
 $DEBUG   = 0 unless defined $DEBUG;
 
 use File::Path;
@@ -209,19 +188,19 @@ sub produce {
         %$pargs,        # Allow any TT opts to be passed in the producer_args
     ) || die "Failed to initialize Template object: ".Template->error;
 
-       for my $tbl ( sort {$a->order <=> $b->order} $scma->get_tables ) {
-               my $outtmp;
+   for my $tbl ( sort {$a->order <=> $b->order} $scma->get_tables ) {
+      my $outtmp;
         $tt->process( $file, {
             translator => $Translator,
             schema     => $scma,
             table      => $tbl,
-        }, \$outtmp ) 
-               or die "Error processing template '$file' for table '".$tbl->name
-                 ."': ".$tt->error;
+        }, \$outtmp )
+      or die "Error processing template '$file' for table '".$tbl->name
+             ."': ".$tt->error;
         $out .= $outtmp;
 
         # Write out the file...
-               write_file(  table_file($tbl), $outtmp ) if $pargs->{mk_files};
+      write_file(  table_file($tbl), $outtmp ) if $pargs->{mk_files};
     }
 
     return $out;
@@ -238,7 +217,7 @@ sub table_file {
 
 # Write the src given to the file given, handling the on_exists arg.
 sub write_file {
-       my ($file, $src) = @_;
+   my ($file, $src) = @_;
     my $pargs = $Translator->producer_args;
     my $root = $pargs->{mk_files_base};
 
@@ -262,16 +241,18 @@ sub write_file {
         }
     }
     else {
-        warn "Creating $file.\n";
+        if ( my $interactive = -t STDIN && -t STDOUT ) {
+            warn "Creating $file.\n";
+        }
     }
 
-    my ($dir) = $file =~ m!^(.*)/!; # Want greedy, eveything before the last /
-       if ( $dir and not -d $dir and $pargs->{mk_file_dir} ) { mkpath($dir); }
+    my ($dir) = $file =~ m!^(.*)/!; # Want greedy, everything before the last /
+   if ( $dir and not -d $dir and $pargs->{mk_file_dir} ) { mkpath($dir); }
 
     debug "Writing to $file\n";
-       open( FILE, ">$file") or die "Error opening file $file : $!\n";
-       print FILE $src;
-       close(FILE);
+   open( FILE, ">$file") or die "Error opening file $file : $!\n";
+   print FILE $src;
+   close(FILE);
 }
 
 # Reads file and inserts code between the insert comments and returns the new
@@ -282,7 +263,7 @@ sub insert_code {
     my $cstart = $pargs->{insert_comment_start} || "SQLF_INSERT_START";
     my $cend   = $pargs->{insert_comment_end}   || "SQLF_INSERT_END";
 
-    # Slurp in the origional file
+    # Slurp in the original file
     open ( FILE, "<", "$file") or die "Error opening file $file : $!\n";
     local $/ = undef;
     my $orig = <FILE>;
@@ -300,8 +281,6 @@ sub insert_code {
 
 1;
 
-# -------------------------------------------------------------------
-
 =pod
 
 =head1 AUTHOR
@@ -311,13 +290,14 @@ Mark Addison E<lt>grommit@users.sourceforge.netE<gt>.
 =head1 TODO
 
 - Some tests for the various on exists options (they have been tested
-implicitley through use in a project but need some proper tests).
+implicitly through use in a project but need some proper tests).
 
 - More docs on code generation strategies.
 
 - Better hooks for filename generation.
 
-- Integrate with L<TT::Base> and L<TTSchema>.
+- Integrate with L<TT::Base|SQL::Translator::Producer::TT::Base> and
+  L<TTSchema|SQL::Translator::Producer::TTSchema>.
 
 =head1 SEE ALSO