Skip to content

Commit

Permalink
tests and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 7, 2017
1 parent 2808cf5 commit f3d9f5d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
34 changes: 18 additions & 16 deletions lib/Mojo/File.pm
Expand Up @@ -128,7 +128,7 @@ sub to_string {"${$_[0]}"}
=head1 NAME
Mojo::File - File paths
Mojo::File - File system paths
=head1 SYNOPSIS
Expand All @@ -146,11 +146,12 @@ Mojo::File - File paths
=head1 DESCRIPTION
L<Mojo::File> is a scalar-based container for file system paths.
L<Mojo::File> is a scalar-based container for file system paths that provides a
friendly API for dealing with different operating systems.
# Access scalar directly to manipulate path
my $path = Mojo::File->new('/home/sri/');
$$path .= '.vimrc';
my $path = Mojo::File->new('/home/sri/test');
$$path .= '.txt';
=head1 FUNCTIONS
Expand All @@ -171,7 +172,8 @@ working directory.
my $path = tempdir;
my $path = tempdir('tempXXXXX');
Construct a new scalar-based L<Mojo::File> object with L<File::Temp>.
Construct a new scalar-based L<Mojo::File> object for a temporary directory with
L<File::Temp>.
# Longer version
my $path = Mojo::File->new(File::Temp->newdir('tempXXXXX'));
Expand All @@ -185,7 +187,7 @@ L<Mojo::File> implements the following methods.
my $name = $path->basename;
my $name = $path->basename('.txt');
Return the last level of the path with L<File::Basename> as a string.
Return the last level of the path with L<File::Basename>.
# ".vimrc" (on UNIX)
Mojo::File->new('/home/sri/.vimrc')->basename;
Expand All @@ -197,7 +199,7 @@ Return the last level of the path with L<File::Basename> as a string.
my $child = $path->child('.vimrc');
Return a new L<Mojo::File> object relative to the original.
Return a new L<Mojo::File> object relative to the path.
# "/home/sri/.vimrc" (on UNIX)
Mojo::File->new('/home')->child('sri', '.vimrc');
Expand All @@ -216,7 +218,7 @@ L<Mojo::File> object.
my $bool = $path->is_abs;
Check if path is absolute.
Check if the path is absolute.
# True (on UNIX)
Mojo::File->new('/home/sri/.vimrc')->is_abs;
Expand All @@ -229,8 +231,8 @@ Check if path is absolute.
my $collection = $path->list;
my $collection = $path->list({hidden => 1});
List all files in a directory and return a L<Mojo::Collection> object containing
the results as L<Mojo::File> objects.
List all files in the directory and return a L<Mojo::Collection> object
containing the results as L<Mojo::File> objects.
# List files
say for Mojo::File->new('/home/sri/myapp')->list->each;
Expand Down Expand Up @@ -258,7 +260,7 @@ Include hidden files.
my $collection = $path->list_tree;
my $collection = $path->list_tree({hidden => 1});
List all files recursively in a directory and return a L<Mojo::Collection>
List all files recursively in the directory and return a L<Mojo::Collection>
object containing the results as L<Mojo::File> objects.
# List all templates
Expand All @@ -280,13 +282,13 @@ Include hidden files and directories.
$path = $path->make_path;
Create the given directories if they don't exist already with L<File::Path>.
Create the directories if they don't already exist with L<File::Path>.
=head2 move_to
$path = $path->move_to('/home/sri/.vimrc.backup');
Move file with L<File::Copy>.
Move the file.
=head2 new
Expand All @@ -301,13 +303,13 @@ directory.
my $bytes = $path->slurp;
Read all data at once from file.
Read all data at once from the file.
=head2 spurt
$path = $path->spurt($bytes);
Write all data at once to file.
Write all data at once to the file.
=head2 tap
Expand Down Expand Up @@ -344,7 +346,7 @@ L<Mojo::File> object.
my $str = $path->to_string;
Turn path into a string.
Stringify the path.
=head1 OPERATORS
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojolicious/Guides.pod
Expand Up @@ -461,6 +461,8 @@ This is the class hierarchy of the L<Mojolicious> distribution.

=item * L<Mojo::DOM>

=item * L<Mojo::File>

=item * L<Mojo::JSON>

=item * L<Mojo::Loader>
Expand Down
3 changes: 3 additions & 0 deletions t/mojo/file.t
Expand Up @@ -52,6 +52,9 @@ my $path = "$dir";
ok -d $path, 'directory exists';
undef $dir;
ok !-d $path, 'directory does not exist anymore';
$dir = tempdir 'mytestXXXXX';
ok -d $dir, 'directory exists';
like $dir->basename, qr/mytest.{5}$/, 'right format';

# Make path
$dir = tempdir;
Expand Down

0 comments on commit f3d9f5d

Please sign in to comment.