FileDirUtil
view release on metacpan or search on metacpan
lib/FileDirUtil.pm view on Meta::CPAN
# -*-CPerl-*-
# Last changed Time-stamp: <2019-08-23 20:19:04 mtw>
=head1 NAME
FileDirUtil - A Moose Role for basic File IO
=head1 SYNOPSIS
package FooBar;
use Moose;
with 'FileDirUtil';
sub BUILD {
my $self = shift;
$self->set_ifilebn;
}
=head1 DESCRIPTION
FileDirUtil is a convenience Moose Role for basic File IO, providing
transparent access to L<Path::Class::File> and L<Path::Class::Dir> for
input files and output directories, respectively, via the following
attributes:
=over 3
=item ifile
A string representing the path to an input file in platform-native
syntax, e.g. I<'moo/foo.bar'>. This will be coerced into a
L<Path::Class::File> object.
=item odir
A L<Path::Class::Dir> object or an ArrayRef specifying path segments
of directories which will be joined to create a single
L<Path::Class::Dir> directory object.
=back
=cut
package FileDirUtil;
use version; our $VERSION = qv('0.04');
use Moose::Util::TypeConstraints;
use Moose::Role;
use Path::Class::File;
use Path::Class::Dir;
use File::Basename;
use Params::Coerce ();
use namespace::autoclean;
subtype 'MyFile' => as class_type('Path::Class::File');
coerce 'MyFile'
=> from 'Str'
=> via { Path::Class::File->new($_) };
subtype 'MyDir' => as class_type('Path::Class::Dir');
coerce 'MyDir'
=> from 'Object'
=> via {$_ -> isa('Path::Class::Dir') ? $_ : Params::Coerce::coerce ('Path::Class::Dir', $_); }
=> from 'ArrayRef'
=> via { Path::Class::Dir->new( @{ $_ } ) };
has 'ifile' => (
is => 'ro',
isa => 'MyFile',
predicate => 'has_ifile',
coerce => 1,
);
has 'ifilebn' => (
is => 'rw',
isa => 'Str',
predicate => 'has_ifilebn',
init_arg => undef, # make this unsettable via constructor
);
( run in 0.582 second using v1.01-cache-2.11-cpan-e1769b4cff6 )