package SQL::Translator::Producer::TT::Table;
# -------------------------------------------------------------------
-# $Id$
-# -------------------------------------------------------------------
# Copyright (C) 2002-2009 SQLFairy Authors
#
# This program is free software; you can redistribute it and/or
use strict;
use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
-$VERSION = '1.99';
+$VERSION = '1.59';
$DEBUG = 0 unless defined $DEBUG;
use File::Path;
%$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;
# 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};
}
}
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); }
+ 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