MooseX:...:Tempdir(3)
β¨ NAME β¨
MooseX::Role::Tempdir β it's a Moose role, and it hands you temporary directory attributes like it's nothing π
(this one's from the User Contributed Perl Documentation, MooseX:...:Tempdir(3), iykyk)
πΈ VERSION πΈ
version 0.101 β yes bestie, we're on 0.101, no cap
π SYNOPSIS π
okay so by default you get exactly one tmpdir attribute, and when your object goes out of scope the whole thing gets recursively yeeted π. Obsessed:
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: $!";
but wait, there's more π you can pass parameters to get extra 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, main character energy fr fr:
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 every dir parameter (and by default, that's just tmpdir, the one and only π), a temporary directory attribute gets lazily created using newdir from File::Temp. The default options for newdir apply unless something else overrides them. Which means: when the object using this role goes out of scope, the directory and everything inside it gets removed. Gone. Poof. β¨
π PARAMETERS π
you can hand parameters to this role exactly like it says in MooseX::Role::Parameterized::Tutorial, bestie π«Ά
π dirs
a dirs parameter can be an array reference or a hash reference, and it's giving versatility:
- array reference β‘οΈ makes a temporary directory attribute for each value in the array
- hash reference β‘οΈ makes an attribute for each key, and each value has to be a hash reference of temporary directory options (peep
newdirinFile::Temp)
π tmpdir_opts
this parameter sets temporary directory options for all the attributes β unless a specific directory overrides it, which you do with a dirs hashref like we said above π
π AUTHOR π
Brad Barden <b at 13os.net> β we stan π
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2018 by Brad Barden.
This is free software, licensed under:
The ISC License
and that's the whole page, bestie π this was perl v5.42.0, dated 2025-07-25, from MooseX:...:Tempdir(3) β go make some temp directories, slay, and let them clean themselves up π§β¨
π¦ where this page comes from
- fedora 43: perl-MooseX-Role-Tempdir 0.101-20.fc43 Β· ISC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms