Skip to content

Commit

Permalink
functions look better in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 5, 2017
1 parent 71a7882 commit d815ed2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
10 changes: 5 additions & 5 deletions lib/Mojo/Collection.pm
Expand Up @@ -170,7 +170,7 @@ Create a new collection with all elements that are defined and not an empty
string.
# "0, 1, 2, 3"
Mojo::Collection->new(0, 1, undef, 2, '', 3)->compact->join(', ');
c(0, 1, undef, 2, '', 3)->compact->join(', ');
=head2 each
Expand Down Expand Up @@ -217,7 +217,7 @@ Flatten nested collections/arrays recursively and create a new collection with
all elements.
# "1, 2, 3, 4, 5, 6, 7"
Mojo::Collection->new(1, [2, [3, 4], 5, [6]], 7)->flatten->join(', ');
c(1, [2, [3, 4], 5, [6]], 7)->flatten->join(', ');
=head2 grep
Expand Down Expand Up @@ -309,7 +309,7 @@ Create a new collection with all elements in reverse order.
Create a new collection with all selected elements.
# "B C E"
Mojo::Collection->new('A', 'B', 'C', 'D', 'E')->slice(1, 2, 4)->join(' ');
c('A', 'B', 'C', 'D', 'E')->slice(1, 2, 4)->join(' ');
=head2 shuffle
Expand Down Expand Up @@ -362,10 +362,10 @@ callback/method.
my $new = $collection->uniq(sub { $_->some_method(@args) });
# "foo bar baz"
Mojo::Collection->new('foo', 'bar', 'bar', 'baz')->uniq->join(' ');
c('foo', 'bar', 'bar', 'baz')->uniq->join(' ');
# "[[1, 2], [2, 1]]"
Mojo::Collection->new([1, 2], [2, 1], [3, 2])->uniq(sub{ $_->[1] })->to_array;
c([1, 2], [2, 1], [3, 2])->uniq(sub{ $_->[1] })->to_array;
=head1 SEE ALSO
Expand Down
23 changes: 12 additions & 11 deletions lib/Mojo/File.pm
Expand Up @@ -209,10 +209,10 @@ L<Mojo::File> implements the following methods.
Return the last level of the path with L<File::Basename>.
# ".vimrc" (on UNIX)
Mojo::File->new('/home/sri/.vimrc')->basename;
path('/home/sri/.vimrc')->basename;
# "test" (on UNIX)
Mojo::File->new('/home/sri/test.txt')->basename('.txt');
path('/home/sri/test.txt')->basename('.txt');
=head2 child
Expand All @@ -221,7 +221,7 @@ Return the last level of the path with L<File::Basename>.
Return a new L<Mojo::File> object relative to the path.
# "/home/sri/.vimrc" (on UNIX)
Mojo::File->new('/home')->child('sri', '.vimrc');
path('/home')->child('sri', '.vimrc');
=head2 dirname
Expand All @@ -231,7 +231,7 @@ Return all but the last level of the path with L<File::Basename> as a
L<Mojo::File> object.
# "/home/sri" (on UNIX)
Mojo::File->new('/home/sri/.vimrc')->dirname;
path('/home/sri/.vimrc')->dirname;
=head2 is_abs
Expand All @@ -240,10 +240,10 @@ L<Mojo::File> object.
Check if the path is absolute.
# True (on UNIX)
Mojo::File->new('/home/sri/.vimrc')->is_abs;
path('/home/sri/.vimrc')->is_abs;
# False (on UNIX)
Mojo::File->new('.vimrc')->is_abs;
path('.vimrc')->is_abs;
=head2 list
Expand All @@ -255,7 +255,7 @@ containing the results as L<Mojo::File> objects. The list does not include C<.>
and C<..>.
# List files
say for Mojo::File->new('/home/sri/myapp')->list->each;
say for path('/home/sri/myapp')->list->each;
These options are currently available:
Expand Down Expand Up @@ -285,7 +285,7 @@ object containing the results as L<Mojo::File> objects. The list does not
include C<.> and C<..>.
# List all templates
say for Mojo::File->new('/home/sri/myapp/templates')->list_tree->each;
say for path('/home/sri/myapp/templates')->list_tree->each;
These options are currently available:
Expand Down Expand Up @@ -318,6 +318,7 @@ Move the file with L<File::Copy>.
my $path = Mojo::File->new;
my $path = Mojo::File->new('/home/sri/.vimrc');
my $path = Mojo::File->new('/home', 'sri', '.vimrc');
my $path = Mojo::File->new(File::Temp->new);
my $path = Mojo::File->new(File::Temp->newdir);
Construct a new L<Mojo::File> object, defaults to using the current working
Expand All @@ -337,7 +338,7 @@ Open file with L<IO::File>.
# Combine "fcntl.h" constants
use Fcntl qw(O_CREAT O_EXCL O_RDWR);
my $handle = Mojo::File->new('/tmp/test.pl')->open(O_RDWR | O_CREAT | O_EXCL);
my $handle = path('/home/sri/test.pl')->open(O_RDWR | O_CREAT | O_EXCL);
=head2 remove_tree
Expand Down Expand Up @@ -379,7 +380,7 @@ Return the canonical path as a L<Mojo::File> object.
Split the path on directory separators.
# "home:sri:.vimrc" (on UNIX)
join ':', @{Mojo::File->new('/home/sri/.vimrc')->to_array};
join ':', @{path('/home/sri/.vimrc')->to_array};
=head2 to_rel
Expand All @@ -389,7 +390,7 @@ Return a relative path from the original path to the destination path as a
L<Mojo::File> object.
# "sri/.vimrc" (on UNIX)
Mojo::File->new('/home/sri/.vimrc')->to_rel('/home');
path('/home/sri/.vimrc')->to_rel('/home');
=head2 to_string
Expand Down

0 comments on commit d815ed2

Please sign in to comment.