File-System

 view release on metacpan or  search on metacpan

lib/File/System/Real.pm  view on Meta::CPAN

			$result .= 'd' if -d $self->{fullpath};
			$result .= 'f' if -f $self->{fullpath};
			return $result;
		};
		/^dev$/      && do {
			return $self->_stat->[0];
		};
		/^ino$/      && do {
			return $self->_stat->[1];
		};
		/^mode$/     && do {
			return $self->_stat->[2];
		};
		/^nlink$/    && do {
			return $self->_stat->[3];
		};
		/^uid$/      && do {
			return $self->_stat->[4];
		};
		/^gid$/      && do {
			return $self->_stat->[5];
		};
		/^rdev$/     && do {
			return $self->_stat->[6];
		};
		/^size$/     && do {
			return $self->_stat->[7];
		};
		/^atime$/    && do {
			return $self->_stat->[8];
		};
		/^mtime$/    && do {
			return $self->_stat->[9];
		};
		/^ctime$/    && do {
			return $self->_stat->[10];
		};
		/^blksize$/  && do {
			return $self->_stat->[11];
		};
		/^blocks$/   && do {
			return $self->_stat->[12];
		};
		DEFAULT: {
			return undef;
		}
	}
}

sub set_property {
	my $self  = shift;
	local $_  = shift;
	my $value = shift;

	SWITCH: {
		/^mode$/ && do {
			chmod $value, $self->{fullpath};
			last SWITCH;
		};
		/^uid$/ && do {
			chown $value, $self->get_property('gid'), $self->{fullpath};
			last SWITCH;
		};
		/^gid$/ && do {
			chown $self->get_property('uid'), $value, $self->{fullpath};
			last SWITCH;
		};
		/^atime$/ && do {
			utime $value, $self->get_property('mtime'), $self->{fullpath};
			last SWITCH;
		};
		/^mtime$/ && do {
			utime $self->get_property('atime'), $value, $self->{fullpath};
			last SWITCH;
		};
		DEFAULT: {
			croak "Cannot set unknown property '$_'";
		}
	}
}

sub is_creatable {
	my $self = shift;
	my $path = shift;
	my $type = shift;

	defined $type
		or croak "No type argument given.";

	return ($type eq 'f' || $type eq 'd') && !$self->exists($path);
}

sub create {
	my $self = shift;
	my $path = shift;
	my $type = shift;

	defined $type
		or croak "Missing required argument 'type'.";

	if ($type eq 'f') {	
		my $fulldir = $self->dirname_of_path($self->normalize_real_path($path));

		File::Path::mkpath($fulldir, 0);

		my $abspath  = $self->normalize_path($path);
		my $fullpath = $self->normalize_real_path($path);

		my $fh = FileHandle->new(">$fullpath")
			or croak "Cannot create file $abspath: $!";
		close $fh;

		return bless {
			fs_root  => $self->{fs_root},
			path     => $abspath,
			fullpath => $fullpath,
		}, ref $self;
	} elsif ($type eq 'd') {
		my $abspath  = $self->normalize_path($path);
		my $fullpath = $self->normalize_real_path($path);

		File::Path::mkpath($fullpath, 0);

		-d $fullpath
			or croak "Failed to create directory '$abspath'";



( run in 1.325 second using v1.01-cache-2.11-cpan-71847e10f99 )