| 1 | package Acme::CPANModules::GettingTempDir; | ||
| 2 | |||
| 3 | 1 | our $DATE = '2019-01-09'; # DATE | |
| 4 | 1 | our $VERSION = '0.001'; # VERSION | |
| 5 | |||
| 6 | 1 | our $LIST = { | |
| 7 | summary => 'Getting system-wide temporary directory in a portable way', | ||
| 8 | description => <<'_', | ||
| 9 | |||
| 10 | There's the good ol' <pm:File::Spec> which has a `tmpdir` function. On Unix it | ||
| 11 | looks at `TMPDIR` environment variable before falling back to `/tmp`. | ||
| 12 | <pm:File::Temp> uses this for its `tempdir` when a template is not specified. | ||
| 13 | |||
| 14 | Then there's <pm:File::Util::Tempdir> which tries a little harder. On Unix, its | ||
| 15 | `get_tempdir` will look at `TMPDIR`, then also `TEMPDIR`, `TMP`, `TEMP`. If none | ||
| 16 | of those are set, it will return the first existing directory from the list: | ||
| 17 | `/tmp`, `/var/tmp`. If everything fails, will die. | ||
| 18 | |||
| 19 | File::Util::Tempdir also provides `get_user_tempdir` which returns a | ||
| 20 | user-private temporary directory, which can be useful if you want to create | ||
| 21 | temporary file with predetermined names. It will return temporary directory | ||
| 22 | pointed by `XDG_RUNTIME_DIR` (e.g. `/run/user/1000`) or, if unavailable, will | ||
| 23 | create a subdirectory under the world-writable temporary directory (e.g. | ||
| 24 | `/tmp/1000`). | ||
| 25 | |||
| 26 | _ | ||
| 27 | tags => ['task'], | ||
| 28 | entries => [ | ||
| 29 | { | ||
| 30 | module=>'File::Spec', | ||
| 31 | }, | ||
| 32 | { | ||
| 33 | module=>'File::Util::Tempdir', | ||
| 34 | }, | ||
| 35 | ], | ||
| 36 | }; | ||
| 37 | |||
| 38 | 1 | 1; | |
| 39 | # ABSTRACT: Getting system-wide temporary directory in a portable way | ||
| 40 | |||
| 41 | __END__ |