simplify_static_dir/lib/Directory/Simplify/File.pm
Dan Church 02f97c2a90
Refactor 'more_linked'
- Make method static.
- Don't call dirname() in sort block. Relegate this to *::File.
  This carries with it a slight performance boost; calculate dirname of
  file only once upon instantiation, instead of (N log N) * 2 times.
- Move determination of read-only entries higher.
  This carries with it a slight performance boost as well, no longer
  redundantly testing directory write-ability N log N times (reduced to
  N times), and no longer requires memory to keep track of warnings
  issued.
2023-07-20 15:09:58 -05:00

33 lines
750 B
Perl

package Directory::Simplify::File;
# vi: et sts=4 sw=4 ts=4
use strict;
use warnings;
require Cwd;
use File::Basename qw/ dirname /;
sub new {
my $class = shift;
my $rel_name = shift;
my $self = bless {
rel_name => $rel_name,
name => Cwd::abs_path($rel_name),
}, $class;
$self->{dirname} = dirname($self->{name});
(@{$self}{qw/ dev ino mode nlink uid gid rdev size
atime mtime ctime blksize blocks /})
= lstat $self->{name};
$self
}
sub hash {
my $self = shift;
unless (defined $self->{_hash}) {
require Digest::SHA;
my $ctx = Digest::SHA->new;
$ctx->addfile($self->{name});
$self->{_hash} = $ctx->hexdigest;
}
$self->{_hash}
}
1;