Creates a new Path::Class::Dir object and returns it. The arguments specify names of directories which will be joined to create a single directory object. A volume may also be specified as the first argument, or as part of the first argument. You can use platform-neutral syntax:

my $dir = dir( 'foo', 'bar', 'baz' );

or platform-native syntax:

my $dir = dir( 'foo/bar/baz' );

or a mixture of the two:

my $dir = dir( 'foo/bar', 'baz' );

All three of the above examples create relative paths. To create an absolute path, either use the platform native syntax for doing so:

my $dir = dir( '/var/tmp' );

or use an empty string as the first argument:

my $dir = dir( '', 'var', 'tmp' );

If the second form seems awkward, that's somewhat intentional - paths like /var/tmp or \Windows aren't cross-platform concepts in the first place (many non-Unix platforms don't have a notion of a "root directory"), so they probably shouldn't appear in your code if you're trying to be cross-platform. The first form is perfectly natural, because paths like this may come from config files, user input, or whatever.

As a special case, since it doesn't otherwise mean anything useful and it's convenient to define this way, Path::Class::Dir->new() (or dir()) refers to the current directory (File::Spec->curdir). To get the current directory as an absolute path, do dir()->absolute.

Finally, as another special case dir(undef) will return undef, since that's usually an accident on the part of the caller, and returning the root directory would be a nasty surprise just asking for trouble a few lines later.

Returns the parent directory of $dir. Note that this is the logical parent, not necessarily the physical parent. It really means we just chop off entries from the end of the directory list until we cain't chop no more. If the directory is relative, we start using the relative forms of parent directories.

The following code demonstrates the behavior on absolute and relative directories:

Returns a list of Path::Class::File and/or Path::Class::Dir objects listed in this directory, or in scalar context the number of such objects. Obviously, it is necessary for $dir to exist and be readable in order to find its children.

Note that the children are returned as subdirectories of $dir, i.e. the children of foo will be foo/bar and foo/baz, not bar and baz.

Ordinarily children() will not include the self and parent entries . and .. (or their equivalents on non-Unix systems), because that's like I'm-my-own-grandpa business. If you do want all directory entries including these special ones, pass a true value for the all parameter:

Returns a Path::Class::Dir object representing $dir as an absolute path. An optional argument, given as either a string or a Path::Class::Dir object, specifies the directory to use as the base of relativity - otherwise the current working directory will be used.

Returns a Path::Class::Dir object representing $dir as a relative path. An optional argument, given as either a string or a Path::Class::Dir object, specifies the directory to use as the base of relativity - otherwise the current working directory will be used.

Returns true if this directory spec subsumes the other spec, and false otherwise. Think of "subsumes" as "contains", but we only look at the specs, not whether $dir actually contains $other on the filesystem.

The $other argument may be a Path::Class::Dir object, a Path::Class::File object, or a string. In the latter case, we assume it's a directory.

Returns a Path::Class::Dir object representing $dir as it would be specified on a system of type $type. Known types include Unix, Win32, Mac, VMS, and OS2, i.e. anything for which there is a subclass of File::Spec.

Any generated objects (subdirectories, files, parents, etc.) will also retain this type.

Returns a Path::Class::Dir object representing $dir as it would be specified on a system of type $type. Known types include Unix, Win32, Mac, VMS, and OS2, i.e. anything for which there is a subclass of File::Spec.

The arguments in @args are the same as they would be specified in new().

Returns the list of strings internally representing this directory structure. Each successive member of the list is understood to be an entry in its predecessor's directory list. By contract, Path::Class->new( $dir->dir_list ) should be equivalent to $dir.

The semantics of this method are similar to Perl's splice or substr functions; they return LENGTH elements starting at OFFSET. If LENGTH is omitted, returns all the elements starting at OFFSET up to the end of the list. If LENGTH is negative, returns the elements from OFFSET onward except for -LENGTH elements at the end. If OFFSET is negative, it counts backward OFFSET elements from the end of the list. If OFFSET and LENGTH are both omitted, the entire list is returned.

In a scalar context, dir_list() with no arguments returns the number of entries in the directory list; dir_list(OFFSET) returns the single element at that offset; dir_list(OFFSET, LENGTH) returns the final element that would have been returned in a list context.

Identical to dir_list(). It exists because there's an analogous method dir_list() in the Path::Class::File class that also returns the basename string, so this method lets someone call components() without caring whether the object is a file or a directory.

Removes the directory, which must be empty. Returns a boolean value indicating whether or not the directory was successfully removed. This method is mainly provided for consistency with Path::Class::File's remove() method.

An interface to File::Temp's tempfile() function. Just like that function, if you call this in a scalar context, the return value is the filehandle and the file is unlinked as soon as possible (which is immediately on Unix-like platforms). If called in a list context, the return values are the filehandle and the filename.

A convenient way to iterate through directory contents. The first time next() is called, it will open() the directory and read the first item from it, returning the result as a Path::Class::Dir or Path::Class::File object (depending, of course, on its actual type). Each subsequent call to next() will simply iterate over the directory's contents, until there are no more items in the directory, and then the undefined value is returned. For example, to iterate over all the regular files in a directory:

Iterates through this directory and all of its children, and all of its children's children, etc., calling the callback subroutine for each entry. This is a lot like what the File::Find module does, and of course File::Find will work fine on Path::Class objects, but the advantage of the recurse() method is that it will also feed your callback routine Path::Class objects rather than just pathname strings.

The recurse() method requires a callback parameter specifying the subroutine to invoke for each entry. It will be passed the Path::Class object as its first argument.

recurse() also accepts two boolean parameters, depthfirst and preorder that control the order of recursion. The default is a preorder, breadth-first search, i.e. depthfirst => 0, preorder => 1. At the time of this writing, all combinations of these two parameters are supported exceptdepthfirst => 0, preorder => 0.

callback is normally not required to return any value. If it returns special constant Path::Class::Entity::PRUNE() (more easily available as $item->PRUNE), no children of analyzed item will be analyzed (mostly as if you set $File::Find::prune=1). Of course pruning is available only in preorder, in postorder return value has no effect.