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

? sunnavy sunnavy at bestpractical.com
Sat Apr 24 20:30:38 EDT 2010


The branch, master has been updated
       via  090a3d63e310e724be1aa18ef13fafc38b049a7a (commit)
       via  6e0ed99d7e08574cab1062187cb4bebac159b05c (commit)
      from  a9a2462bd62d2fb40e451fb4abeccf2038da5e01 (commit)

Summary of changes:
 Changes                |    4 +++
 bin/mhere              |   34 +++++++++++++++++++------------
 dist.ini               |    2 +-
 lib/App/moduleshere.pm |    7 ++++-
 t/01.mhere.t           |   51 +++++++++++++++++++++++++++++++++--------------
 5 files changed, 67 insertions(+), 31 deletions(-)

- Log -----------------------------------------------------------------
commit 6e0ed99d7e08574cab1062187cb4bebac159b05c
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Apr 25 08:26:41 2010 +0800

    add -l option

diff --git a/bin/mhere b/bin/mhere
index bedc249..2233326 100755
--- a/bin/mhere
+++ b/bin/mhere
@@ -4,11 +4,28 @@ use warnings;
 use File::Spec::Functions qw/catdir catfile rel2abs/;
 use File::Path 'mkpath';
 use File::Copy qw/copy/;
+use Getopt::Long;
+my %args;
+GetOptions(\%args, 'help|h', 'location|l=s') or exit;
+
 @ARGV = grep { defined } @ARGV;
-undef @ARGV if grep { /^-/ } @ARGV; # force to show usage if found -
+
+if ( $args{help} || ! @ARGV ) {
+    print <<'EOF';
+USAGE: mhere Module [ ... ]
+EXAMPLES:
+    mhere Carp                                    # copy Carp.pm in @INC to cwd
+    mhere Carp CGI                                # copy both Carp.pm and CGI.pm
+    APP_MODULES_HERE=outlib mhere Carp            # copy to outlib dir in cwd
+    mhere -l outlib Carp                          # ditto
+    APP_MODULES_HERE=/tmp/ mhere Carp             # copy to /tmp/
+    mhere -l /tmp/ Carp                           # ditto
+EOF
+    exit;
+}
 
 if (@ARGV) {
-    my $to = $ENV{APP_MODULES_HERE} || '.';
+    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";
@@ -29,7 +46,8 @@ if (@ARGV) {
 
             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";
+                warn
+                  "failed to make path $here: it exists but not a directory\n";
                 next;
             }
 
@@ -50,13 +68,3 @@ if (@ARGV) {
         print "0 modules are copied\n";
     }
 }
-else {
-    print <<'EOF';
-USAGE: mhere Module [ ... ]
-EXAMPLES:
-    mhere Carp                                    # copy Carp.pm in @INC to cwd
-    mhere Carp CGI                                # copy both Carp.pm and CGI.pm
-    APP_MODULES_HERE=outlib mhere Carp            # copy to outlib dir in cwd
-    APP_MODULES_HERE=/tmp/ mhere Carp             # copy to /tmp/
-EOF
-}
diff --git a/lib/App/moduleshere.pm b/lib/App/moduleshere.pm
index 9b280e8..8f8cb04 100644
--- a/lib/App/moduleshere.pm
+++ b/lib/App/moduleshere.pm
@@ -17,12 +17,15 @@ App::moduleshere - copy modules(.pm) to cwd or somewhere
     mhere Carp                                    # copy Carp.pm in @INC to cwd
     mhere Carp CGI                                # copy both Carp.pm and CGI.pm
     APP_MODULES_HERE=outlib mhere Carp            # copy to outlib dir in cwd
+    mhere -l outlib Carp                          # ditto
     APP_MODULES_HERE=/tmp/ mhere Carp             # copy to /tmp/
+    mhere -l /tmp/ Carp                           # ditto
 
 =head1 DESCRIPTION
 
 This small script(C<mhere>) helps you copy modules to somewhere you like.
