IO-Easy
view release on metacpan or search on metacpan
lib/IO/Easy/Dir.pm view on Meta::CPAN
package IO::Easy::Dir;
use Class::Easy;
use IO::Easy;
use base qw(IO::Easy);
use File::Spec;
my $FS = 'File::Spec';
use Cwd ();
sub current {
my $pack = shift;
return $pack->new (Cwd::cwd());
}
sub home {
my $pack = shift;
return $pack->new (
$ENV{USERPROFILE} || $ENV{HOME} || (getpwuid($<)) [7]
);
}
sub create {
my $self = shift;
my @path = @_;
my $path = $self->{path};
if (scalar @path) { # create @path into received directory
$path = File::Spec->catdir ($path, @path);
}
my @dirs = File::Spec->splitdir ($path);
foreach my $depth (0 .. scalar @dirs - 1) {
my $dir = File::Spec->join(map {$dirs[$_]} 0..$depth);
mkdir $dir
unless -d $dir;
}
}
sub type {
return 'dir';
}
sub items {
my $self = shift;
my $filter = shift || '';
my $is_regexp = shift || 0;
my $path = $self->{path};
unless ($is_regexp) {
$filter = join '', '\.', $filter, '$';
}
opendir (DH, $path) || die "can't open $path: $!";
my @files = ();
foreach my $file_name (readdir (DH)) {
next if $file_name =~ /^\.+$/;
next if $filter ne '\.$' and $file_name !~ /$filter/i;
my $file = $self->append ($file_name);
next unless -e $file;
push @files, $file->attach_interface;
}
closedir (DH);
return @files;
}
sub rm_tree {
my $self = shift;
my @files = $self->items;
foreach my $file (@files) {
( run in 0.805 second using v1.01-cache-2.11-cpan-13bb782fe5a )