From: Andrew Ford Date: Thu, 21 Jul 2005 07:30:24 +0000 (+0000) Subject: helpers now create .new files where files to be created already exist; -nonew option... X-Git-Tag: 5.7099_04~1254 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=ef3250bcc579b6ace8ec3bc0b4d93b9660162994;hp=fb9257c1ef523c89c4d5b8accd000809ded660e9 helpers now create .new files where files to be created already exist; -nonew option to suppress the behaviour. --- diff --git a/Changes b/Changes index 2578cda..8d6c8b7 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ This file documents the revision history for Perl extension Catalyst. 5.31 2005-06-04 12:35:00 + - helpers now create .new files where files already exist and differ - fixed $Data::Dumper::Terse (Robin Berjon) - added arguments for detach - new credits section in pod diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index a717bee..2af57d0 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -211,7 +211,12 @@ sub mk_file { my ( $self, $file, $content ) = @_; if ( -e $file ) { print qq/ exists "$file"\n/; - return 0; + return 0 unless $self->{'.newfiles'}; + if ( my $f = IO::File->new("< $file") ) { + my $oldcontent = join('', (<$f>)); + return 0 if $content eq $oldcontent; + } + $file .= '.new'; } if ( my $f = IO::File->new("> $file") ) { print $f $content; @@ -748,12 +753,14 @@ use Pod::Usage; use Catalyst::Helper; my $help = 0; +my $nonew = 0; -GetOptions( 'help|?' => \$help ); +GetOptions( 'help|?' => \$help, + 'nonew' => \$nonew ); pod2usage(1) if ( $help || !$ARGV[0] ); -my $helper = Catalyst::Helper->new; +my $helper = Catalyst::Helper->new({'.newfiles' => !$nonew}); pod2usage(1) unless $helper->mk_component( '[% name %]', @ARGV ); 1; @@ -768,6 +775,7 @@ pod2usage(1) unless $helper->mk_component( '[% name %]', @ARGV ); Options: -help display this help and exits + -nonew don't create a .new file where a file to be created exists Examples: [% appprefix %]_create.pl controller My::Controller @@ -786,6 +794,10 @@ pod2usage(1) unless $helper->mk_component( '[% name %]', @ARGV ); Create a new Catalyst Component. +Existing component files are not overwritten. If any of the component files +to be created already exist the file will be written with a '.new' suffix. +This behaviour can be supressed with the C<-nonew> option. + =head1 AUTHOR Sebastian Riedel, C diff --git a/script/catalyst.pl b/script/catalyst.pl index 161af6a..7514e11 100755 --- a/script/catalyst.pl +++ b/script/catalyst.pl @@ -5,13 +5,15 @@ use Getopt::Long; use Pod::Usage; use Catalyst::Helper; -my $help = 0; +my $help = 0; +my $nonew = 0; -GetOptions( 'help|?' => \$help ); +GetOptions( 'help|?' => \$help, + 'nonew' => \$nonew ); pod2usage(1) if ( $help || !$ARGV[0] ); -my $helper = Catalyst::Helper->new; +my $helper = Catalyst::Helper->new({'.newfiles' => !$nonew}); pod2usage(1) unless $helper->mk_app( $ARGV[0] ); 1; @@ -27,6 +29,7 @@ catalyst.pl [options] application-name Options: -help display this help and exits + -nonew don't create a .new file where a file to be created exists application-name has to be a valid Perl module name and can include ::