Venus
view release on metacpan or search on metacpan
lib/Venus/Path.pm view on Meta::CPAN
with 'Venus::Role::Valuable';
with 'Venus::Role::Buildable';
with 'Venus::Role::Accessible';
with 'Venus::Role::Explainable';
# OVERLOADS
use overload (
'""' => 'explain',
'eq' => sub{$_[0]->value eq "$_[1]"},
'ne' => sub{$_[0]->value ne "$_[1]"},
'qr' => sub{qr/@{[quotemeta($_[0]->value)]}/},
'~~' => 'explain',
fallback => 1,
);
# HOOKS
sub _exitcode {
$? >> 8;
}
# METHODS
sub absolute {
my ($self) = @_;
require File::Spec;
return $self->class->new(File::Spec->rel2abs($self->get));
}
sub basename {
my ($self) = @_;
require File::Basename;
return File::Basename::basename($self->get);
}
sub child {
my ($self, $path) = @_;
require File::Spec;
my @parts = File::Spec->splitdir($path);
return $self->class->new(File::Spec->catfile($self->get, @parts));
}
sub chmod {
my ($self, $mode) = @_;
my $path = $self->get;
CORE::chmod($mode, $path);
return $self;
}
sub chown {
my ($self, @args) = @_;
my $path = $self->get;
CORE::chown((map $_||-1, @args[0,1]), $path);
return $self;
}
sub children {
my ($self) = @_;
require File::Spec;
my @paths = map $self->glob($_), '.??*', '*';
return wantarray ? (@paths) : \@paths;
}
sub copy {
my ($self, $path) = @_;
require File::Copy;
File::Copy::copy("$self", "$path") or my $error = $!;
if ($error) {
$self->error_on_copy({error => $error, path => $path})
->input($self, $path)
->output($error)
->throw;
}
return $self;
}
sub default {
require Cwd;
return Cwd::getcwd();
}
sub directories {
my ($self) = @_;
my @paths = grep -d, $self->children;
return wantarray ? (@paths) : \@paths;
}
sub exists {
my ($self) = @_;
return int!!-e $self->get;
}
sub explain {
my ($self) = @_;
return $self->get;
}
sub extension {
my ($self, $value) = @_;
my $basename = $self->basename;
lib/Venus/Path.pm view on Meta::CPAN
=head2 children
children() (within[arrayref, Venus::Path])
The children method returns the files and directories under the path. This
method can return a list of values in list-context.
I<Since C<0.01>>
=over 4
=item children example 1
# given: synopsis;
my $children = $path->children;
# [
# bless({ value => "t/data/planets/ceres" }, "Venus::Path"),
# bless({ value => "t/data/planets/earth" }, "Venus::Path"),
# bless({ value => "t/data/planets/eris" }, "Venus::Path"),
# bless({ value => "t/data/planets/haumea" }, "Venus::Path"),
# bless({ value => "t/data/planets/jupiter" }, "Venus::Path"),
# bless({ value => "t/data/planets/makemake" }, "Venus::Path"),
# bless({ value => "t/data/planets/mars" }, "Venus::Path"),
# bless({ value => "t/data/planets/mercury" }, "Venus::Path"),
# bless({ value => "t/data/planets/neptune" }, "Venus::Path"),
# bless({ value => "t/data/planets/planet9" }, "Venus::Path"),
# bless({ value => "t/data/planets/pluto" }, "Venus::Path"),
# bless({ value => "t/data/planets/saturn" }, "Venus::Path"),
# bless({ value => "t/data/planets/uranus" }, "Venus::Path"),
# bless({ value => "t/data/planets/venus" }, "Venus::Path"),
# ]
=back
=cut
=head2 chmod
chmod(string $mode) (Venus::Path)
The chmod method changes the file permissions of the file or directory.
I<Since C<0.01>>
=over 4
=item chmod example 1
# given: synopsis;
$path = $path->chmod(0755);
# bless({ value => "t/data/planets" }, "Venus::Path")
=back
=cut
=head2 chown
chown(string @args) (Venus::Path)
The chown method changes the group and/or owner or the file or directory.
I<Since C<0.01>>
=over 4
=item chown example 1
# given: synopsis;
$path = $path->chown(-1, -1);
# bless({ value => "t/data/planets" }, "Venus::Path")
=back
=cut
=head2 copy
copy(string | Venus::Path $path) (Venus::Path)
The copy method uses L<File::Copy/copy> to copy the file represented by the
invocant to the path provided and returns the invocant.
I<Since C<2.80>>
=over 4
=item copy example 1
# given: synopsis
package main;
my $copy = $path->child('mercury')->copy($path->child('yrucrem'));
# bless({...}, 'Venus::Path')
=back
=over 4
=item B<may raise> L<Venus::Path::Error> C<on.copy>
package main;
use Venus::Path;
my $path = Venus::Path->new('t/data/planets');
$path->copy('/path/to/nowhere');
# Error! (on.copy)
=back
=cut
=head2 default
default() (string)
The default method returns the default value, i.e. C<$ENV{PWD}>.
I<Since C<0.01>>
=over 4
=item default example 1
( run in 0.515 second using v1.01-cache-2.11-cpan-5511b514fd6 )