App::Kit::Obj::FS - file system utility object
This document describes App::Kit::Obj::FS version 0.1
my $fs = App::Kit::Obj::FS->new(); my @guts = $fs->read_file(…);
file system utility object
Returns the object.
Takes one required attribute: _app. It should be an App::Kit object for it to use internally.
Has 3 optional attributes:
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(…);
The applications main directory. Defaults to script’s directory or the current working directory.
Lazy loads FindBin and Cwd.
Works with .psgi files being run under Plack/PSGI.
An array ref of paths for file_lookup() to use. Defaults to [].
Lazy wrapper of Cwd’s cwd().
The directory that belongs to the app.
It is a directory in the object’s base path called .$prefix.d (where $prefix is the _app attributes’s ->str->prefix):
$fs->bindir()/.$str->prefix().d/
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_bindir/.appkit.d/data/foo.json
The path is looked for in this order:
1. the 'inc' paths in the given argument if any
2. appdir()
3. the objects’s inc attribute
Lazy wrapper of File::Path::Tiny’s mk().
Lazy wrapper of File::Path::Tiny’s rm().
Lazy wrapper of File::Path::Tiny’s empty_dir().
Lazy wrapper of File::Path::Tiny’s mk_parent().
Lazy wrapper of File::Temp’s tmpfile().
Lazy wrapper of File::Temp’s tmpdir().
Lazy wrapper of File::Slurp’s read_dir().
Lazy wrapper of File::Slurp’s read_file().
Lazy wrapper of File::Slurp’s write_file().
Lazy wrapper to consistently load a JSON file to a data structure.
my $data = $fs->read_json($file);
Lazy wrapper to consistently write a data structure as a JSON file.
$fs->write_json($file, $data);
Lazy wrapper to consistently load a YAML file to a data structure.
my $data = $fs->read_yaml($file);
Lazy wrapper to consistently write a data structure as a YAML file.
$fs->write_yaml($file, $data);
Lazy wrapper of Path::Iter’s get_iterator().
Takes a bytes string (utf8 if encoding matters in your context) and returns true if it safe to use as part of a path name.
e.g.:
foo # safe .. # not safe f\x00o # not safe f\x{2665}o # not safe f\xe2\x99\xa5o # safe
Takes a bytes string (utf8 if encoding matters in your context) and returns true if it is safe to use as a path name.
foo/bar # safe foo/../bar # not safe f\x00o/bar # not safe f\x{2665}o/bar # not safe f\xe2\x99\xa5o/bar # safe
2nd arg: boolean (default false) to allow absolute paths.
/foo/bar # now safe
3rd arg: boolean (default false) to allow trailing path separator
foo/bar/ # now safe
'inc' must be an array ref
The value given for 'inc' was not an array ref.
Requires no configuration files or environment variables.
Moo for the object.
Lazy loaded as needed:
Cwd File::Path::Tiny File::Temp File::Slurp Path::Iter File::Spec FindBinCwd
None reported.
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.
bug-app-kit@rt.cpan.org
Daniel Muey <http://drmuey.com/cpan_contact.pl>
<http://drmuey.com/cpan_contact.pl>
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.
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.
To install App::Kit, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Kit
CPAN shell
perl -MCPAN -e shell install App::Kit
For more information on module installation, please visit the detailed CPAN module installation guide.