[Bps-public-commit] app-moduleshere branch, master, updated. ff7f74ae18b15fa5edd545cfeee9bea9c45067fa

? sunnavy sunnavy at bestpractical.com
Wed Apr 27 01:57:00 EDT 2011


The branch, master has been updated
       via  ff7f74ae18b15fa5edd545cfeee9bea9c45067fa (commit)
       via  03a6cf1d3611d21a3ef23378627d4f4b7fe73173 (commit)
       via  125c503c2b299bb1a945973235fb20c1c4aef2a2 (commit)
       via  3ac63e22fa600474b2f425f28f94270c51056f50 (commit)
       via  c852cf2b154caee40c7502cb0282a1c77b0c2c88 (commit)
       via  081e920af3e9da86910a85153b080f6d7e32df48 (commit)
       via  ef8f7add3d60f07e1fe27243435ac1c2fb9f5b29 (commit)
       via  09e424e4783b552251d16e559524d4e4c75d1279 (commit)
      from  94bc686cb4588187ded7354b7db5a5e7488fce43 (commit)

Summary of changes:
 Changes                |    4 +++
 bin/mhere              |   54 ++++++++++++++++++++++++++++++++---------------
 dist.ini               |    2 +-
 lib/App/moduleshere.pm |    4 +-
 t/00.load.t            |    4 ++-
 t/01.mhere.t           |    4 ++-
 t/02.dry-run.t         |   41 ++++++++++++++++++++++++++++++++++++
 7 files changed, 91 insertions(+), 22 deletions(-)
 create mode 100644 t/02.dry-run.t

- Log -----------------------------------------------------------------
commit 09e424e4783b552251d16e559524d4e4c75d1279
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Apr 27 13:41:38 2011 +0800

    --dry-run option

diff --git a/bin/mhere b/bin/mhere
index c203f15..1389f55 100755
--- a/bin/mhere
+++ b/bin/mhere
@@ -7,11 +7,12 @@ use File::Copy qw/copy/;
 
 use Getopt::Long;
 my %args;
-GetOptions(\%args, 'help|h', 'location|l=s', 'recursive|r') or exit;
+GetOptions( \%args, 'help|h', 'location|l=s', 'recursive|r', 'dry-run' )
+  or exit;
 
 @ARGV = grep { defined } @ARGV;
 
