$cache{$class} = eval "package $class; <DATA>";
}
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;
$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';
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;
print qq/ exists "$dir"\n/;
return 0;
}
- if ( mkpath $dir) {
+ if ( mkpath [$dir] ) {
print qq/created "$dir"\n/;
return 1;
}
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;
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;
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
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<sri\@oook.de>
}
=back
+
[% END %]
=head1 AUTHOR