NAME
App::Kit::Obj::FS - file system utility object
VERSION
This document describes App::Kit::Obj::FS version 0.1
SYNOPSIS
my $fs = App::Kit::Obj::FS->new();
my @guts = $fs->read_file(…);
DESCRIPTION
file system utility object
INTERFACE
new()
Returns the object.
Takes one required attribute: _app. It should be an App::Kit object for it to use internally.
Has 3 optional attributes:
spec
Lazy loads File::Spec and returns the class accessor for File::Spec methods. Setting this via new() is probably not a good idea.
my $dir = $fs->spec->catdir(…);
bindir
The applications main directory. Defaults to script’s directory or the current working directory.
inc
An array ref of paths for file_lookup() to use. Defaults to [].
cwd()
Lazy wrapper of Cwd’s cwd().
file_lookup()
In scalar context returns the first path that exists for the given arguments.
In array context returns all possible paths for the given arguments without any existence check.
The final argument can be a config hashref with the inc key whose value is an array of paths.
The arguments are the pieces of the path you are interested in that get put together in a portable way.
my $conf = $fs->file_lookup('data', 'foo.json'); # e.g. …/my_app_base/.appkit.d/data/foo.json
The path is looked for in this order:
1. the 'inc' paths in the given argument if any
2. a directory in the object’s base path called .$prefix.d (where $prefix is the _app attributes’s ->str->prefix).
3. the objects’s inc attribute
mkpath()
Lazy wrapper of File::Path::Tiny’s mk().
rmpath()
Lazy wrapper of File::Path::Tiny’s rm().
empty_dir()
Lazy wrapper of File::Path::Tiny’s empty_dir().
mk_parent()
Lazy wrapper of File::Path::Tiny’s mk_parent().
tmpfile()
Lazy wrapper of File::Temp’s tmpfile().
tmpdir()
Lazy wrapper of File::Temp’s tmpdir().
read_dir()
Lazy wrapper of File::Slurp’s read_dir().
read_file()
Lazy wrapper of File::Slurp’s read_file().
write_file()
Lazy wrapper of File::Slurp’s write_file().
json_read()
Lazy wrapper to consistently load a JSON file to a data structure.
my $data = $fs->read_json($file);
json_write()
Lazy wrapper to consistently write a data structure as a JSON file.
$fs->write_json($file, $data);
yaml_read()
Lazy wrapper to consistently load a YAML file to a data structure.
my $data = $fs->read_yaml($file);
yaml_write()
Lazy wrapper to consistently write a data structure as a YAML file.
$fs->write_yaml($file, $data);
get_iterator()
Lazy wrapper of Path::Iter’s get_iterator().
DIAGNOSTICS
CONFIGURATION AND ENVIRONMENT
Requires no configuration files or environment variables.
DEPENDENCIES
Moo for the object.
Lazy loaded as needed:
Cwd File::Path::Tiny File::Temp File::Slurp Path::Iter File::Spec FindBinCwd
INCOMPATIBILITIES
None reported.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests to bug-app-kit@rt.cpan.org
, or through the web interface at http://rt.cpan.org.
AUTHOR
Daniel Muey <http://drmuey.com/cpan_contact.pl>
LICENCE AND COPYRIGHT
Copyright (c) 2013, Daniel Muey <http://drmuey.com/cpan_contact.pl>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.