[Bps-public-commit] app-moduleshere branch, master, updated. 9a7be7ee496153bc54bea02f8f79a9307d52dfc1
? sunnavy
sunnavy at bestpractical.com
Mon Sep 27 07:27:10 EDT 2010
The branch, master has been updated
via 9a7be7ee496153bc54bea02f8f79a9307d52dfc1 (commit)
from b5ded493734abfd77219e624dcbba77c1e5b1fc7 (commit)
Summary of changes:
Changes | 5 +++++
bin/mhere | 22 ++++++++++++++++++----
dist.ini | 2 +-
lib/App/moduleshere.pm | 3 ++-
t/01.mhere.t | 23 ++++++++++++++++++++++-
5 files changed, 48 insertions(+), 7 deletions(-)
- Log -----------------------------------------------------------------
commit 9a7be7ee496153bc54bea02f8f79a9307d52dfc1
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Sep 27 19:30:07 2010 +0800
add -r option
diff --git a/Changes b/Changes
index 4c617a1..4994792 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,11 @@ Revision history for App-moduleshere
{{$NEXT}}
+0.06 2010-09-27 19:28:21 CST
+
+ Add -r cmd option to copy modules and modules under them, e.g.
+ "-r Carp" will copy both Carp.pm and Carp/Heavy.pm
+
0.05 2010-04-25 08:28:41 CST
Add -l cmd option to set the destination directory
diff --git a/bin/mhere b/bin/mhere
index 2233326..a170152 100755
--- a/bin/mhere
+++ b/bin/mhere
@@ -1,12 +1,15 @@
#!/usr/bin/env perl
use strict;
use warnings;
-use File::Spec::Functions qw/catdir catfile rel2abs/;
+use File::Spec::Functions qw/catdir catfile rel2abs splitpath/;
use File::Path 'mkpath';
use File::Copy qw/copy/;
+use File::Copy::Recursive 'rcopy';
+$File::Copy::Recursive::KeepMode = 0;
+
use Getopt::Long;
my %args;
-GetOptions(\%args, 'help|h', 'location|l=s') or exit;
+GetOptions(\%args, 'help|h', 'location|l=s', 'recursive|r') or exit;
@ARGV = grep { defined } @ARGV;
@@ -15,6 +18,7 @@ if ( $args{help} || ! @ARGV ) {
USAGE: mhere Module [ ... ]
EXAMPLES:
mhere Carp # copy Carp.pm in @INC to cwd
+ mhere -r Carp # copy Carp and all under it.
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
@@ -37,7 +41,7 @@ if (@ARGV) {
my @parts = split /::/, $mod;
my $inc = join( '/', @parts ) . '.pm';
my $source = $INC{$inc};
- warn "failed to fild 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"
@@ -55,7 +59,17 @@ if (@ARGV) {
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";
+ or warn "failed to copy $source to $here: $!\n" and next;
+
+ if ( $args{recursive} ) {
+ my $dir = $source;
+ $dir =~ s/\.pm$//;
+ my $last_name = (splitpath $dir)[-1];
+ if ( -e $dir ) {
+ rcopy( $dir, catdir( $here, $last_name ) )
+ or warn "failed to copy $dir to $here: $!\n" and next;
+ }
+ }
push @success, $mod;
}
}
diff --git a/dist.ini b/dist.ini
index fa102c5..79311d0 100644
--- a/dist.ini
+++ b/dist.ini
@@ -1,5 +1,5 @@
name = App-moduleshere
-version = 0.05
+version = 0.06
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 524ec3b..3893811 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.05';
+our $VERSION = '0.06';
1;
@@ -15,6 +15,7 @@ App::moduleshere - copy modules(.pm) to cwd or somewhere
=head1 SYNOPSIS
mhere Carp # copy Carp.pm in @INC to cwd
+ mhere -r Carp # copy Carp and all under it.
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
diff --git a/t/01.mhere.t b/t/01.mhere.t
index f1ee4b6..fd29669 100644
--- a/t/01.mhere.t
+++ b/t/01.mhere.t
@@ -1,10 +1,11 @@
use strict;
use warnings;
-use Test::More tests => 11;
+use Test::More tests => 14;
use File::Temp 'tempdir';
use FindBin;
use File::Spec::Functions qw/catfile updir/;
+use Carp;
my $mhere = catfile( $FindBin::Bin, updir, '/bin/mhere' );
my $dir = tempdir( CLEANUP => 1 );
@@ -13,6 +14,7 @@ my $usage = <<'EOF';
USAGE: mhere Module [ ... ]
EXAMPLES:
mhere Carp # copy Carp.pm in @INC to cwd
+ mhere -r Carp # copy Carp and all under it.
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
@@ -49,6 +51,25 @@ is(
'mhere strict, File::Spec::Functions'
);
+is(
+ `$^X $mhere Carp -r`,
+ 'copied module(s): Carp' . "\n",
+ 'mhere Carp'
+);
+
+compare_files(
+ $INC{'Carp.pm'},
+ catfile( $dir, 'Carp.pm' ),
+ 'copied Carp.pm is indeed a copy'
+);
+
+compare_files(
+ $INC{'Carp/Heavy.pm'},
+ catfile( $dir, 'Carp', 'Heavy.pm' ),
+ 'copied Carp/Heavy.pm is indeed a copy'
+);
+
+
# test if the source and the destination is the same file
is(
`$^X -I$dir $mhere strict`,
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list