1
package File::Fu::Base;
12
File::Fu::Base - nothing to see here
19
'=' => sub {shift->clone(@_)},
22
'%' => sub {shift->clonedo('append', @_)},
23
# can't overload s/// or accomplish anything with prototypes
24
'&' => sub {shift->clonedo('map', @_)},
26
cmp => sub {"$_[0]" cmp "$_[1]"},
29
'-' => sub {shift->error('-')},
30
'*' => sub {shift->error('*')},
31
nomethod => sub {shift->error($_[2])},
36
my $obj = $obj->clone;
43
bless($clone, ref($self));
44
#carp("clone the ", overload::StrVal($self));
45
foreach my $item (values(%$clone)) {
46
my $ref = ref($item) or next;
48
#warn "clone [@$item]\n";
51
elsif($ref eq 'HASH') {
54
elsif(eval {$item->can('clone')}) {
58
croak("cannot deref $item");
61
#carp("now ", overload::StrVal($clone));
63
} # end subroutine clone definition
64
########################################################################
68
$clone = $self->clonedo($action, @args);
74
my ($action, $arg, $rev) = @_;
75
#carp("clonedo $action", $rev ? ' backwards' : '');
77
return($arg . $self->stringify) if($action eq 'append');
78
croak("$action is invalid in that order");
81
# perl doesn't know how to stringify
82
# TODO how can I tell when this is just a quoted string?
83
#if($action eq 'append' and $arg =~ m/\n/) { return($self->stringify . $arg); }
87
#carp("now ", overload::StrVal($self));
89
} # end subroutine clonedo definition
90
########################################################################
101
croak("$op is not a valid op for a ", ref($self), " object");
102
} # end subroutine error definition
103
########################################################################
107
=head2 r w x o R W X O e z s f d l p S b c t u g k T B M A C
113
foreach my $test (split(//, 'rwxoRWXOezsfdlpSbctugkTBMAC')) {
114
my $subref = eval("sub {-$test shift}");
115
$@ and croak("I broke this -- $@");
117
*{"$test"} = $subref;
120
=head1 File::Spec stuff
122
This needs to be redone.
126
use File::Spec; # GRR
133
# XXX this is immutable, no?
134
File::Spec->file_name_is_absolute($_[0]->stringify);
141
my $rel = $abs->relative;
143
Also, with optional relative-to directory:
145
my $rel = $abs->relative($to);
152
return $self->new(File::Spec->abs2rel($self->stringify,
153
defined($base) ? "$base" : ()
159
Fully resolve any symlinks;
161
my $path = $path->resolve;
168
return $self unless($self->l);
169
my $to = $self->readlink;
170
return $to if($to->is_absolute);
171
$self = $self->new($self->dirname . $to);
173
} # end subroutine resolve definition
174
########################################################################
176
=head2 relative_symlink
178
Where $path and $linkname are both relative to the current directory.
180
$path->relative_symlink($linkname);
184
sub relative_symlink {
188
my $rel = $self->relative($self->new($link)->dirname);
189
return($rel->symlink($link));
190
} # end subroutine relative_symlink definition
191
########################################################################
195
Update the file timestamps.
197
$file->utime($atime, $mtime);
199
Optionally, set both to the same time.
209
@_ or croak("not enough arguments to utime()");
211
my $mt = @_ ? shift(@_) : $at;
215
utime($at, $mt, $self) or croak("cannot utime '$self' $!");
216
} # end subroutine utime definition
217
########################################################################
229
chmod($mode, "$self") or croak("cannot chmod '$self' $!");
230
} # end subroutine chmod definition
231
########################################################################
235
The stat() and lstat() methods both return a File::stat object.
245
my $st = File::stat::stat("$self") or
246
croak("cannot stat '$self' $!");
248
} # end subroutine stat definition
249
########################################################################
253
Same as stat, but does not dereference symlinks.
255
my $st = $obj->lstat;
262
if($self->is_dir and $self->l) {
265
my $st = File::stat::lstat("$self") or
266
croak("cannot lstat '$self' $!");
268
} # end subroutine lstat definition
269
########################################################################
273
Returns true if the two paths are the same. This is by string equality,
274
then (if both paths exist) by device+inode equality.
276
$bool = $path->is_same($other);
284
my $proto = ($self->is_file and $other =~ m#/$#) ?
285
$self->dir_class : $self;
286
$other = $proto->new($other);
288
return(1) if($self eq $other);
289
return(0) if($self->is_dir != $other->is_dir);
291
# TODO just check absolutely?
292
# this currently probably misses non-existent files where the dirname
293
# resolves to the same location.
294
my ($s1, $s2) = map({eval {$_->stat}} $self, $other);
295
return(0) unless($s1 and $s2);
297
$s1->dev eq $s2->dev and
300
} # end subroutine is_same definition
301
########################################################################
305
Eric Wilhelm @ <ewilhelm at cpan dot org>
307
http://scratchcomputing.com/
311
If you found this module on CPAN, please report any bugs or feature
312
requests through the web interface at L<http://rt.cpan.org>. I will be
313
notified, and then you'll automatically be notified of progress on your
314
bug as I make changes.
316
If you pulled this development version from my /svn/, please contact me
321
Copyright (C) 2008 Eric L. Wilhelm, All Rights Reserved.
325
Absolutely, positively NO WARRANTY, neither express or implied, is
326
offered with this software. You use this software at your own risk. In
327
case of loss, no person or entity owes you anything whatsoever. You
332
This program is free software; you can redistribute it and/or modify it
333
under the same terms as Perl itself.
337
# vi:ts=2:sw=2:et:sta