2022-11-16 17:33:08 +00:00
|
|
|
package Directory::Simplify::File;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
require Cwd;
|
2023-07-20 18:29:55 +00:00
|
|
|
use File::Basename qw/ dirname /;
|
2022-11-16 17:33:08 +00:00
|
|
|
|
|
|
|
sub new {
|
2023-07-20 17:37:07 +00:00
|
|
|
my ($class, $rel_name) = @_;
|
2022-11-16 17:33:08 +00:00
|
|
|
my $self = bless {
|
|
|
|
rel_name => $rel_name,
|
|
|
|
name => Cwd::abs_path($rel_name),
|
|
|
|
}, $class;
|
2023-07-20 18:29:55 +00:00
|
|
|
$self->{dirname} = dirname($self->{name});
|
2022-11-16 17:33:08 +00:00
|
|
|
(@{$self}{qw/ dev ino mode nlink uid gid rdev size
|
|
|
|
atime mtime ctime blksize blocks /})
|
|
|
|
= lstat $self->{name};
|
2023-07-20 17:37:27 +00:00
|
|
|
return $self;
|
2022-11-16 17:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-07-20 17:37:27 +00:00
|
|
|
return $self->{_hash};
|
2022-11-16 17:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|