{
    "content": [
        {
            "type": "text",
            "text": "# Path::Class::Dir (perldoc)\n\n## NAME\n\nPath::Class::Dir - Objects representing directories\n\n## SYNOPSIS\n\nuse Path::Class;  # Exports dir() by default\nmy $dir = dir('foo', 'bar');       # Path::Class::Dir object\nmy $dir = Path::Class::Dir->new('foo', 'bar');  # Same thing\n# Stringifies to 'foo/bar' on Unix, 'foo\\bar' on Windows, etc.\nprint \"dir: $dir\\n\";\nif ($dir->isabsolute) { ... }\nif ($dir->isrelative) { ... }\nmy $v = $dir->volume; # Could be 'C:' on Windows, empty string\n# on Unix, 'Macintosh HD:' on Mac OS\n$dir->cleanup; # Perform logical cleanup of pathname\n$dir->resolve; # Perform physical cleanup of pathname\nmy $file = $dir->file('file.txt'); # A file in this directory\nmy $subdir = $dir->subdir('george'); # A subdirectory\nmy $parent = $dir->parent; # The parent directory, 'foo'\nmy $abs = $dir->absolute; # Transform to absolute path\nmy $rel = $abs->relative; # Transform to relative path\nmy $rel = $abs->relative('/foo'); # Relative to /foo\nprint $dir->asforeign('Mac');   # :foo:bar:\nprint $dir->asforeign('Win32'); #  foo\\bar\n# Iterate with IO::Dir methods:\nmy $handle = $dir->open;\nwhile (my $file = $handle->read) {\n$file = $dir->file($file);  # Turn into Path::Class::File object\n...\n}\n# Iterate with Path::Class methods:\nwhile (my $file = $dir->next) {\n# $file is a Path::Class::File or Path::Class::Dir object\n...\n}\n\n## DESCRIPTION\n\nThe \"Path::Class::Dir\" class contains functionality for manipulating directory names in a\ncross-platform way.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **AUTHOR**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Path::Class::Dir",
        "section": "",
        "mode": "perldoc",
        "summary": "Path::Class::Dir - Objects representing directories",
        "synopsis": "use Path::Class;  # Exports dir() by default\nmy $dir = dir('foo', 'bar');       # Path::Class::Dir object\nmy $dir = Path::Class::Dir->new('foo', 'bar');  # Same thing\n# Stringifies to 'foo/bar' on Unix, 'foo\\bar' on Windows, etc.\nprint \"dir: $dir\\n\";\nif ($dir->isabsolute) { ... }\nif ($dir->isrelative) { ... }\nmy $v = $dir->volume; # Could be 'C:' on Windows, empty string\n# on Unix, 'Macintosh HD:' on Mac OS\n$dir->cleanup; # Perform logical cleanup of pathname\n$dir->resolve; # Perform physical cleanup of pathname\nmy $file = $dir->file('file.txt'); # A file in this directory\nmy $subdir = $dir->subdir('george'); # A subdirectory\nmy $parent = $dir->parent; # The parent directory, 'foo'\nmy $abs = $dir->absolute; # Transform to absolute path\nmy $rel = $abs->relative; # Transform to relative path\nmy $rel = $abs->relative('/foo'); # Relative to /foo\nprint $dir->asforeign('Mac');   # :foo:bar:\nprint $dir->asforeign('Win32'); #  foo\\bar\n# Iterate with IO::Dir methods:\nmy $handle = $dir->open;\nwhile (my $file = $handle->read) {\n$file = $dir->file($file);  # Turn into Path::Class::File object\n...\n}\n# Iterate with Path::Class methods:\nwhile (my $file = $dir->next) {\n# $file is a Path::Class::File or Path::Class::Dir object\n...\n}",
        "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": 41,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 362,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Path::Class::Dir - Objects representing directories\n",
                "subsections": []
            },
            "VERSION": {
                "content": "version 0.37\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Path::Class;  # Exports dir() by default\n\nmy $dir = dir('foo', 'bar');       # Path::Class::Dir object\nmy $dir = Path::Class::Dir->new('foo', 'bar');  # Same thing\n\n# Stringifies to 'foo/bar' on Unix, 'foo\\bar' on Windows, etc.\nprint \"dir: $dir\\n\";\n\nif ($dir->isabsolute) { ... }\nif ($dir->isrelative) { ... }\n\nmy $v = $dir->volume; # Could be 'C:' on Windows, empty string\n# on Unix, 'Macintosh HD:' on Mac OS\n\n$dir->cleanup; # Perform logical cleanup of pathname\n$dir->resolve; # Perform physical cleanup of pathname\n\nmy $file = $dir->file('file.txt'); # A file in this directory\nmy $subdir = $dir->subdir('george'); # A subdirectory\nmy $parent = $dir->parent; # The parent directory, 'foo'\n\nmy $abs = $dir->absolute; # Transform to absolute path\nmy $rel = $abs->relative; # Transform to relative path\nmy $rel = $abs->relative('/foo'); # Relative to /foo\n\nprint $dir->asforeign('Mac');   # :foo:bar:\nprint $dir->asforeign('Win32'); #  foo\\bar\n\n# Iterate with IO::Dir methods:\nmy $handle = $dir->open;\nwhile (my $file = $handle->read) {\n$file = $dir->file($file);  # Turn into Path::Class::File object\n...\n}\n\n# Iterate with Path::Class methods:\nwhile (my $file = $dir->next) {\n# $file is a Path::Class::File or Path::Class::Dir object\n...\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The \"Path::Class::Dir\" class contains functionality for manipulating directory names in a\ncross-platform way.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "$dir = Path::Class::Dir->new( <dir1>, <dir2>, ... )\n$dir = dir( <dir1>, <dir2>, ... )\nCreates a new \"Path::Class::Dir\" object and returns it. The arguments specify names of\ndirectories which will be joined to create a single directory object. A volume may also be\nspecified as the first argument, or as part of the first argument. You can use\nplatform-neutral syntax:\n\nmy $dir = dir( 'foo', 'bar', 'baz' );\n\nor platform-native syntax:\n\nmy $dir = dir( 'foo/bar/baz' );\n\nor a mixture of the two:\n\nmy $dir = dir( 'foo/bar', 'baz' );\n\nAll three of the above examples create relative paths. To create an absolute path, either\nuse the platform native syntax for doing so:\n\nmy $dir = dir( '/var/tmp' );\n\nor use an empty string as the first argument:\n\nmy $dir = dir( '', 'var', 'tmp' );\n\nIf the second form seems awkward, that's somewhat intentional - paths like \"/var/tmp\" or\n\"\\Windows\" aren't cross-platform concepts in the first place (many non-Unix platforms don't\nhave a notion of a \"root directory\"), so they probably shouldn't appear in your code if\nyou're trying to be cross-platform. The first form is perfectly natural, because paths like\nthis may come from config files, user input, or whatever.\n\nAs a special case, since it doesn't otherwise mean anything useful and it's convenient to\ndefine this way, \"Path::Class::Dir->new()\" (or \"dir()\") refers to the current directory\n(\"File::Spec->curdir\"). To get the current directory as an absolute path, do\n\"dir()->absolute\".\n\nFinally, as another special case \"dir(undef)\" will return undef, since that's usually an\naccident on the part of the caller, and returning the root directory would be a nasty\nsurprise just asking for trouble a few lines later.\n\n$dir->stringify\nThis method is called internally when a \"Path::Class::Dir\" object is used in a string\ncontext, so the following are equivalent:\n\n$string = $dir->stringify;\n$string = \"$dir\";\n\n$dir->volume\nReturns the volume (e.g. \"C:\" on Windows, \"Macintosh HD:\" on Mac OS, etc.) of the directory\nobject, if any. Otherwise, returns the empty string.\n\n$dir->basename\nReturns the last directory name of the path as a string.\n\n$dir->isdir\nReturns a boolean value indicating whether this object represents a directory. Not\nsurprisingly, Path::Class::File objects always return false, and \"Path::Class::Dir\" objects\nalways return true.\n\n$dir->isabsolute\nReturns true or false depending on whether the directory refers to an absolute path\nspecifier (like \"/usr/local\" or \"\\Windows\").\n\n$dir->isrelative\nReturns true or false depending on whether the directory refers to a relative path specifier\n(like \"lib/foo\" or \"./dir\").\n\n$dir->cleanup\nPerforms a logical cleanup of the file path. For instance:\n\nmy $dir = dir('/foo//baz/./foo')->cleanup;\n# $dir now represents '/foo/baz/foo';\n\n$dir->resolve\nPerforms a physical cleanup of the file path. For instance:\n\nmy $dir = dir('/foo//baz/../foo')->resolve;\n# $dir now represents '/foo/foo', assuming no symlinks\n\nThis actually consults the filesystem to verify the validity of the path.\n\n$file = $dir->file( <dir1>, <dir2>, ..., <file> )\nReturns a Path::Class::File object representing an entry in $dir or one of its\nsubdirectories. Internally, this just calls \"Path::Class::File->new( @ )\".\n\n$subdir = $dir->subdir( <dir1>, <dir2>, ... )\nReturns a new \"Path::Class::Dir\" object representing a subdirectory of $dir.\n\n$parent = $dir->parent\nReturns the parent directory of $dir. Note that this is the *logical* parent, not\nnecessarily the physical parent. It really means we just chop off entries from the end of\nthe directory list until we cain't chop no more. If the directory is relative, we start\nusing the relative forms of parent directories.\n\nThe following code demonstrates the behavior on absolute and relative directories:\n\n$dir = dir('/foo/bar');\nfor (1..6) {\nprint \"Absolute: $dir\\n\";\n$dir = $dir->parent;\n}\n\n$dir = dir('foo/bar');\nfor (1..6) {\nprint \"Relative: $dir\\n\";\n$dir = $dir->parent;\n}\n\n########### Output on Unix ################\nAbsolute: /foo/bar\nAbsolute: /foo\nAbsolute: /\nAbsolute: /\nAbsolute: /\nAbsolute: /\nRelative: foo/bar\nRelative: foo\nRelative: .\nRelative: ..\nRelative: ../..\nRelative: ../../..\n\n@list = $dir->children\nReturns a list of Path::Class::File and/or \"Path::Class::Dir\" objects listed in this\ndirectory, or in scalar context the number of such objects. Obviously, it is necessary for\n$dir to exist and be readable in order to find its children.\n\nNote that the children are returned as subdirectories of $dir, i.e. the children of foo will\nbe foo/bar and foo/baz, not bar and baz.\n\nOrdinarily \"children()\" will not include the *self* and *parent* entries \".\" and \"..\" (or\ntheir equivalents on non-Unix systems), because that's like I'm-my-own-grandpa business. If\nyou do want all directory entries including these special ones, pass a true value for the\n\"all\" parameter:\n\n@c = $dir->children(); # Just the children\n@c = $dir->children(all => 1); # All entries\n\nIn addition, there's a \"nohidden\" parameter that will exclude all normally \"hidden\" entries\n- on Unix this means excluding all entries that begin with a dot (\".\"):\n\n@c = $dir->children(nohidden => 1); # Just normally-visible entries\n\n$abs = $dir->absolute\nReturns a \"Path::Class::Dir\" object representing $dir as an absolute path. An optional\nargument, given as either a string or a \"Path::Class::Dir\" object, specifies the directory\nto use as the base of relativity - otherwise the current working directory will be used.\n\n$rel = $dir->relative\nReturns a \"Path::Class::Dir\" object representing $dir as a relative path. An optional\nargument, given as either a string or a \"Path::Class::Dir\" object, specifies the directory\nto use as the base of relativity - otherwise the current working directory will be used.\n\n$boolean = $dir->subsumes($other)\nReturns true if this directory spec subsumes the other spec, and false otherwise. Think of\n\"subsumes\" as \"contains\", but we only look at the *specs*, not whether $dir actually\ncontains $other on the filesystem.\n\nThe $other argument may be a \"Path::Class::Dir\" object, a Path::Class::File object, or a\nstring. In the latter case, we assume it's a directory.\n\n# Examples:\ndir('foo/bar' )->subsumes(dir('foo/bar/baz'))  # True\ndir('/foo/bar')->subsumes(dir('/foo/bar/baz')) # True\ndir('foo/..')->subsumes(dir('foo/../bar))      # True\ndir('foo/bar' )->subsumes(dir('bar/baz'))      # False\ndir('/foo/bar')->subsumes(dir('foo/bar'))      # False\ndir('foo/..')->subsumes(dir('bar'))            # False! Use C<contains> to resolve \"..\"\n\n$boolean = $dir->contains($other)\nReturns true if this directory actually contains $other on the filesystem. $other doesn't\nhave to be a direct child of $dir, it just has to be subsumed after both paths have been\nresolved.\n\n$foreign = $dir->asforeign($type)\nReturns a \"Path::Class::Dir\" object representing $dir as it would be specified on a system\nof type $type. Known types include \"Unix\", \"Win32\", \"Mac\", \"VMS\", and \"OS2\", i.e. anything\nfor which there is a subclass of \"File::Spec\".\n\nAny generated objects (subdirectories, files, parents, etc.) will also retain this type.\n\n$foreign = Path::Class::Dir->newforeign($type, @args)\nReturns a \"Path::Class::Dir\" object representing $dir as it would be specified on a system\nof type $type. Known types include \"Unix\", \"Win32\", \"Mac\", \"VMS\", and \"OS2\", i.e. anything\nfor which there is a subclass of \"File::Spec\".\n\nThe arguments in @args are the same as they would be specified in \"new()\".\n\n@list = $dir->dirlist([OFFSET, [LENGTH]])\nReturns the list of strings internally representing this directory structure. Each\nsuccessive member of the list is understood to be an entry in its predecessor's directory\nlist. By contract, \"Path::Class->new( $dir->dirlist )\" should be equivalent to $dir.\n\nThe semantics of this method are similar to Perl's \"splice\" or \"substr\" functions; they\nreturn \"LENGTH\" elements starting at \"OFFSET\". If \"LENGTH\" is omitted, returns all the\nelements starting at \"OFFSET\" up to the end of the list. If \"LENGTH\" is negative, returns\nthe elements from \"OFFSET\" onward except for \"-LENGTH\" elements at the end. If \"OFFSET\" is\nnegative, it counts backward \"OFFSET\" elements from the end of the list. If \"OFFSET\" and\n\"LENGTH\" are both omitted, the entire list is returned.\n\nIn a scalar context, \"dirlist()\" with no arguments returns the number of entries in the\ndirectory list; \"dirlist(OFFSET)\" returns the single element at that offset;\n\"dirlist(OFFSET, LENGTH)\" returns the final element that would have been returned in a list\ncontext.\n\n$dir->components\nIdentical to \"dirlist()\". It exists because there's an analogous method \"dirlist()\" in the\n\"Path::Class::File\" class that also returns the basename string, so this method lets someone\ncall \"components()\" without caring whether the object is a file or a directory.\n\n$fh = $dir->open()\nPasses $dir to \"IO::Dir->open\" and returns the result as an IO::Dir object. If the opening\nfails, \"undef\" is returned and $! is set.\n\n$dir->mkpath($verbose, $mode)\nPasses all arguments, including $dir, to \"File::Path::mkpath()\" and returns the result (a\nlist of all directories created).\n\n$dir->rmtree($verbose, $cautious)\nPasses all arguments, including $dir, to \"File::Path::rmtree()\" and returns the result (the\nnumber of files successfully deleted).\n\n$dir->remove()\nRemoves the directory, which must be empty. Returns a boolean value indicating whether or\nnot the directory was successfully removed. This method is mainly provided for consistency\nwith \"Path::Class::File\"'s \"remove()\" method.\n\n$dir->tempfile(...)\nAn interface to File::Temp's \"tempfile()\" function. Just like that function, if you call\nthis in a scalar context, the return value is the filehandle and the file is \"unlink\"ed as\nsoon as possible (which is immediately on Unix-like platforms). If called in a list context,\nthe return values are the filehandle and the filename.\n\nThe given directory is passed as the \"DIR\" parameter.\n\nHere's an example of pretty good usage which doesn't allow race conditions, won't leave\nyucky tempfiles around on your filesystem, etc.:\n\nmy $fh = $dir->tempfile;\nprint $fh \"Here's some data...\\n\";\nseek($fh, 0, 0);\nwhile (<$fh>) { do something... }\n\nOr in combination with a \"fork\":\n\nmy $fh = $dir->tempfile;\nprint $fh \"Here's some more data...\\n\";\nseek($fh, 0, 0);\nif ($pid=fork()) {\nwait;\n} else {\nsomething($) while <$fh>;\n}\n\n$dirorfile = $dir->next()\nA convenient way to iterate through directory contents. The first time \"next()\" is called,\nit will \"open()\" the directory and read the first item from it, returning the result as a\n\"Path::Class::Dir\" or Path::Class::File object (depending, of course, on its actual type).\nEach subsequent call to \"next()\" will simply iterate over the directory's contents, until\nthere are no more items in the directory, and then the undefined value is returned. For\nexample, to iterate over all the regular files in a directory:\n\nwhile (my $file = $dir->next) {\nnext unless -f $file;\nmy $fh = $file->open('r') or die \"Can't read $file: $!\";\n...\n}\n\nIf an error occurs when opening the directory (for instance, it doesn't exist or isn't\nreadable), \"next()\" will throw an exception with the value of $!.\n\n$dir->traverse( sub { ... }, @args )\nCalls the given callback for the root, passing it a continuation function which, when\ncalled, will call this recursively on each of its children. The callback function should be\nof the form:\n\nsub {\nmy ($child, $cont, @args) = @;\n# ...\n}\n\nFor instance, to calculate the number of files in a directory, you can do this:\n\nmy $nfiles = $dir->traverse(sub {\nmy ($child, $cont) = @;\nreturn sum($cont->(), ($child->isdir ? 0 : 1));\n});\n\nor to calculate the maximum depth of a directory:\n\nmy $depth = $dir->traverse(sub {\nmy ($child, $cont, $depth) = @;\nreturn max($cont->($depth + 1), $depth);\n}, 0);\n\nYou can also choose not to call the callback in certain situations:\n\n$dir->traverse(sub {\nmy ($child, $cont) = @;\nreturn if -l $child; # don't follow symlinks\n# do something with $child\nreturn $cont->();\n});\n\n$dir->traverseif( sub { ... }, sub { ... }, @args )\ntraverse with additional \"should I visit this child\" callback. Particularly useful in case\nexamined tree contains inaccessible directories.\n\nCanonical example:\n\n$dir->traverseif(\nsub {\nmy ($child, $cont) = @;\n# do something with $child\nreturn $cont->();\n},\nsub {\nmy ($child) = @;\n# Process only readable items\nreturn -r $child;\n});\n\nSecond callback gets single parameter: child. Only children for which it returns true will\nbe processed by the first callback.\n\nRemaining parameters are interpreted as in traverse, in particular \"traverseif(callback,\nsub { 1 }, @args\" is equivalent to \"traverse(callback, @args)\".\n\n$dir->recurse( callback => sub {...} )\nIterates through this directory and all of its children, and all of its children's children,\netc., calling the \"callback\" subroutine for each entry. This is a lot like what the\nFile::Find module does, and of course \"File::Find\" will work fine on Path::Class objects,\nbut the advantage of the \"recurse()\" method is that it will also feed your callback routine\n\"Path::Class\" objects rather than just pathname strings.\n\nThe \"recurse()\" method requires a \"callback\" parameter specifying the subroutine to invoke\nfor each entry. It will be passed the \"Path::Class\" object as its first argument.\n\n\"recurse()\" also accepts two boolean parameters, \"depthfirst\" and \"preorder\" that control\nthe order of recursion. The default is a preorder, breadth-first search, i.e. \"depthfirst =>\n0, preorder => 1\". At the time of this writing, all combinations of these two parameters are\nsupported *except* \"depthfirst => 0, preorder => 0\".\n\n\"callback\" is normally not required to return any value. If it returns special constant\n\"Path::Class::Entity::PRUNE()\" (more easily available as \"$item->PRUNE\"), no children of\nanalyzed item will be analyzed (mostly as if you set \"$File::Find::prune=1\"). Of course\npruning is available only in \"preorder\", in postorder return value has no effect.\n\n$st = $file->stat()\nInvokes \"File::stat::stat()\" on this directory and returns a \"File::stat\" object\nrepresenting the result.\n\n$st = $file->lstat()\nSame as \"stat()\", but if $file is a symbolic link, \"lstat()\" stats the link instead of the\ndirectory the link points to.\n\n$class = $file->fileclass()\nReturns the class which should be used to create file objects.\n\nGenerally overridden whenever this class is subclassed.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Ken Williams, kwilliams@cpan.org\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Path::Class, Path::Class::File, File::Spec\n",
                "subsections": []
            }
        }
    }
}