NAME
Command::Run::Tmpfile - Temporary file with /dev/fd path access
SYNOPSIS
use Command::Run::Tmpfile;
my $tmp = Command::Run::Tmpfile->new;
$tmp->write("some data")->flush;
# Pass to external command as file argument
system("cat", $tmp->path); # /dev/fd/N
# Read back
$tmp->rewind;
my $data = do { local $/; my $fh = $tmp->fh; <$fh> };
DESCRIPTION
This module provides an anonymous temporary file that can be accessed via /dev/fd/N or /proc/self/fd/N path. The file is automatically deleted when the object is destroyed.
This is useful when you need to pass data to external commands that require file arguments rather than stdin.
METHODS
- new()
-
Create a new temporary file object.
- write(@data)
-
Write data to the temporary file. Returns the object for method chaining.
- flush()
-
Flush the file buffer. Returns the object for method chaining.
- rewind()
-
Seek to the beginning of the file. Returns the object for method chaining.
- reset()
-
Rewind and truncate the file (clear contents). Returns the object for method chaining.
- fh()
-
Return the underlying file handle.
- fd()
-
Return the file descriptor number.
- path()
-
Return the file descriptor path (e.g.,
/dev/fd/3).
SEE ALSO
AUTHOR
Kazumasa Utashiro
LICENSE
Copyright 2026 Kazumasa Utashiro.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.