MooseX:...:Tempdir(3)

πŸ“¦
version 0.101 Β· 2 versions
, in fedora 43

✨ 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 newdir in File::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 🌟


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