[Pdx-pm] File-Fu v0.0.3 -- ok, % is the inner append
Eric Wilhelm
scratchcomputing at gmail.com
Sat Mar 8 01:00:33 PST 2008
Hi all,
v0.0.3 should be arriving real soon.
http://search.cpan.org/dist/File-Fu
Well, I'm not very happy with what perl gives me to work with in
overloading, but at least I think my operator API has reached the final
state now.
The append operator gets called before the stringify when the append is
happening inside a quoted string, so some basic debugging code caused
me to need to do a lot of debugging...
Before:
my $dir = File::Fu->dir('bar'); # 'bar/'
$dir .= 'baz'; # 'barbaz/'
print "$dir\n"; # "barbaz\n/'
After:
my $dir = File::Fu->dir('bar'); # 'bar/'
$dir %= 'baz'; # 'barbaz/'
print "$dir\n"; # "barbaz\n/'
I was thinking about '*' as the append (because it looks like a fat,
hairy dot), but decided that '%' is easier to pronounce ('mod') and
I'll post-rationalize something about it being symbolic of the
slash-sensitive append if that helps. (The truth is that I code out
loud (in my head) and the best pronunciation I could come up with
for '*' was 'glue', which just elicits thoughts of waiting for it to
dry.)
my $dir = File::Fu->dir("bar"); # "bar/"
my $alsodir = $dir % 'bat'; # "barbat/"
my $subdir = $alsodir / 'baz'; # "barbat/baz/"
my $subdir2 = $dir % 'bat' / 'baz'; # "barbat/baz/"
my $file = $subdir + 'file.txt'; # "barbat/baz/file.txt"
And I may have mentioned the fact that I can't hack '=~ s///', so to
modify just the file part (not to mention "not breaking the object"),
you use &.
$file &= sub {s/^file/pile/};
So, that's all I can do with the operator API in perl 5. If there are
any great ideas, I could probably still break it once more, but
otherwise I think I'm moving on to adding more features to the method
API and will declare it stable pretty soon.
And just one more reason...
use File::Fu;
my @files = File::Fu->dir('lib')->find(sub {
return shift->prune if($_->is_dir and $_->end =~ m/^\.svn$/);
$_->is_file and m/\.pm$/;
});
--Eric
--
If the above message is encrypted and you have lost your pgp key, please
send a self-addressed, stamped lead box to the address below.
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------
More information about the Pdx-pm-list
mailing list