NAME

Sweet::Dir

SYNOPSIS

use Sweet::Dir;

my $dir = Sweet::Dir->new(path => '/path/to/dir');
$dir->create;

say $dir; # /path/to/dir

ATTRIBUTES

path

METHODS

create

$dir->create;

does_not_exists

$dir->create if $dir->does_not_exists;

erase

$dir->erase;

file

Instance of file inside dir. Returns a Sweet::File by default.

my $file = $dir->file('foo.txt');
say $file; # /path/to/dir/foo.txt

Accepts an optional reference to a sub which expects $dir and $name parameters and will be called to build the object reference. For example

use Sweet::File::DSV;

my $file = $dir->file('bar.tsv', sub {
    my ( $dir, $name ) = @_;

    my $file = Sweet::File::DSV->new(
        dir  => $dir,
        name => $name,
        separator => "\t",
    );

    return $file;
});

file_list

Returns a list of files contained in the directory

my @files = @$dir->file_list;

is_a_directory

# Create dir if it does not exists.
$dir->is_a_directory or $dir->create;

sub_dir

my $dir2 = $dir->sub_dir('foo', bar');
# Or pass an arrayref if you prefer.
# my $dir2 = $dir->sub_dir(['foo', bar']);

# Create foo/bar sub directory.
$dir2->create;