The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::Role::Tempdir - Moose role providing temporary directory attributes

VERSION

version 0.101

SYNOPSIS

By default, a single 'tmpdir' attribute is provided. It is recursively removed when the object goes out of scope:

    package My::Awesome::Package;
    use Moose;
    with 'MooseX::Role::Tempdir';

    ...

    package main;
    my $thing = My::Awesome::Package->new;
    open(my $fh, '>', $thing->tmpdir."/somefile") or die "problem: $!";

You can also use parameters for more directory attributes and/or options:

    with 'MooseX::Role::Tempdir' => {
      dirs => [ qw/tmpdir workdir fundir/ ],
      tmpdir_opts => { DIR => '/my/alternate/tmp' },
    };

    ...

    open(my $fh, '>', $thing->fundir."/somefile") or die "problem: $!";

Or be even more explicit:

    with 'MooseX::Role::Tempdir' => {
      dirs => {
        tmpdir => { TEMPLATE => 'fooXXXXX' },
        permadir => { DIR => '/some/other/dir', CLEANUP => 0 },
      },
      tmpdir_opts => { DIR => '/default/dir' },
    }

    ...

    open(my $fh, '>', $thing->nameddir."/somefile") or die "problem: $!";

ATTRIBUTES

For each dir parameter (by default, only tmpdir), a temporary directory attribute is lazily created using "newdir" in File::Temp. The default options to newdir will apply, unless overriden by further parameters. This means the directory and its contents will be removed when the object using this role goes out of scope.

PARAMETERS

Parameters may be given to this role as described in MooseX::Role::Parameterized::Tutorial.

"dirs"

A dirs parameter may be an array or hash reference. An array reference will create a temporary directory attribute for each value in the array. A hash reference creates an attribute for each key, and its value must be a hash reference of temporary directory options (see "newdir" in File::Temp).

"tmpdir_opts"

This parameter sets temporary directory options for all attributes, unless overridden for a specific directory as described above (with a dirs hashref).

AUTHOR

Brad Barden <b at 13os.net>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2018 by Brad Barden.

This is free software, licensed under:

  The ISC License