-if ( $args{help} || ! @ARGV ) {
+if ( $args{help} || !@ARGV ) {
     print <<'EOF';
 USAGE: mhere Module [ ... ]
 EXAMPLES:
@@ -30,12 +31,12 @@ if (@ARGV) {
     my $to = $args{location} || $ENV{APP_MODULES_HERE} || '.';
     my @success;
     if ( -e $to && !-d $to ) {
-        warn "failed to make path $to: it exists but not a directory\n";
+        warn "failed to make path '$to': it exists but not a directory\n";
     }
     else {
         if ( $args{recursive} ) {
             eval { require File::Copy::Recursive };
-            if ( $@ ) {
+            if ($@) {
                 print
 "you need to install File::Copy::Recursive to use the -r flag\n";
                 exit;
@@ -45,44 +46,62 @@ if (@ARGV) {
         }
 
         for my $mod (@ARGV) {
-            eval "require $mod" or warn "failed to require $mod\n" and next;
+            eval "require $mod" or warn "failed to require '$mod'\n" and next;
 
             my @parts = split /::/, $mod;
             my $inc = join( '/', @parts ) . '.pm';
             my $source = $INC{$inc};
-            warn "failed to find source of $mod\n" and next unless $source;
+            warn "failed to find source of '$mod'\n" and next unless $source;
 
             my $dest = catfile( $to, @parts ) . '.pm';
-            warn "failed to copy $source to $dest: they are the same path\n"
+            warn "failed to copy '$source' to '$dest': they are the same path\n"
               and next
               if rel2abs($source) eq rel2abs($dest);
 
             my $here = catdir( $to, @parts[ 0 .. $#parts - 1 ] );
             if ( -e $here && !-d $here ) {
                 warn
-                  "failed to make path $here: it exists but not a directory\n";
+"failed to make path '$here': it exists but not a directory\n";
                 next;
             }
 
-            mkpath($here)
-              or warn "failed to make path $here: $!\n" and next
-              unless -e $here;
-            copy( $source, $here )
-              or warn "failed to copy $source to $here: $!\n" and next;
+            if ( $args{'dry-run'} ) {
+                print "going to copy '$source' to '$dest'\n";
+            }
+            else {
+
+                mkpath($here)
+                  or warn "failed to make path '$here': $!\n" and next
+                  unless -e $here;
+
+                copy( $source, $dest )
+                  or warn "failed to copy '$source' to '$dest': $!\n" and next;
+            }
 
             if ( $args{recursive} ) {
                 my $dir = $source;
                 $dir =~ s/\.pm$//;
-                my $last_name = (splitpath $dir)[-1];
+                my $last_name = ( splitpath $dir)[-1];
                 if ( -e $dir ) {
-                    File::Copy::Recursive::dircopy( $dir, catdir( $here, $last_name ) )
-                      or warn "failed to copy $dir to $here: $!\n" and next;
+                    if ( $args{'dry-run'} ) {
+                        print "going to copy '$dir' to '"
+                          . catdir( $here, $last_name ) . "'\n";
+                    }
+                    else {
+                        File::Copy::Recursive::dircopy( $dir,
+                            catdir( $here, $last_name ) )
+                          or warn "failed to copy '$dir' to '$here': $!\n"
+                          and next;
+                    }
                 }
             }
-            push @success, $mod;
+
+            push @success, $mod unless $args{'dry-run'};
         }
     }
 
+    exit if $args{'dry-run'};
+
     if (@success) {
         print 'copied module(s): ', join ', ', @success;
         print "\n";

commit ef8f7add3d60f07e1fe27243435ac1c2fb9f5b29
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Apr 27 13:41:49 2011 +0800

    --dry-run test

diff --git a/t/02.dry-run.t b/t/02.dry-run.t
new file mode 100644
index 0000000..6a31c4d
--- /dev/null
+++ b/t/02.dry-run.t
@@ -0,0 +1,41 @@
+use strict;
+use warnings;
+
+use Test::More;
+use File::Temp 'tempdir';
+use FindBin;
+use File::Spec::Functions qw/catfile catdir updir/;
+use Carp;
+my $mhere = catfile( $FindBin::Bin, updir, 'bin', 'mhere' );
+
+my $dir = tempdir( CLEANUP => 1 );
+local $ENV{APP_MODULES_HERE} = $dir;
+my $out = `$^X $mhere strict --dry-run`;
+my $dest = catfile( $dir, 'strict.pm' );
+like( $out, qr/going to copy '.*strict\.pm' to '\Q$dest\E'/, 'dry-run output' );
+unlike( $out, qr/copied/, 'no copied msg' );
+ok( !-e catfile( $dir, 'strict.pm' ), 'strict.pm is indeed not copied' );
+
+SKIP: {
+    eval { require File::Copy::Recursive };
+    skip 'need File::Copy::Recursive to use -r', 3 if $@;
+    my $out = `$^X $mhere Carp -r --dry-run`;
+    $dest = catfile( $dir, 'Carp' );
+    like(
+        $out,
+        qr/going to copy '.*Carp\.pm' to '\Q$dest.pm\E'/,
+        'dry-run output'
+    );
+
+    like(
+        $out,
+        qr/going to copy '.*Carp' to '\Q$dest\E'/,
+        'dry-run output with -r'
+    );
+    unlike( $out, qr/copied/, 'no copied msg' );
+
+    ok( !-e catfile( $dir, 'Carp.pm' ), 'Carp.pm is indeed not copied' );
+    ok( !-e catfile( $dir, 'Carp' ),    'Carp dir is indeed not copied' );
+}
+
+done_testing();

commit 081e920af3e9da86910a85153b080f6d7e32df48
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Apr 27 13:43:00 2011 +0800

    use done_testing() for all

diff --git a/t/00.load.t b/t/00.load.t
index 6e4bc43..6c929c2 100644
--- a/t/00.load.t
+++ b/t/00.load.t
@@ -1,7 +1,9 @@
-use Test::More tests => 1;
+use Test::More;
 
 BEGIN {
     use_ok('App::moduleshere');
 }
 
 diag("Testing App::moduleshere $App::moduleshere::VERSION");
+
+done_testing();
diff --git a/t/01.mhere.t b/t/01.mhere.t
index e29d319..7028b75 100644
--- a/t/01.mhere.t
+++ b/t/01.mhere.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 14;
+use Test::More;
 use File::Temp 'tempdir';
 use FindBin;
 use File::Spec::Functions qw/catfile updir/;
@@ -100,3 +100,4 @@ sub compare_files {
     }
 }
 
+done_testing();

commit c852cf2b154caee40c7502cb0282a1c77b0c2c88
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Apr 27 13:44:44 2011 +0800

    doc for --dry-run

diff --git a/bin/mhere b/bin/mhere
index 1389f55..70a728c 100755
--- a/bin/mhere
+++ b/bin/mhere
@@ -23,6 +23,7 @@ EXAMPLES:
     mhere -l outlib Carp                          # ditto
     APP_MODULES_HERE=/tmp/ mhere Carp             # copy to /tmp/
     mhere -l /tmp/ Carp                           # ditto
+    mhere Carp --dry-run                          # don't actually copy
 EOF
     exit;
 }

commit 3ac63e22fa600474b2f425f28f94270c51056f50
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Apr 27 13:47:09 2011 +0800

    test update

diff --git a/t/01.mhere.t b/t/01.mhere.t
index 7028b75..256d0d6 100644
--- a/t/01.mhere.t
+++ b/t/01.mhere.t
@@ -20,6 +20,7 @@ EXAMPLES:
     mhere -l outlib Carp                          # ditto
     APP_MODULES_HERE=/tmp/ mhere Carp             # copy to /tmp/
     mhere -l /tmp/ Carp                           # ditto
+    mhere Carp --dry-run                          # don't actually copy
 EOF
 
 is( `$^X $mhere`,        $usage, 'mhere without args shows usage' );

commit 125c503c2b299bb1a945973235fb20c1c4aef2a2
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Apr 27 13:46:02 2011 +0800

    copyright update

diff --git a/lib/App/moduleshere.pm b/lib/App/moduleshere.pm
index 3f6ea7b..c91fc7e 100644
--- a/lib/App/moduleshere.pm
+++ b/lib/App/moduleshere.pm
@@ -2,7 +2,7 @@ package App::moduleshere;
 
 use warnings;
 use strict;
-our $VERSION = '0.07';
+our $VERSION = '0.08';
 
 1;
 
@@ -57,7 +57,7 @@ sunnavy  C<< sunnavy at bestpractical.com >>
 
 =head1 LICENCE AND COPYRIGHT
 
-Copyright 2010 Best Practical Solutions.
+Copyright 2010-2011 Best Practical Solutions.
 
 This program is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.

commit 03a6cf1d3611d21a3ef23378627d4f4b7fe73173
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Apr 27 13:46:15 2011 +0800

    release 0.08

diff --git a/Changes b/Changes
index cf7a073..6c60295 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,8 @@ Revision history for App-moduleshere
 
 {{$NEXT}}
 
+    Add --dry-run cmd option
+
 0.07   2010-09-28 09:20:17 CST
 
     code tweak
diff --git a/dist.ini b/dist.ini
index e92b215..f2b63b2 100644
--- a/dist.ini
+++ b/dist.ini
@@ -1,5 +1,5 @@
 name    = App-moduleshere
-version = 0.07
+version = 0.08
 author  = sunnavy <sunnavy at bestpractical.com>
 license = Perl_5
 copyright_holder = Best Practical Solutions 

commit ff7f74ae18b15fa5edd545cfeee9bea9c45067fa
Author: sunnavy <sunnavy at gmail.com>
Date:   Wed Apr 27 13:56:47 2011 +0800

    bump to 0.09

diff --git a/Changes b/Changes
index 6c60295..28bf301 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,8 @@ Revision history for App-moduleshere
 
 {{$NEXT}}
 
+0.08   2011-04-27 13:55:55 CST
+
     Add --dry-run cmd option
 
 0.07   2010-09-28 09:20:17 CST
diff --git a/lib/App/moduleshere.pm b/lib/App/moduleshere.pm
index c91fc7e..4c6c22b 100644
--- a/lib/App/moduleshere.pm
+++ b/lib/App/moduleshere.pm
@@ -2,7 +2,7 @@ package App::moduleshere;
 
 use warnings;
 use strict;
-our $VERSION = '0.08';
+our $VERSION = '0.09';
 
 1;
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list