X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper.pm;h=2af57d04453f5f0ab4a7629810c26619784e7c82;hb=58e9ce65718ef828fbec4a5a3afa713c95ef4c6f;hp=cca4dd1f6e86684b98782c7235ce6a38d881cb78;hpb=d2ee9760ceba06de9ab9a1cc0014fab331a04809;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index cca4dd1..2af57d0 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -64,7 +64,7 @@ sub mk_app { $self->{appprefix} = lc $self->{dir}; $self->{appprefix} =~ s/-/_/g; $self->{startperl} = $Config{startperl}; - $self->{scriptgen} = $Catalyst::CATALYST_SCRIPT_GEN; + $self->{scriptgen} = $Catalyst::CATALYST_SCRIPT_GEN || 4; $self->{author} = $self->{author} = $ENV{'AUTHOR'} || eval { @{ [ getpwuid($<) ] }[6] } || 'Catalyst developer'; @@ -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 @@ -830,6 +842,7 @@ sub default : Private { } =back + [% END %] =head1 AUTHOR