1 package Path::Class::Entity;
19 my ($class, $fs_class) = (ref($from)
20 ? (ref $from, $from->{file_spec_class})
21 : ($from, $Path::Class::Foreign));
22 return bless {file_spec_class => $fs_class}, $class;
28 my ($class, $type) = @_;
30 die "Invalid system type '$type'" unless ($type) = $type =~ /^(\w+)$/; # Untaint
31 my $spec = "File::Spec::$type";
32 eval "require $spec; 1" or die $@;
37 my ($class, $type) = (shift, shift);
38 local $Path::Class::Foreign = $class->_spec_class($type);
39 return $class->new(@_);
42 sub _spec { $_[0]->{file_spec_class} || 'File::Spec' }
47 # 5.6.0 has a bug with regexes and stringification that's ticked by
48 # file_name_is_absolute(). Help it along with an explicit stringify().
49 $_[0]->_spec->file_name_is_absolute($_[0]->stringify)
52 sub is_relative { ! $_[0]->is_absolute }
56 my $cleaned = $self->new( $self->_spec->canonpath($self) );
63 my $cleaned = $self->new( Cwd::realpath($self->stringify) );
65 # realpath() always returns absolute path, kind of annoying
66 $cleaned = $cleaned->relative if $self->is_relative;
74 return $self if $self->is_absolute;
75 return $self->new($self->_spec->rel2abs($self->stringify, @_));
80 return $self->new($self->_spec->abs2rel($self->stringify, @_));
83 sub stat { File::stat::stat("$_[0]") }
84 sub lstat { File::stat::lstat("$_[0]") }