-by default, it will copy to your current working directory.
+The precedence order is: C<-l>, env C<APP_MODULES_HERE> and cwd.
+By default, it will copy to cwd.
 
 It's first written when I tried to trace a bug in one of my modules which 
 led me to the other module(let's call it C<Foo> here) in C<@INC>.
diff --git a/t/01.mhere.t b/t/01.mhere.t
index 5c7f620..f1ee4b6 100644
--- a/t/01.mhere.t
+++ b/t/01.mhere.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 9;
+use Test::More tests => 11;
 use File::Temp 'tempdir';
 use FindBin;
 use File::Spec::Functions qw/catfile updir/;
@@ -15,7 +15,9 @@ EXAMPLES:
     mhere Carp                                    # copy Carp.pm in @INC to cwd
     mhere Carp CGI                                # copy both Carp.pm and CGI.pm
     APP_MODULES_HERE=outlib mhere Carp            # copy to outlib dir in cwd
+    mhere -l outlib Carp                          # ditto
     APP_MODULES_HERE=/tmp/ mhere Carp             # copy to /tmp/
+    mhere -l /tmp/ Carp                           # ditto
 EOF
 
 is( `$^X $mhere`,        $usage, 'mhere without args shows usage' );
@@ -29,21 +31,17 @@ is(
     'mhere File::Spec::Functions'
 );
 
-open my $ori_fh, '<', $INC{'strict.pm'} or die $!;
-open my $new_fh, '<', catfile( $dir, 'strict.pm' ) or die $!;
-
-{
-    local $/;
-    is( <$ori_fh>, <$new_fh>, 'copied strict.pm is indeed a copy' )
-}
-
-open $ori_fh, '<', $INC{'File/Spec/Functions.pm'} or die $!;
-open $new_fh, '<', catfile( $dir, 'File', 'Spec', 'Functions.pm' ) or die $!;
+compare_files(
+    $INC{'strict.pm'},
+    catfile( $dir, 'strict.pm' ),
+    'copied strict.pm is indeed a copy'
+);
 
-{
-    local $/;
-    is( <$ori_fh>, <$new_fh>, 'copied File/Spec/Functions.pm is indeed a copy' )
-}
+compare_files(
+    $INC{'File/Spec/Functions.pm'},
+    catfile( $dir, 'File', 'Spec', 'Functions.pm' ),
+    'copied File/Spec/Functions.pm is indeed a copy'
+);
 
 is(
     `$^X $mhere strict File::Spec::Functions`,
@@ -58,3 +56,26 @@ is(
     "don't copy if the source and destination are the same path"
 );
 
+my $another_dir = tempdir( CLEANUP => 1 );
+is(
+    `$^X $mhere -l $another_dir strict`,
+    'copied module(s): strict' . "\n",
+    'mhere -l $another_dir strict'
+);
+compare_files(
+    $INC{'strict.pm'},
+    catfile( $another_dir, 'strict.pm' ),
+    'copied strict.pm is indeed a copy'
+);
+
+sub compare_files {
+    my ( $a, $b, $msg ) = @_;
+    open my $ori_fh, '<', $a or die $!;
+    open my $new_fh, '<', $b or die $!;
+
+    {
+        local $/;
+        is( <$ori_fh>, <$new_fh>, $msg || "$a and $b have the same content" )
+    }
+}
+

commit 090a3d63e310e724be1aa18ef13fafc38b049a7a
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sun Apr 25 08:29:04 2010 +0800

    update version to 0.05

diff --git a/Changes b/Changes
index dfeea31..4c617a1 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,10 @@ Revision history for App-moduleshere
 
 {{$NEXT}}
 
+0.05   2010-04-25 08:28:41 CST
+
+    Add -l cmd option to set the destination directory
+
 0.04   2010-04-25 07:37:46 CST
 
     Warn if we want a directory but get a plain file.
diff --git a/dist.ini b/dist.ini
index d137c9b..5496588 100644
--- a/dist.ini
+++ b/dist.ini
@@ -1,5 +1,5 @@
 name    = App-moduleshere
-version = 0.04
+version = 0.05
 author  = sunnavy <sunnavy at bestpractical.com>
 license = Perl_5
 copyright_holder = Best Practical Solutions 
diff --git a/lib/App/moduleshere.pm b/lib/App/moduleshere.pm
index 8f8cb04..945d171 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.04';
+our $VERSION = '0.05';
 
 1;
 

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



More information about the Bps-public-commit mailing list