{
    "content": [
        {
            "type": "text",
            "text": "# File::Temp (perldoc)\n\n## NAME\n\nFile::Temp - return name and handle of a temporary file safely\n\n## SYNOPSIS\n\nuse File::Temp qw/ tempfile tempdir /;\n$fh = tempfile();\n($fh, $filename) = tempfile();\n($fh, $filename) = tempfile( $template, DIR => $dir);\n($fh, $filename) = tempfile( $template, SUFFIX => '.dat');\n($fh, $filename) = tempfile( $template, TMPDIR => 1 );\nbinmode( $fh, \":utf8\" );\n$dir = tempdir( CLEANUP => 1 );\n($fh, $filename) = tempfile( DIR => $dir );\nObject interface:\nrequire File::Temp;\nuse File::Temp ();\nuse File::Temp qw/ :seekable /;\n$fh = File::Temp->new();\n$fname = $fh->filename;\n$fh = File::Temp->new(TEMPLATE => $template);\n$fname = $fh->filename;\n$tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.dat' );\nprint $tmp \"Some data\\n\";\nprint \"Filename is $tmp\\n\";\n$tmp->seek( 0, SEEKEND );\n$dir = File::Temp->newdir(); # CLEANUP => 1 by default\nThe following interfaces are provided for compatibility with existing APIs. They should not be\nused in new code.\nMkTemp family:\nuse File::Temp qw/ :mktemp  /;\n($fh, $file) = mkstemp( \"tmpfileXXXXX\" );\n($fh, $file) = mkstemps( \"tmpfileXXXXXX\", $suffix);\n$tmpdir = mkdtemp( $template );\n$unopenedfile = mktemp( $template );\nPOSIX functions:\nuse File::Temp qw/ :POSIX /;\n$file = tmpnam();\n$fh = tmpfile();\n($fh, $file) = tmpnam();\nCompatibility functions:\n$unopenedfile = File::Temp::tempnam( $dir, $pfx );\n\n## DESCRIPTION\n\n\"File::Temp\" can be used to create and open temporary files in a safe way. There is both a\nfunction interface and an object-oriented interface. The File::Temp constructor or the\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION** (1 subsections)\n- **OBJECT-ORIENTED INTERFACE**\n- **FUNCTIONS**\n- **MKTEMP FUNCTIONS**\n- **POSIX FUNCTIONS**\n- **ADDITIONAL FUNCTIONS**\n- **UTILITY FUNCTIONS**\n- **PACKAGE VARIABLES**\n- **WARNING** (4 subsections)\n- **HISTORY**\n- **SEE ALSO**\n- **SUPPORT**\n- **AUTHOR**\n- **CONTRIBUTORS**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "File::Temp",
        "section": "",
        "mode": "perldoc",
        "summary": "File::Temp - return name and handle of a temporary file safely",
        "synopsis": "use File::Temp qw/ tempfile tempdir /;\n$fh = tempfile();\n($fh, $filename) = tempfile();\n($fh, $filename) = tempfile( $template, DIR => $dir);\n($fh, $filename) = tempfile( $template, SUFFIX => '.dat');\n($fh, $filename) = tempfile( $template, TMPDIR => 1 );\nbinmode( $fh, \":utf8\" );\n$dir = tempdir( CLEANUP => 1 );\n($fh, $filename) = tempfile( DIR => $dir );\nObject interface:\nrequire File::Temp;\nuse File::Temp ();\nuse File::Temp qw/ :seekable /;\n$fh = File::Temp->new();\n$fname = $fh->filename;\n$fh = File::Temp->new(TEMPLATE => $template);\n$fname = $fh->filename;\n$tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.dat' );\nprint $tmp \"Some data\\n\";\nprint \"Filename is $tmp\\n\";\n$tmp->seek( 0, SEEKEND );\n$dir = File::Temp->newdir(); # CLEANUP => 1 by default\nThe following interfaces are provided for compatibility with existing APIs. They should not be\nused in new code.\nMkTemp family:\nuse File::Temp qw/ :mktemp  /;\n($fh, $file) = mkstemp( \"tmpfileXXXXX\" );\n($fh, $file) = mkstemps( \"tmpfileXXXXXX\", $suffix);\n$tmpdir = mkdtemp( $template );\n$unopenedfile = mktemp( $template );\nPOSIX functions:\nuse File::Temp qw/ :POSIX /;\n$file = tmpnam();\n$fh = tmpfile();\n($fh, $file) = tmpnam();\nCompatibility functions:\n$unopenedfile = File::Temp::tempnam( $dir, $pfx );",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 60,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 2,
                "subsections": [
                    {
                        "name": "tempfile",
                        "lines": 20
                    }
                ]
            },
            {
                "name": "OBJECT-ORIENTED INTERFACE",
                "lines": 105,
                "subsections": []
            },
            {
                "name": "FUNCTIONS",
                "lines": 149,
                "subsections": []
            },
            {
                "name": "MKTEMP FUNCTIONS",
                "lines": 58,
                "subsections": []
            },
            {
                "name": "POSIX FUNCTIONS",
                "lines": 47,
                "subsections": []
            },
            {
                "name": "ADDITIONAL FUNCTIONS",
                "lines": 22,
                "subsections": []
            },
            {
                "name": "UTILITY FUNCTIONS",
                "lines": 104,
                "subsections": []
            },
            {
                "name": "PACKAGE VARIABLES",
                "lines": 92,
                "subsections": []
            },
            {
                "name": "WARNING",
                "lines": 15,
                "subsections": [
                    {
                        "name": "Temporary files and NFS",
                        "lines": 5
                    },
                    {
                        "name": "Forking",
                        "lines": 10
                    },
                    {
                        "name": "Directory removal",
                        "lines": 4
                    },
                    {
                        "name": "Taint mode",
                        "lines": 11
                    }
                ]
            },
            {
                "name": "HISTORY",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "SUPPORT",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "CONTRIBUTORS",
                "lines": 38,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 6,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "File::Temp - return name and handle of a temporary file safely\n",
                "subsections": []
            },
            "VERSION": {
                "content": "version 0.2311\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use File::Temp qw/ tempfile tempdir /;\n\n$fh = tempfile();\n($fh, $filename) = tempfile();\n\n($fh, $filename) = tempfile( $template, DIR => $dir);\n($fh, $filename) = tempfile( $template, SUFFIX => '.dat');\n($fh, $filename) = tempfile( $template, TMPDIR => 1 );\n\nbinmode( $fh, \":utf8\" );\n\n$dir = tempdir( CLEANUP => 1 );\n($fh, $filename) = tempfile( DIR => $dir );\n\nObject interface:\n\nrequire File::Temp;\nuse File::Temp ();\nuse File::Temp qw/ :seekable /;\n\n$fh = File::Temp->new();\n$fname = $fh->filename;\n\n$fh = File::Temp->new(TEMPLATE => $template);\n$fname = $fh->filename;\n\n$tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.dat' );\nprint $tmp \"Some data\\n\";\nprint \"Filename is $tmp\\n\";\n$tmp->seek( 0, SEEKEND );\n\n$dir = File::Temp->newdir(); # CLEANUP => 1 by default\n\nThe following interfaces are provided for compatibility with existing APIs. They should not be\nused in new code.\n\nMkTemp family:\n\nuse File::Temp qw/ :mktemp  /;\n\n($fh, $file) = mkstemp( \"tmpfileXXXXX\" );\n($fh, $file) = mkstemps( \"tmpfileXXXXXX\", $suffix);\n\n$tmpdir = mkdtemp( $template );\n\n$unopenedfile = mktemp( $template );\n\nPOSIX functions:\n\nuse File::Temp qw/ :POSIX /;\n\n$file = tmpnam();\n$fh = tmpfile();\n\n($fh, $file) = tmpnam();\n\nCompatibility functions:\n\n$unopenedfile = File::Temp::tempnam( $dir, $pfx );\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "\"File::Temp\" can be used to create and open temporary files in a safe way. There is both a\nfunction interface and an object-oriented interface. The File::Temp constructor or the",
                "subsections": [
                    {
                        "name": "tempfile",
                        "content": "The tempdir() function can be used to create a temporary directory.\n\nThe security aspect of temporary file creation is emphasized such that a filehandle and filename\nare returned together. This helps guarantee that a race condition can not occur where the\ntemporary file is created by another process between checking for the existence of the file and\nits opening. Additional security levels are provided to check, for example, that the sticky bit\nis set on world writable directories. See \"safelevel\" for more information.\n\nFor compatibility with popular C library functions, Perl implementations of the mkstemp() family\nof functions are provided. These are, mkstemp(), mkstemps(), mkdtemp() and mktemp().\n\nAdditionally, implementations of the standard POSIX tmpnam() and tmpfile() functions are\nprovided if required.\n\nImplementations of mktemp(), tmpnam(), and tempnam() are provided, but should be used with\ncaution since they return only a filename that was valid when function was called, so cannot\nguarantee that the file will not exist by the time the caller opens the filename.\n\nFilehandles returned by these functions support the seekable methods.\n"
                    }
                ]
            },
            "OBJECT-ORIENTED INTERFACE": {
                "content": "This is the primary interface for interacting with \"File::Temp\". Using the OO interface a\ntemporary file can be created when the object is constructed and the file can be removed when\nthe object is no longer required.\n\nNote that there is no method to obtain the filehandle from the \"File::Temp\" object. The object\nitself acts as a filehandle. The object isa \"IO::Handle\" and isa \"IO::Seekable\" so all those\nmethods are available.\n\nAlso, the object is configured such that it stringifies to the name of the temporary file and so\ncan be compared to a filename directly. It numifies to the \"refaddr\" the same as other handles\nand so can be compared to other handles with \"==\".\n\n$fh eq $filename       # as a string\n$fh != \\*STDOUT        # as a number\n\nAvailable since 0.14.\n\nnew Create a temporary file object.\n\nmy $tmp = File::Temp->new();\n\nby default the object is constructed as if \"tempfile\" was called without options, but with\nthe additional behaviour that the temporary file is removed by the object destructor if\nUNLINK is set to true (the default).\n\nSupported arguments are the same as for \"tempfile\": UNLINK (defaulting to true), DIR,\nEXLOCK, PERMS and SUFFIX. Additionally, the filename template is specified using the\nTEMPLATE option. The OPEN option is not supported (the file is always opened).\n\n$tmp = File::Temp->new( TEMPLATE => 'tempXXXXX',\nDIR => 'mydir',\nSUFFIX => '.dat');\n\nArguments are case insensitive.\n\nCan call croak() if an error occurs.\n\nAvailable since 0.14.\n\nTEMPLATE available since 0.23\n\nnewdir\nCreate a temporary directory using an object oriented interface.\n\n$dir = File::Temp->newdir();\n\nBy default the directory is deleted when the object goes out of scope.\n\nSupports the same options as the \"tempdir\" function. Note that directories created with this\nmethod default to CLEANUP => 1.\n\n$dir = File::Temp->newdir( $template, %options );\n\nA template may be specified either with a leading template or with a TEMPLATE argument.\n\nAvailable since 0.19.\n\nTEMPLATE available since 0.23.\n\nfilename\nReturn the name of the temporary file associated with this object (if the object was created\nusing the \"new\" constructor).\n\n$filename = $tmp->filename;\n\nThis method is called automatically when the object is used as a string.\n\nCurrent API available since 0.14\n\ndirname\nReturn the name of the temporary directory associated with this object (if the object was\ncreated using the \"newdir\" constructor).\n\n$dirname = $tmpdir->dirname;\n\nThis method is called automatically when the object is used in string context.\n\nunlinkondestroy\nControl whether the file is unlinked when the object goes out of scope. The file is removed\nif this value is true and $KEEPALL is not.\n\n$fh->unlinkondestroy( 1 );\n\nDefault is for the file to be removed.\n\nCurrent API available since 0.15\n\nDESTROY\nWhen the object goes out of scope, the destructor is called. This destructor will attempt to\nunlink the file (using unlink1) if the constructor was called with UNLINK set to 1 (the\ndefault state if UNLINK is not specified).\n\nNo error is given if the unlink fails.\n\nIf the object has been passed to a child process during a fork, the file will be deleted\nwhen the object goes out of scope in the parent.\n\nFor a temporary directory object the directory will be removed unless the CLEANUP argument\nwas used in the constructor (and set to false) or \"unlinkondestroy\" was modified after\ncreation. Note that if a temp directory is your current directory, it cannot be removed - a\nwarning will be given in this case. \"chdir()\" out of the directory before letting the object\ngo out of scope.\n\nIf the global variable $KEEPALL is true, the file or directory will not be removed.\n",
                "subsections": []
            },
            "FUNCTIONS": {
                "content": "This section describes the recommended interface for generating temporary files and directories.\n\ntempfile\nThis is the basic function to generate temporary files. The behaviour of the file can be\nchanged using various options:\n\n$fh = tempfile();\n($fh, $filename) = tempfile();\n\nCreate a temporary file in the directory specified for temporary files, as specified by the\ntmpdir() function in File::Spec.\n\n($fh, $filename) = tempfile($template);\n\nCreate a temporary file in the current directory using the supplied template. Trailing `X'\ncharacters are replaced with random letters to generate the filename. At least four `X'\ncharacters must be present at the end of the template.\n\n($fh, $filename) = tempfile($template, SUFFIX => $suffix)\n\nSame as previously, except that a suffix is added to the template after the `X' translation.\nUseful for ensuring that a temporary filename has a particular extension when needed by\nother applications. But see the WARNING at the end.\n\n($fh, $filename) = tempfile($template, DIR => $dir);\n\nTranslates the template as before except that a directory name is specified.\n\n($fh, $filename) = tempfile($template, TMPDIR => 1);\n\nEquivalent to specifying a DIR of \"File::Spec->tmpdir\", writing the file into the same\ntemporary directory as would be used if no template was specified at all.\n\n($fh, $filename) = tempfile($template, UNLINK => 1);\n\nReturn the filename and filehandle as before except that the file is automatically removed\nwhen the program exits (dependent on $KEEPALL). Default is for the file to be removed if a\nfile handle is requested and to be kept if the filename is requested. In a scalar context\n(where no filename is returned) the file is always deleted either (depending on the\noperating system) on exit or when it is closed (unless $KEEPALL is true when the temp file\nis created).\n\nUse the object-oriented interface if fine-grained control of when a file is removed is\nrequired.\n\nIf the template is not specified, a template is always automatically generated. This\ntemporary file is placed in tmpdir() (File::Spec) unless a directory is specified explicitly\nwith the DIR option.\n\n$fh = tempfile( DIR => $dir );\n\nIf called in scalar context, only the filehandle is returned and the file will automatically\nbe deleted when closed on operating systems that support this (see the description of\ntmpfile() elsewhere in this document). This is the preferred mode of operation, as if you\nonly have a filehandle, you can never create a race condition by fumbling with the filename.\nOn systems that can not unlink an open file or can not mark a file as temporary when it is\nopened (for example, Windows NT uses the \"OTEMPORARY\" flag) the file is marked for deletion\nwhen the program ends (equivalent to setting UNLINK to 1). The \"UNLINK\" flag is ignored if\npresent.\n\n(undef, $filename) = tempfile($template, OPEN => 0);\n\nThis will return the filename based on the template but will not open this file. Cannot be\nused in conjunction with UNLINK set to true. Default is to always open the file to protect\nfrom possible race conditions. A warning is issued if warnings are turned on. Consider using\nthe tmpnam() and mktemp() functions described elsewhere in this document if opening the file\nis not required.\n\nTo open the temporary filehandle with OEXLOCK (open with exclusive file lock) use\n\"EXLOCK=>1\". This is supported only by some operating systems (most notably BSD derived\nsystems). By default EXLOCK will be false. Former \"File::Temp\" versions set EXLOCK to true,\nso to be sure to get an unlocked filehandle also with older versions, explicitly set\n\"EXLOCK=>0\".\n\n($fh, $filename) = tempfile($template, EXLOCK => 1);\n\nBy default, the temp file is created with 0600 file permissions. Use \"PERMS\" to change this:\n\n($fh, $filename) = tempfile($template, PERMS => 0666);\n\nOptions can be combined as required.\n\nWill croak() if there is an error.\n\nAvailable since 0.05.\n\nUNLINK flag available since 0.10.\n\nTMPDIR flag available since 0.19.\n\nEXLOCK flag available since 0.19.\n\nPERMS flag available since 0.2310.\n\ntempdir\nThis is the recommended interface for creation of temporary directories. By default the\ndirectory will not be removed on exit (that is, it won't be temporary; this behaviour can\nnot be changed because of issues with backwards compatibility). To enable removal either use\nthe CLEANUP option which will trigger removal on program exit, or consider using the\n\"newdir\" method in the object interface which will allow the directory to be cleaned up when\nthe object goes out of scope.\n\nThe behaviour of the function depends on the arguments:\n\n$tempdir = tempdir();\n\nCreate a directory in tmpdir() (see File::Spec).\n\n$tempdir = tempdir( $template );\n\nCreate a directory from the supplied template. This template is similar to that described\nfor tempfile(). `X' characters at the end of the template are replaced with random letters\nto construct the directory name. At least four `X' characters must be in the template.\n\n$tempdir = tempdir ( DIR => $dir );\n\nSpecifies the directory to use for the temporary directory. The temporary directory name is\nderived from an internal template.\n\n$tempdir = tempdir ( $template, DIR => $dir );\n\nPrepend the supplied directory name to the template. The template should not include parent\ndirectory specifications itself. Any parent directory specifications are removed from the\ntemplate before prepending the supplied directory.\n\n$tempdir = tempdir ( $template, TMPDIR => 1 );\n\nUsing the supplied template, create the temporary directory in a standard location for\ntemporary files. Equivalent to doing\n\n$tempdir = tempdir ( $template, DIR => File::Spec->tmpdir);\n\nbut shorter. Parent directory specifications are stripped from the template itself. The\n\"TMPDIR\" option is ignored if \"DIR\" is set explicitly. Additionally, \"TMPDIR\" is implied if\nneither a template nor a directory are supplied.\n\n$tempdir = tempdir( $template, CLEANUP => 1);\n\nCreate a temporary directory using the supplied template, but attempt to remove it (and all\nfiles inside it) when the program exits. Note that an attempt will be made to remove all\nfiles from the directory even if they were not created by this module (otherwise why ask to\nclean it up?). The directory removal is made with the rmtree() function from the File::Path\nmodule. Of course, if the template is not specified, the temporary directory will be created\nin tmpdir() and will also be removed at program exit.\n\nWill croak() if there is an error.\n\nCurrent API available since 0.05.\n",
                "subsections": []
            },
            "MKTEMP FUNCTIONS": {
                "content": "The following functions are Perl implementations of the mktemp() family of temp file generation\nsystem calls.\n\nmkstemp\nGiven a template, returns a filehandle to the temporary file and the name of the file.\n\n($fh, $name) = mkstemp( $template );\n\nIn scalar context, just the filehandle is returned.\n\nThe template may be any filename with some number of X's appended to it, for example\n/tmp/temp.XXXX. The trailing X's are replaced with unique alphanumeric combinations.\n\nWill croak() if there is an error.\n\nCurrent API available since 0.05.\n\nmkstemps\nSimilar to mkstemp(), except that an extra argument can be supplied with a suffix to be\nappended to the template.\n\n($fh, $name) = mkstemps( $template, $suffix );\n\nFor example a template of \"testXXXXXX\" and suffix of \".dat\" would generate a file similar to\ntesthGjiw.dat.\n\nReturns just the filehandle alone when called in scalar context.\n\nWill croak() if there is an error.\n\nCurrent API available since 0.05.\n\nmkdtemp\nCreate a directory from a template. The template must end in X's that are replaced by the\nroutine.\n\n$tmpdirname = mkdtemp($template);\n\nReturns the name of the temporary directory created.\n\nDirectory must be removed by the caller.\n\nWill croak() if there is an error.\n\nCurrent API available since 0.05.\n\nmktemp\nReturns a valid temporary filename but does not guarantee that the file will not be opened\nby someone else.\n\n$unopenedfile = mktemp($template);\n\nTemplate is the same as that required by mkstemp().\n\nWill croak() if there is an error.\n\nCurrent API available since 0.05.\n",
                "subsections": []
            },
            "POSIX FUNCTIONS": {
                "content": "This section describes the re-implementation of the tmpnam() and tmpfile() functions described\nin POSIX using the mkstemp() from this module.\n\nUnlike the POSIX implementations, the directory used for the temporary file is not specified in\na system include file (\"Ptmpdir\") but simply depends on the choice of tmpdir() returned by\nFile::Spec. On some implementations this location can be set using the \"TMPDIR\" environment\nvariable, which may not be secure. If this is a problem, simply use mkstemp() and specify a\ntemplate.\n\ntmpnam\nWhen called in scalar context, returns the full name (including path) of a temporary file\n(uses mktemp()). The only check is that the file does not already exist, but there is no\nguarantee that that condition will continue to apply.\n\n$file = tmpnam();\n\nWhen called in list context, a filehandle to the open file and a filename are returned. This\nis achieved by calling mkstemp() after constructing a suitable template.\n\n($fh, $file) = tmpnam();\n\nIf possible, this form should be used to prevent possible race conditions.\n\nSee \"tmpdir\" in File::Spec for information on the choice of temporary directory for a\nparticular operating system.\n\nWill croak() if there is an error.\n\nCurrent API available since 0.05.\n\ntmpfile\nReturns the filehandle of a temporary file.\n\n$fh = tmpfile();\n\nThe file is removed when the filehandle is closed or when the program exits. No access to\nthe filename is provided.\n\nIf the temporary file can not be created undef is returned. Currently this command will\nprobably not work when the temporary directory is on an NFS file system.\n\nWill croak() if there is an error.\n\nAvailable since 0.05.\n\nReturning undef if unable to create file added in 0.12.\n",
                "subsections": []
            },
            "ADDITIONAL FUNCTIONS": {
                "content": "These functions are provided for backwards compatibility with common tempfile generation C\nlibrary functions.\n\nThey are not exported and must be addressed using the full package name.\n\ntempnam\nReturn the name of a temporary file in the specified directory using a prefix. The file is\nguaranteed not to exist at the time the function was called, but such guarantees are good\nfor one clock tick only. Always use the proper form of \"sysopen\" with \"OCREAT | OEXCL\" if\nyou must open such a filename.\n\n$filename = File::Temp::tempnam( $dir, $prefix );\n\nEquivalent to running mktemp() with $dir/$prefixXXXXXXXX (using unix file convention as an\nexample)\n\nBecause this function uses mktemp(), it can suffer from race conditions.\n\nWill croak() if there is an error.\n\nCurrent API available since 0.05.\n",
                "subsections": []
            },
            "UTILITY FUNCTIONS": {
                "content": "Useful functions for dealing with the filehandle and filename.\n\nunlink0\nGiven an open filehandle and the associated filename, make a safe unlink. This is achieved\nby first checking that the filename and filehandle initially point to the same file and that\nthe number of links to the file is 1 (all fields returned by stat() are compared). Then the\nfilename is unlinked and the filehandle checked once again to verify that the number of\nlinks on that file is now 0. This is the closest you can come to making sure that the\nfilename unlinked was the same as the file whose descriptor you hold.\n\nunlink0($fh, $path)\nor die \"Error unlinking file $path safely\";\n\nReturns false on error but croaks() if there is a security anomaly. The filehandle is not\nclosed since on some occasions this is not required.\n\nOn some platforms, for example Windows NT, it is not possible to unlink an open file (the\nfile must be closed first). On those platforms, the actual unlinking is deferred until the\nprogram ends and good status is returned. A check is still performed to make sure that the\nfilehandle and filename are pointing to the same thing (but not at the time the end block is\nexecuted since the deferred removal may not have access to the filehandle).\n\nAdditionally, on Windows NT not all the fields returned by stat() can be compared. For\nexample, the \"dev\" and \"rdev\" fields seem to be different. Also, it seems that the size of\nthe file returned by stat() does not always agree, with \"stat(FH)\" being more accurate than\n\"stat(filename)\", presumably because of caching issues even when using autoflush (this is\nusually overcome by waiting a while after writing to the tempfile before attempting to\n\"unlink0\" it).\n\nFinally, on NFS file systems the link count of the file handle does not always go to zero\nimmediately after unlinking. Currently, this command is expected to fail on NFS disks.\n\nThis function is disabled if the global variable $KEEPALL is true and an unlink on open\nfile is supported. If the unlink is to be deferred to the END block, the file is still\nregistered for removal.\n\nThis function should not be called if you are using the object oriented interface since the\nit will interfere with the object destructor deleting the file.\n\nAvailable Since 0.05.\n\nIf can not unlink open file, defer removal until later available since 0.06.\n\ncmpstat\nCompare \"stat\" of filehandle with \"stat\" of provided filename. This can be used to check\nthat the filename and filehandle initially point to the same file and that the number of\nlinks to the file is 1 (all fields returned by stat() are compared).\n\ncmpstat($fh, $path)\nor die \"Error comparing handle with file\";\n\nReturns false if the stat information differs or if the link count is greater than 1. Calls\ncroak if there is a security anomaly.\n\nOn certain platforms, for example Windows, not all the fields returned by stat() can be\ncompared. For example, the \"dev\" and \"rdev\" fields seem to be different in Windows. Also, it\nseems that the size of the file returned by stat() does not always agree, with \"stat(FH)\"\nbeing more accurate than \"stat(filename)\", presumably because of caching issues even when\nusing autoflush (this is usually overcome by waiting a while after writing to the tempfile\nbefore attempting to \"unlink0\" it).\n\nNot exported by default.\n\nCurrent API available since 0.14.\n\nunlink1\nSimilar to \"unlink0\" except after file comparison using cmpstat, the filehandle is closed\nprior to attempting to unlink the file. This allows the file to be removed without using an\nEND block, but does mean that the post-unlink comparison of the filehandle state provided by\n\"unlink0\" is not available.\n\nunlink1($fh, $path)\nor die \"Error closing and unlinking file\";\n\nUsually called from the object destructor when using the OO interface.\n\nNot exported by default.\n\nThis function is disabled if the global variable $KEEPALL is true.\n\nCan call croak() if there is a security anomaly during the stat() comparison.\n\nCurrent API available since 0.14.\n\ncleanup\nCalling this function will cause any temp files or temp directories that are registered for\nremoval to be removed. This happens automatically when the process exits but can be\ntriggered manually if the caller is sure that none of the temp files are required. This\nmethod can be registered as an Apache callback.\n\nNote that if a temp directory is your current directory, it cannot be removed. \"chdir()\" out\nof the directory first before calling \"cleanup()\". (For the cleanup at program exit when the\nCLEANUP flag is set, this happens automatically.)\n\nOn OSes where temp files are automatically removed when the temp file is closed, calling\nthis function will have no effect other than to remove temporary directories (which may\ninclude temporary files).\n\nFile::Temp::cleanup();\n\nNot exported by default.\n\nCurrent API available since 0.15.\n",
                "subsections": []
            },
            "PACKAGE VARIABLES": {
                "content": "These functions control the global state of the package.\n\nsafelevel\nControls the lengths to which the module will go to check the safety of the temporary file\nor directory before proceeding. Options are:\n\nSTANDARD\nDo the basic security measures to ensure the directory exists and is writable, that\ntemporary files are opened only if they do not already exist, and that possible race\nconditions are avoided. Finally the unlink0 function is used to remove files safely.\n\nMEDIUM  In addition to the STANDARD security, the output directory is checked to make sure\nthat it is owned either by root or the user running the program. If the directory is\nwritable by group or by other, it is then checked to make sure that the sticky bit\nis set.\n\nWill not work on platforms that do not support the \"-k\" test for sticky bit.\n\nHIGH    In addition to the MEDIUM security checks, also check for the possibility of\n``chown() giveaway'' using the POSIX sysconf() function. If this is a possibility,\neach directory in the path is checked in turn for safeness, recursively walking back\nto the root directory.\n\nFor platforms that do not support the POSIX \"PCCHOWNRESTRICTED\" symbol (for\nexample, Windows NT) it is assumed that ``chown() giveaway'' is possible and the\nrecursive test is performed.\n\nThe level can be changed as follows:\n\nFile::Temp->safelevel( File::Temp::HIGH );\n\nThe level constants are not exported by the module.\n\nCurrently, you must be running at least perl v5.6.0 in order to run with MEDIUM or HIGH\nsecurity. This is simply because the safety tests use functions from Fcntl that are not\navailable in older versions of perl. The problem is that the version number for Fcntl is the\nsame in perl 5.6.0 and in 5.00503 even though they are different versions.\n\nOn systems that do not support the HIGH or MEDIUM safety levels (for example Win NT or OS/2)\nany attempt to change the level will be ignored. The decision to ignore rather than raise an\nexception allows portable programs to be written with high security in mind for the systems\nthat can support this without those programs failing on systems where the extra tests are\nirrelevant.\n\nIf you really need to see whether the change has been accepted simply examine the return\nvalue of \"safelevel\".\n\n$newlevel = File::Temp->safelevel( File::Temp::HIGH );\ndie \"Could not change to high security\"\nif $newlevel != File::Temp::HIGH;\n\nAvailable since 0.05.\n\nTopSystemUID\nThis is the highest UID on the current system that refers to a root UID. This is used to\nmake sure that the temporary directory is owned by a system UID (\"root\", \"bin\", \"sys\" etc)\nrather than simply by root.\n\nThis is required since on many unix systems \"/tmp\" is not owned by root.\n\nDefault is to assume that any UID less than or equal to 10 is a root UID.\n\nFile::Temp->topsystemuid(10);\nmy $topid = File::Temp->topsystemuid;\n\nThis value can be adjusted to reduce security checking if required. The value is only\nrelevant when \"safelevel\" is set to MEDIUM or higher.\n\nAvailable since 0.05.\n\n$KEEPALL\nControls whether temporary files and directories should be retained regardless of any\ninstructions in the program to remove them automatically. This is useful for debugging but\nshould not be used in production code.\n\n$File::Temp::KEEPALL = 1;\n\nDefault is for files to be removed as requested by the caller.\n\nIn some cases, files will only be retained if this variable is true when the file is\ncreated. This means that you can not create a temporary file, set this variable and expect\nthe temp file to still be around when the program exits.\n\n$DEBUG\nControls whether debugging messages should be enabled.\n\n$File::Temp::DEBUG = 1;\n\nDefault is for debugging mode to be disabled.\n\nAvailable since 0.15.\n",
                "subsections": []
            },
            "WARNING": {
                "content": "For maximum security, endeavour always to avoid ever looking at, touching, or even imputing the\nexistence of the filename. You do not know that that filename is connected to the same file as\nthe handle you have, and attempts to check this can only trigger more race conditions. It's far\nmore secure to use the filehandle alone and dispense with the filename altogether.\n\nIf you need to pass the handle to something that expects a filename then on a unix system you\ncan use \"\"/dev/fd/\" . fileno($fh)\" for arbitrary programs. Perl code that uses the 2-argument\nversion of \"open\" can be passed \"\"+<=&\" . fileno($fh)\". Otherwise you will need to pass the\nfilename. You will have to clear the close-on-exec bit on that file descriptor before passing it\nto another process.\n\nuse Fcntl qw/FSETFD FGETFD/;\nfcntl($tmpfh, FSETFD, 0)\nor die \"Can't clear close-on-exec flag on temp fh: $!\\n\";\n",
                "subsections": [
                    {
                        "name": "Temporary files and NFS",
                        "content": "Some problems are associated with using temporary files that reside on NFS file systems and it\nis recommended that a local filesystem is used whenever possible. Some of the security tests\nwill most probably fail when the temp file is not local. Additionally, be aware that the\nperformance of I/O operations over NFS will not be as good as for a local disk.\n"
                    },
                    {
                        "name": "Forking",
                        "content": "In some cases files created by File::Temp are removed from within an END block. Since END blocks\nare triggered when a child process exits (unless \"POSIX::exit()\" is used by the child)\nFile::Temp takes care to only remove those temp files created by a particular process ID. This\nmeans that a child will not attempt to remove temp files created by the parent process.\n\nIf you are forking many processes in parallel that are all creating temporary files, you may\nneed to reset the random number seed using srand(EXPR) in each child else all the children will\nattempt to walk through the same set of random file names and may well cause themselves to give\nup if they exceed the number of retry attempts.\n"
                    },
                    {
                        "name": "Directory removal",
                        "content": "Note that if you have chdir'ed into the temporary directory and it is subsequently cleaned up\n(either in the END block or as part of object destruction), then you will get a warning from\nFile::Path::rmtree().\n"
                    },
                    {
                        "name": "Taint mode",
                        "content": "If you need to run code under taint mode, updating to the latest File::Spec is highly\nrecommended. On Windows, if the directory given by File::Spec::tmpdir isn't writable, File::Temp\nwill attempt to fallback to the user's local application data directory or croak with an error.\n\nBINMODE\nThe file returned by File::Temp will have been opened in binary mode if such a mode is\navailable. If that is not correct, use the \"binmode()\" function to change the mode of the\nfilehandle.\n\nNote that you can modify the encoding of a file opened by File::Temp also by using \"binmode()\".\n"
                    }
                ]
            },
            "HISTORY": {
                "content": "Originally began life in May 1999 as an XS interface to the system mkstemp() function. In March\n2000, the OpenBSD mkstemp() code was translated to Perl for total control of the code's security\nchecking, to ensure the presence of the function regardless of operating system and to help with\nportability. The module was shipped as a standard part of perl from v5.6.1.\n\nThanks to Tom Christiansen for suggesting that this module should be written and providing ideas\nfor code improvements and security enhancements.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "\"tmpnam\" in POSIX, \"tmpfile\" in POSIX, File::Spec, File::Path\n\nSee IO::File and File::MkTemp, Apache::TempFile for different implementations of temporary file\nhandling.\n\nSee File::Tempdir for an alternative object-oriented wrapper for the \"tempdir\" function.\n",
                "subsections": []
            },
            "SUPPORT": {
                "content": "Bugs may be submitted through the RT bug tracker\n<https://rt.cpan.org/Public/Dist/Display.html?Name=File-Temp> (or bug-File-Temp@rt.cpan.org\n<mailto:bug-File-Temp@rt.cpan.org>).\n\nThere is also a mailing list available for users of this distribution, at\n<http://lists.perl.org/list/cpan-workers.html>.\n\nThere is also an irc channel available for users of this distribution, at \"#toolchain\" on\n\"irc.perl.org\" <irc://irc.perl.org/#toolchain>.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Tim Jenness <tjenness@cpan.org>\n",
                "subsections": []
            },
            "CONTRIBUTORS": {
                "content": "*   Tim Jenness <t.jenness@jach.hawaii.edu>\n\n*   Karen Etheridge <ether@cpan.org>\n\n*   David Golden <dagolden@cpan.org>\n\n*   Slaven Rezic <srezic@cpan.org>\n\n*   mohawk2 <mohawk2@users.noreply.github.com>\n\n*   Roy Ivy III <rivy.dev@gmail.com>\n\n*   Peter Rabbitson <ribasushi@cpan.org>\n\n*   Olivier Mengué <dolmen@cpan.org>\n\n*   Peter John Acklam <pjacklam@online.no>\n\n*   Tim Gim Yee <tim.gim.yee@gmail.com>\n\n*   Nicolas R <atoomic@cpan.org>\n\n*   Brian Mowrey <brian@drlabs.org>\n\n*   Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>\n\n*   David Steinbrunner <dsteinbrunner@pobox.com>\n\n*   Ed Avis <eda@linux01.wcl.local>\n\n*   Guillem Jover <guillem@hadrons.org>\n\n*   James E. Keenan <jkeen@verizon.net>\n\n*   Kevin Ryde <user42@zip.com.au>\n\n*   Ben Tilly <btilly@gmail.com>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "This software is copyright (c) 2020 by Tim Jenness and the UK Particle Physics and Astronomy\nResearch Council.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
                "subsections": []
            }
        }
    }
}