r53569 - in /branches/upstream/libfile-fu-perl/current: Changes MANIFEST MANIFEST.SKIP META.yml lib/File/Fu.pm lib/File/Fu/Base.pm lib/File/Fu/Dir.pm lib/File/Fu/Dir/Temp.pm lib/File/Fu/File.pm lib/File/Fu/File/Temp.pm t/findknob.t t/slice.t todo
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Wed Mar 3 17:09:50 UTC 2010
Author: jawnsy-guest
Date: Wed Mar 3 17:09:36 2010
New Revision: 53569
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=53569
Log:
[svn-upgrade] Integrating new upstream version, libfile-fu-perl (0.0.7)
Added:
branches/upstream/libfile-fu-perl/current/t/findknob.t (with props)
branches/upstream/libfile-fu-perl/current/t/slice.t (with props)
Modified:
branches/upstream/libfile-fu-perl/current/Changes
branches/upstream/libfile-fu-perl/current/MANIFEST
branches/upstream/libfile-fu-perl/current/MANIFEST.SKIP
branches/upstream/libfile-fu-perl/current/META.yml
branches/upstream/libfile-fu-perl/current/lib/File/Fu.pm
branches/upstream/libfile-fu-perl/current/lib/File/Fu/Base.pm
branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir.pm
branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir/Temp.pm
branches/upstream/libfile-fu-perl/current/lib/File/Fu/File.pm
branches/upstream/libfile-fu-perl/current/lib/File/Fu/File/Temp.pm
branches/upstream/libfile-fu-perl/current/todo
Modified: branches/upstream/libfile-fu-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/Changes?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/Changes (original)
+++ branches/upstream/libfile-fu-perl/current/Changes Wed Mar 3 17:09:36 2010
@@ -1,4 +1,14 @@
Revision history for File-Fu
+
+v0.0.7 2010-02-27
+
+ * much better documentation for File::Fu::Dir::find()
+
+ * added rename() for Dir objects
+
+ * allow Dir parts() and slice() to have negative indices
+
+ * improvements to temp_dir
v0.0.6 2009-01-31
Modified: branches/upstream/libfile-fu-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/MANIFEST?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/MANIFEST (original)
+++ branches/upstream/libfile-fu-perl/current/MANIFEST Wed Mar 3 17:09:36 2010
@@ -6,7 +6,7 @@
lib/File/Fu/Dir/Temp.pm
lib/File/Fu/File.pm
lib/File/Fu/File/Temp.pm
-MANIFEST This list of files
+MANIFEST
MANIFEST.SKIP
META.yml
README
@@ -17,8 +17,10 @@
t/end_bits.t
t/errors.t
t/finder.t
+t/findknob.t
t/global.t
t/links.t
+t/slice.t
t/slurp.t
t/temp.t
todo
Modified: branches/upstream/libfile-fu-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/MANIFEST.SKIP?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/MANIFEST.SKIP (original)
+++ branches/upstream/libfile-fu-perl/current/MANIFEST.SKIP Wed Mar 3 17:09:36 2010
@@ -35,3 +35,4 @@
\bcover_db\b
TODO
+^MYMETA.yml$
Modified: branches/upstream/libfile-fu-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/META.yml?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/META.yml (original)
+++ branches/upstream/libfile-fu-perl/current/META.yml Wed Mar 3 17:09:36 2010
@@ -1,6 +1,6 @@
---
name: File-Fu
-version: v0.0.6
+version: v0.0.7
author:
- 'Eric Wilhelm @ <ewilhelm at cpan dot org>'
abstract: file and directory objects
@@ -10,38 +10,40 @@
homepage: http://scratchcomputing.com/
license: http://dev.perl.org/licenses/
repository: http://svn.scratchcomputing.com/File-Fu/trunk
+build_requires:
+ Module::Build: 0.26
+ Test::More: 0
requires:
Class::Accessor::Classy: v0.9.0
File::Spec: 0
File::Which: 0.05
IO::File: 0
-build_requires:
- Module::Build: 0.26
- Test::More: 0
+configure_requires:
+ Module::Build: 0.35
provides:
File::Fu:
file: lib/File/Fu.pm
- version: v0.0.6
+ version: v0.0.7
File::Fu::Base:
file: lib/File/Fu/Base.pm
- version: v0.0.6
+ version: v0.0.7
File::Fu::Dir:
file: lib/File/Fu/Dir.pm
- version: v0.0.6
+ version: v0.0.7
File::Fu::Dir::FindKnob:
file: lib/File/Fu/Dir.pm
File::Fu::Dir::Temp:
file: lib/File/Fu/Dir/Temp.pm
- version: v0.0.6
+ version: v0.0.7
File::Fu::Dir::Token:
file: lib/File/Fu/Dir.pm
File::Fu::File:
file: lib/File/Fu/File.pm
- version: v0.0.6
+ version: v0.0.7
File::Fu::File::Temp:
file: lib/File/Fu/File/Temp.pm
- version: v0.0.6
-generated_by: Module::Build version 0.3103
+ version: v0.0.7
+generated_by: Module::Build version 0.350201
meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.2.html
- version: 1.2
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
Modified: branches/upstream/libfile-fu-perl/current/lib/File/Fu.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/lib/File/Fu.pm?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/lib/File/Fu.pm (original)
+++ branches/upstream/libfile-fu-perl/current/lib/File/Fu.pm Wed Mar 3 17:09:36 2010
@@ -1,5 +1,5 @@
package File::Fu;
-$VERSION = v0.0.6;
+$VERSION = v0.0.7;
use warnings;
use strict;
Modified: branches/upstream/libfile-fu-perl/current/lib/File/Fu/Base.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/lib/File/Fu/Base.pm?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/lib/File/Fu/Base.pm (original)
+++ branches/upstream/libfile-fu-perl/current/lib/File/Fu/Base.pm Wed Mar 3 17:09:36 2010
@@ -1,5 +1,5 @@
package File::Fu::Base;
-$VERSION = v0.0.6;
+$VERSION = v0.0.7;
use warnings;
use strict;
@@ -230,6 +230,25 @@
} # end subroutine chmod definition
########################################################################
+=head2 rename
+
+Calls the builtin rename() on the $path and returns a new object with
+that name.
+
+ $path = $path->rename($newname);
+
+=cut
+
+sub rename :method {
+ my $self = shift;
+ my ($name) = @_;
+
+ rename($self, $name) or
+ croak("cannot rename '$self' to '$name' $!");
+ return($self->new($name));
+} # end subroutine rename definition
+########################################################################
+
=head1 Stat Object
The stat() and lstat() methods both return a File::stat object.
Modified: branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir.pm?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir.pm (original)
+++ branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir.pm Wed Mar 3 17:09:36 2010
@@ -1,5 +1,5 @@
package File::Fu::Dir;
-$VERSION = v0.0.6;
+$VERSION = v0.0.7;
use warnings;
use strict;
@@ -166,7 +166,7 @@
The trailing slash causes trouble when trying to address a symlink to a
directory via a dir object. Thus, C<-l $dir> doesn't work, but
-C<$dir->l> does.
+C<$dir-E<gt>l> does the same thing as C<-l $dir-E<gt>bare>.
=cut
@@ -287,11 +287,13 @@
my @parts = $dir->parts(0..2);
The returned parts will be contiguous, but the request can be a
-two-element list (and can also end at -1.)
+two-element list (and can also start or end at negative indices.)
my @parts = $dir->parts(3, 7);
my @parts = $dir->parts(3, -1);
+
+ my @parts = $dir->parts(-5, -1);
=cut
@@ -300,8 +302,11 @@
my @want = @_;
@want or return(@{$self->{dirs}});
if(@want == 2) {
- if($want[1] < 0) {
- $want[1] = $#{$self->{dirs}};
+ foreach my $end (@want) {
+ $end = $#{$self->{dirs}} + 1 + $end if($end < 0);
+ }
+ if($want[0] > $want[1]) {
+ croak("first endpoint '$want[0]' is after last '$want[1]'");
}
@want = $want[0]..$want[1];
}
@@ -576,9 +581,39 @@
=head2 find
-Not the same as File::Find::find().
-
- my @files = $dir->find(sub {m/foo/});
+Recursively search a directory's contents for items where the supplied
+coderef (matcher) returns true. The matcher will be invoked with the
+topic (C<$_>) set to the current path (which is either a Dir or File
+object.) The return values will be File::Fu::File or File::Fu::Dir
+objects.
+
+If your matcher returns true, the topic will be added to the return
+values.
+
+ my @paths = $dir->find(sub {m/foo/});
+
+There is a knob for controlling recursion, which is the first argument
+to your matcher.
+
+ my @pm_files = $dir->find(sub {
+ return shift->prune
+ if($_->is_dir and $_->part(-1) =~ m/^\.svn$/);
+ $_->is_file and m/\.pm$/;
+ });
+
+=over
+
+=item Differences from File::Find::find()
+
+The invocant (C<$dir> aka '.') is not examined (because this is an
+object method, there is always only one starting path.)
+
+The topic is always absolute in the same sense as the invocant. That
+is, if C<$dir> is relative to your current directory, then so are the
+topics and return values. If C<$dir> is absolute, so are the topics and
+return values.
+
+=back
=cut
@@ -597,7 +632,9 @@
=head2 finder
-Returns an iterator for finding files.
+Returns an iterator for finding files. This iterator does everything
+that find() does, but returns one path at a time. Returns undef when
+exhausted and zero when it is just taking a break.
my $subref = $dir->finder(sub {$_->is_file and $_->file =~ m/foo/});
@@ -605,22 +642,17 @@
while(defined(my $path = $subref->())) {
$path or next; # 0 means 'not done yet'
- # do something with $path (is a file or dir object)
+ # do something with $path (a file or dir object)
}
-And there is a knob:
-
- my $finder = $dir->finder(sub {
- return shift->prune
- if($_->is_dir and $_->part(-1) =~ m/^\.svn$/);
- $_->is_file and m/\.pm$/;
- });
+The find() method is implemented in terms of finder() by simply using a
+while() loop and accumulating the return values.
=cut
sub finder {
my $self = shift;
- my ($matcher, @opt) = @_;
+ my ($matcher, @opt) = @_; # TODO support options e.g. loops
my %opt = (all => 1);
@@ -637,9 +669,8 @@
($self, $reader) = ($path, undef);
}
local $_ = $path;
- #warn " check $path\n";
my $ok = $matcher->(my $knob = File::Fu::Dir::FindKnob->new);
- if($knob->pruned) {
+ if($knob->pruned and not $path->l) { # XXX nofollow assumption
($self, $reader) = @{pop(@stack)};
}
if($ok) {
@@ -659,6 +690,24 @@
} # end subroutine finder definition
########################################################################
+=head2 The FindKnob object
+
+The FindKnob object allows you to control the next steps of find().
+Methods called on it will typically return a value which also makes
+sense as a return value of your matcher sub. Thus the idiom:
+
+ $dir->find(sub {return shift->prune if(condition); ...})
+
+=over
+
+=item prune
+
+Do not recurse into the topic directory. Returns false.
+
+=back
+
+=cut
+
BEGIN {
package File::Fu::Dir::FindKnob;
use Class::Accessor::Classy;
Modified: branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir/Temp.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir/Temp.pm?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir/Temp.pm (original)
+++ branches/upstream/libfile-fu-perl/current/lib/File/Fu/Dir/Temp.pm Wed Mar 3 17:09:36 2010
@@ -1,5 +1,5 @@
package File::Fu::Dir::Temp;
-$VERSION = v0.0.6;
+$VERSION = v0.0.7;
use warnings;
use strict;
@@ -73,6 +73,20 @@
}} # end subroutine new definition
########################################################################
+=head2 chdir
+
+ my $dir = $dir->chdir;
+
+=cut
+
+sub chdir {
+ my $self = shift;
+
+ my $dir = $self->SUPER::chdir;
+ $dir->{temp_parent} = $self;
+ return($dir);
+} # chdir ##############################################################
+
=for nit head2 clone
Because clone doesn't call new :-/
$not_temp = $temp->clone;
@@ -85,6 +99,21 @@
bless($self, $self->dir_class);
} # end subroutine clone definition
########################################################################
+
+=head2 rename
+
+Same as the base rename(), but promotes the temp dir to a regular Dir
+object (prevents any cleanup actions.)
+
+ $temp = $temp->rename($dest);
+
+=cut
+
+sub rename {
+ my $self = shift->SUPER::rename(@_);
+ bless($self, $self->dir_class);
+ return($self);
+}
# TODO File::Fu->temp_dir->chdir causes immediate deletion?
@@ -115,7 +144,8 @@
sub DESTROY {
my $self = shift;
- # ? should this have: return unless($self->auto_delete);
+ # ? should this have:
+ return unless($self->auto_delete);
# forked case
return unless($$ == $self->{_proc});
Modified: branches/upstream/libfile-fu-perl/current/lib/File/Fu/File.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/lib/File/Fu/File.pm?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/lib/File/Fu/File.pm (original)
+++ branches/upstream/libfile-fu-perl/current/lib/File/Fu/File.pm Wed Mar 3 17:09:36 2010
@@ -1,5 +1,5 @@
package File::Fu::File;
-$VERSION = v0.0.6;
+$VERSION = v0.0.7;
use warnings;
use strict;
@@ -319,25 +319,6 @@
# TODO
# my $link = $file->dwimlink(absolute|relative|samedir => $linkname);
-
-=head2 rename
-
-Calls the builtin rename() on the $file and returns a new object with
-that name.
-
- $file = $file->rename($newname);
-
-=cut
-
-sub rename :method {
- my $self = shift;
- my ($name) = @_;
-
- rename($self, $name) or
- croak("cannot rename '$self' to '$name' $!");
- return($self->new($name));
-} # end subroutine rename definition
-########################################################################
=head2 unlink
Modified: branches/upstream/libfile-fu-perl/current/lib/File/Fu/File/Temp.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/lib/File/Fu/File/Temp.pm?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/lib/File/Fu/File/Temp.pm (original)
+++ branches/upstream/libfile-fu-perl/current/lib/File/Fu/File/Temp.pm Wed Mar 3 17:09:36 2010
@@ -1,5 +1,5 @@
package File::Fu::File::Temp;
-$VERSION = v0.0.6;
+$VERSION = v0.0.7;
use warnings;
use strict;
Added: branches/upstream/libfile-fu-perl/current/t/findknob.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/t/findknob.t?rev=53569&op=file
==============================================================================
--- branches/upstream/libfile-fu-perl/current/t/findknob.t (added)
+++ branches/upstream/libfile-fu-perl/current/t/findknob.t Wed Mar 3 17:09:36 2010
@@ -1,0 +1,37 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More no_plan =>;
+
+use File::Fu;
+
+my $topdir = File::Fu->dir('tmp.' . $$);
+END { $topdir->remove; }
+
+$topdir->mkdir;
+($topdir+$_)->touch for('a'..'z');
+my $foo = $topdir->subdir("foo");
+$foo->mkdir;
+$foo->basename->symlink($topdir/'link');
+($foo+$_)->touch for('a'..'z');
+
+# bah!
+my $x = do {
+ my @files = $topdir->list;
+ my ($i) = grep({$files[$_]->basename eq 'foo/'} 0..$#files);
+ $_->unlink for(@files[($i+1)..$#files]);
+ #warn join("|", $topdir->contents);
+ $files[0]->basename;
+};
+
+my @files = $topdir->find(sub {
+ #warn $_;
+ $_->is_dir and return(shift->prune);
+ $_->basename eq $x
+});
+
+is(scalar(@files), 1);
+
+# vim:ts=2:sw=2:et:sta
Propchange: branches/upstream/libfile-fu-perl/current/t/findknob.t
------------------------------------------------------------------------------
svn:executable = *
Added: branches/upstream/libfile-fu-perl/current/t/slice.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/t/slice.t?rev=53569&op=file
==============================================================================
--- branches/upstream/libfile-fu-perl/current/t/slice.t (added)
+++ branches/upstream/libfile-fu-perl/current/t/slice.t Wed Mar 3 17:09:36 2010
@@ -1,0 +1,18 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More qw{no_plan};
+
+use File::Fu;
+
+my $dir = File::Fu->dir('foo/bar/baz/bort/');
+is($dir->slice(0,3), 'foo/bar/baz/bort/');
+is($dir->slice(0,-1), 'foo/bar/baz/bort/');
+is($dir->slice(0,-2), 'foo/bar/baz/');
+is($dir->slice(0,-3), 'foo/bar/');
+is($dir->slice(-2,-1), 'baz/bort/');
+
+
+# vim:ts=2:sw=2:et:sta
Propchange: branches/upstream/libfile-fu-perl/current/t/slice.t
------------------------------------------------------------------------------
svn:executable = *
Modified: branches/upstream/libfile-fu-perl/current/todo
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libfile-fu-perl/current/todo?rev=53569&op=diff
==============================================================================
--- branches/upstream/libfile-fu-perl/current/todo (original)
+++ branches/upstream/libfile-fu-perl/current/todo Wed Mar 3 17:09:36 2010
@@ -11,9 +11,12 @@
$file->dirname->map([qw(wav flac)], 0);
($file &= λ{s/wav/flac/})->dirname &= λ{s/wav/flac/};
$file->map(λ{s/\.wav$/flac/})->dirname->map(λ{s/wav/flac/}, 0);
-o $dir + 'foo/bar' problem
+x $dir + 'foo/bar' problem
o freedesktop
o home
o mimeinfo
o basedir
o resolve() symlink chase-down
+
+o URI support?
+ - is that just a subclass with a volume-like thing?
More information about the Pkg-perl-cvs-commits
mailing list