X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper.pm;h=1d25105f0c65cfc03525282d81efe492d4f31cab;hb=9edb1eb325435873ed55f643d671cb050bd8b659;hp=a717bee9d4c10325c8afce68a8b78b1e972f21dd;hpb=7dcb4831027234fcb0b401addaab9332bd5211eb;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index a717bee..1d25105 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -40,7 +40,7 @@ sub get_file { $cache{$class} = eval "package $class; "; } my $data = $cache{$class}; - my @files = split /^__(.+)__\n/m, $data; + my @files = split /^__(.+)__\r?\n/m, $data; shift @files; while (@files) { my ( $name, $content ) = splice @files, 0, 2; @@ -136,7 +136,7 @@ sub mk_component { my @path = split /\:\:/, $name; $file = pop @path; $path = File::Spec->catdir( $path, @path ); - mkpath $path; + mkpath [$path]; } $file = File::Spec->catfile( $path, "$file.pm" ); $self->{file} = $file; @@ -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