Path::Extended::Class::Dir - Path::Extended::Class::Dir documentation


Path-Extended documentation Contained in the Path-Extended distribution.

Index


Code Index:

NAME

Top

Path::Extended::Class::Dir

DESCRIPTION

Top

Path::Extended::Class::Dir behaves pretty much like Path::Class::Dir and can do some extra things. See appropriate pods for details.

COMPATIBLE METHODS

Top

absolute, relative

change how to stringify internally and return the file object (instead of the path itself).

mkdir, mkpath

create a directory with File::Path, and return the result (instead of the directory object itself).

rmtree, rmdir, remove

remove a directory with File::Path, and return the result (instead of the directory object itself).

dir_list

returns parts of the path. See Path::Class::Dir for details.

tempfile

returns a temporary file handle (and its corresponding file name in a list context). See Path::Class::Dir and File::Temp for details

INCOMPATIBLE METHODS

Top

cleanup

does nothing but returns the object to chain. Path::Extended::Class should always return a canonical path.

as_foreign

does nothing but returns the object to chain. Path::Extended::Class doesn't support foreign path expressions.

new_foreign

returns a new Path::Extended::Class::Dir object whatever the type is specified.

SEE ALSO

Top

Path::Extended::Class, Path::Extended::Dir, Path::Class::Dir

AUTHOR

Top

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Top


Path-Extended documentation Contained in the Path-Extended distribution.

package Path::Extended::Class::Dir;

use strict;
use warnings;
use base qw( Path::Extended::Dir );

sub _initialize {
  my ($self, @args) = @_;

  return if @args && !defined $args[0];

  my $dir = @args ? File::Spec->catdir( @args ) : File::Spec->curdir;

  $self->{path}      = $self->_unixify( File::Spec->rel2abs($dir) );
  $self->{is_dir}    = 1;
  $self->{_compat}   = 1;
  $self->{_absolute} = File::Spec->file_name_is_absolute( $dir );

  $self;
}

sub new_foreign {
  my ($class, $type, @args) = @_;
  $class->new(@args);
}

sub absolute {
  my $self = shift;
  $self->{_base} = undef;
  $self;
}

sub relative {
  my $self = shift;
  my $base = @_ % 2 ? shift : undef;
  my %options = @_;
  $self->{_base} = $base || $options{base} || File::Spec->curdir;
  $self;
}

sub cleanup    { shift } # is always clean
sub as_foreign { shift } # does nothing

sub dir_list {
  my $self = shift;

  my @parts = $self->_parts;
  return @parts unless @_;

  my $offset = shift;
  $offset = @parts + $offset if $offset < 0;

  return wantarray ? @parts[$offset .. $#parts] : $parts[$offset] unless @_;

  my $length = shift;
  $length = @parts + $length - $offset if $length < 0;
  return @parts[$offset .. $length + $offset - 1];
}

sub tempfile {
  my $self = shift;
  require File::Temp;
  return File::Temp::tempfile(@_, DIR => $self->stringify);
}

sub mkdir {require File::Path; File::Path::mkpath(shift->path, @_)}
sub rmdir {require File::Path; File::Path::rmtree(shift->path, @_)}
*mkpath = \&mkdir;
*rmtree = *remove = \&rmdir;

1;

__END__