Added -scripts option to catalyst.pl for script updating
Sebastian Riedel [Wed, 2 Nov 2005 16:22:34 +0000 (16:22 +0000)]
Changes
lib/Catalyst/Helper.pm
script/catalyst.pl

diff --git a/Changes b/Changes
index 836ed27..4d0dce8 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 Tis file documents the revision history for Perl extension Catalyst.
 
 5.50
+        - Added -scripts option to catalyst.pl for script updating
         - Changed helpers to default to long types, Controller instead of C
         - Added Catalyst::Controller, Catalyst::Model and Catalyst::View
           base classes
index 5288ed2..470809a 100644 (file)
@@ -62,26 +62,30 @@ sub mk_app {
     $self->{name} = $name;
     $self->{dir}  = $name;
     $self->{dir} =~ s/\:\:/-/g;
+    $self->{script}    = File::Spec->catdir( $self->{dir}, 'script' );
     $self->{appprefix} = Catalyst::Utils::appprefix($name);
     $self->{startperl} = $Config{startperl};
     $self->{scriptgen} = $Catalyst::CATALYST_SCRIPT_GEN || 4;
     $self->{author}    = $self->{author} = $ENV{'AUTHOR'}
       || eval { @{ [ getpwuid($<) ] }[6] }
       || 'Catalyst developer';
-    $self->_mk_dirs;
-    $self->_mk_appclass;
-    $self->_mk_build;
-    $self->_mk_makefile;
-    $self->_mk_readme;
-    $self->_mk_changes;
-    $self->_mk_apptest;
+
+    unless ( $self->{scripts} ) {
+        $self->_mk_dirs;
+        $self->_mk_appclass;
+        $self->_mk_build;
+        $self->_mk_makefile;
+        $self->_mk_readme;
+        $self->_mk_changes;
+        $self->_mk_apptest;
+        $self->_mk_images;
+        $self->_mk_favicon;
+    }
     $self->_mk_cgi;
     $self->_mk_fastcgi;
     $self->_mk_server;
     $self->_mk_test;
     $self->_mk_create;
-    $self->_mk_images;
-    $self->_mk_favicon;
     return 1;
 }
 
@@ -210,12 +214,14 @@ sub mk_file {
     my ( $self, $file, $content ) = @_;
     if ( -e $file ) {
         print qq/ exists "$file"\n/;
-        return 0 unless $self->{'.newfiles'};
-        if ( my $f = IO::File->new("< $file") ) {
-            my $oldcontent = join( '', (<$f>) );
-            return 0 if $content eq $oldcontent;
+        return 0 unless ( $self->{'.newfiles'} || $self->{scripts} );
+        if ( $self->{'.newfiles'} ) {
+            if ( my $f = IO::File->new("< $file") ) {
+                my $oldcontent = join( '', (<$f>) );
+                return 0 if $content eq $oldcontent;
+            }
+            $file .= '.new';
         }
-        $file .= '.new';
     }
     if ( my $f = IO::File->new("> $file") ) {
         binmode $f;
@@ -275,7 +281,6 @@ sub render_file {
 sub _mk_dirs {
     my $self = shift;
     $self->mk_dir( $self->{dir} );
-    $self->{script} = File::Spec->catdir( $self->{dir}, 'script' );
     $self->mk_dir( $self->{script} );
     $self->{lib} = File::Spec->catdir( $self->{dir}, 'lib' );
     $self->mk_dir( $self->{lib} );
index 0de8e3d..6a20cfe 100755 (executable)
@@ -5,20 +5,23 @@ use Getopt::Long;
 use Pod::Usage;
 use Catalyst::Helper;
 
-my $help  = 0;
-my $nonew = 0;
-my $short = 0;
+my $help    = 0;
+my $nonew   = 0;
+my $scripts = 0;
+my $short   = 0;
 
 GetOptions(
-    'help|?' => \$help,
-    'nonew'  => \$nonew,
-    'short'  => \$short
+    'help|?'  => \$help,
+    'nonew'   => \$nonew,
+    'scripts' => \$scripts,
+    'short'   => \$short
 );
 
 pod2usage(1) if ( $help || !$ARGV[0] );
 
 my $helper =
-  Catalyst::Helper->new( { '.newfiles' => !$nonew, 'short' => $short } );
+  Catalyst::Helper->new(
+    { '.newfiles' => !$nonew, 'scripts' => $scripts, 'short' => $short } );
 pod2usage(1) unless $helper->mk_app( $ARGV[0] );
 
 1;
@@ -33,9 +36,10 @@ catalyst - Bootstrap a Catalyst application
 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
-   -short    use short types, like C instead of Controller...
+   -help       display this help and exits
+   -nonew      don't create a .new file where a file to be created exists
+   -scripts    update helper scripts only
+   -short      use short types, like C instead of Controller...
 
  application-name must be a valid Perl module name and can include "::"