Subject: | File::Fu::Dir->parts does not handle -#'s |
perl -MFile::Fu -e 'print File::Fu->file(q{/home/benh/git/ext/File-Fu/t/
slice.t})->dir->absolute->slice(0,-2)->stringify, qq{\n}'
/home/benh/git/ext/File-Fu/t/
Subject: | 0001-fixing-the-ability-to-specify-for-parts-slice.patch |
From 0b5a165cb8da982089466c916d6561aac79c4039 Mon Sep 17 00:00:00 2001
From: ben hengst <notbenh@cpan.org>
Date: Mon, 3 Aug 2009 15:55:12 -0700
Subject: [ULOGD PATCH 1/1] fixing the ability to specify -# for parts/slice
Signed-off-by: ben hengst <notbenh@cpan.org>
---
:100644 100644 379e871... 2f8567b... M lib/File/Fu/Dir.pm
:000000 100644 0000000... 9f92f1d... A t/slice.t
lib/File/Fu/Dir.pm | 2 +-
t/slice.t | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/lib/File/Fu/Dir.pm b/lib/File/Fu/Dir.pm
index 379e871..2f8567b 100644
--- a/lib/File/Fu/Dir.pm
+++ b/lib/File/Fu/Dir.pm
@@ -301,7 +301,7 @@ sub parts {
@want or return(@{$self->{dirs}});
if(@want == 2) {
if($want[1] < 0) {
- $want[1] = $#{$self->{dirs}};
+ $want[1] = $#{$self->{dirs}} + $want[1];
}
@want = $want[0]..$want[1];
}
diff --git a/t/slice.t b/t/slice.t
new file mode 100644
index 0000000..9f92f1d
--- /dev/null
+++ b/t/slice.t
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More qw{no_plan};
+use File::Fu;
+
+sub chopshop {
+ join '/', splice(@{[ split /\//, shift ]},0,-1)
+}
+
+is( File::Fu->file(__FILE__)->dir->stringify, q{t/} );
+is( chopshop( File::Fu->file(__FILE__)->dir->absolute->bare ),
+ File::Fu->file(__FILE__)->dir->absolute->slice(0,-1)->bare,
+);
+
--
1.6.3.3