1MooseX::Role::Tempdir(3U)ser Contributed Perl DocumentatiMoonoseX::Role::Tempdir(3)
2
3
4
6 MooseX::Role::Tempdir - Moose role providing temporary directory
7 attributes
8
10 version 0.101
11
13 By default, a single 'tmpdir' attribute is provided. It is recursively
14 removed when the object goes out of scope:
15
16 package My::Awesome::Package;
17 use Moose;
18 with 'MooseX::Role::Tempdir';
19
20 ...
21
22 package main;
23 my $thing = My::Awesome::Package->new;
24 open(my $fh, '>', $thing->tmpdir."/somefile") or die "problem: $!";
25
26 You can also use parameters for more directory attributes and/or
27 options:
28
29 with 'MooseX::Role::Tempdir' => {
30 dirs => [ qw/tmpdir workdir fundir/ ],
31 tmpdir_opts => { DIR => '/my/alternate/tmp' },
32 };
33
34 ...
35
36 open(my $fh, '>', $thing->fundir."/somefile") or die "problem: $!";
37
38 Or be even more explicit:
39
40 with 'MooseX::Role::Tempdir' => {
41 dirs => {
42 tmpdir => { TEMPLATE => 'fooXXXXX' },
43 permadir => { DIR => '/some/other/dir', CLEANUP => 0 },
44 },
45 tmpdir_opts => { DIR => '/default/dir' },
46 }
47
48 ...
49
50 open(my $fh, '>', $thing->nameddir."/somefile") or die "problem: $!";
51
53 For each "dir" parameter (by default, only "tmpdir"), a temporary
54 directory attribute is lazily created using "newdir" in File::Temp. The
55 default options to "newdir" will apply, unless overriden by further
56 parameters. This means the directory and its contents will be removed
57 when the object using this role goes out of scope.
58
60 Parameters may be given to this role as described in
61 MooseX::Role::Parameterized::Tutorial.
62
63 "dirs"
64 A "dirs" parameter may be an array or hash reference. An array
65 reference will create a temporary directory attribute for each value in
66 the array. A hash reference creates an attribute for each key, and its
67 value must be a hash reference of temporary directory options (see
68 "newdir" in File::Temp).
69
70 "tmpdir_opts"
71 This parameter sets temporary directory options for all attributes,
72 unless overridden for a specific directory as described above (with a
73 "dirs" hashref).
74
76 Brad Barden <b at 13os.net>
77
79 This software is Copyright (c) 2018 by Brad Barden.
80
81 This is free software, licensed under:
82
83 The ISC License
84
85
86
87perl v5.32.1 2021-01-27 MooseX::Role::Tempdir(3)