Skip to content

Commit

Permalink
fix bug where the results of the list_files method in Mojo::Home woul…
Browse files Browse the repository at this point in the history
…d include directories
  • Loading branch information
kraih committed Feb 22, 2016
1 parent 43b77bf commit ea8dc33
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

6.48 2016-02-22
- Fixed bug where the results of the list_files method in Mojo::Home would
include directories.

6.47 2016-02-19
- Deprecated Mojo::Log::is_debug, Mojo::Log::is_error, Mojo::Log::is_info and
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Date.pm
Expand Up @@ -58,7 +58,7 @@ sub to_datetime {
my ($s, $m, $h, $day, $month, $year) = gmtime(my $epoch = shift->epoch);
my $str = sprintf '%04d-%02d-%02dT%02d:%02d:%02d', $year + 1900, $month + 1,
$day, $h, $m, $s;
return $str . ($epoch =~ /(\.\d+)$/ ? "$1Z" : 'Z');
return $str . ($epoch =~ /(\.\d+)$/ ? $1 : '') . 'Z';
}

sub to_string {
Expand Down
15 changes: 7 additions & 8 deletions lib/Mojo/Home.pm
Expand Up @@ -39,15 +39,14 @@ sub lib_dir {
}

sub list_files {
my ($self, $dir) = @_;
my ($self, $dir) = (shift, shift // '');

$dir = catdir @{$self->parts}, split('/', $dir // '');
return [] unless -d $dir;
my @files;
return \@files unless -d ($dir = catdir @{$self->parts}, split('/', $dir));
find {
wanted => sub {
my @parts = splitdir abs2rel($File::Find::name, $dir);
push @files, join '/', @parts unless grep {/^\./} @parts;
push @files, join '/', splitdir abs2rel($File::Find::name, $dir)
unless -d $File::Find::name;
},
no_chdir => 1
}, $dir;
Expand Down Expand Up @@ -124,10 +123,10 @@ Path to C<lib> directory of application.
my $files = $home->list_files;
my $files = $home->list_files('foo/bar');
Portably list all files recursively in directory relative to the home
directory.
Portably list all files recursively in directory relative to the home directory.
say $home->rel_file($home->list_files('templates/layouts')->[1]);
# List layouts
say for @{$home->rel_file($home->list_files('templates/layouts')};
=head2 mojo_lib_dir
Expand Down
16 changes: 10 additions & 6 deletions t/mojo/home.t
Expand Up @@ -48,11 +48,15 @@ is $home->rel_dir('foo/bar'), catdir(splitdir($FindBin::Bin), 'foo', 'bar'),
'right path';

# List files
is first(sub {/Base1\.pm$/}, @{$home->list_files('lib')}),
'Mojo/BaseTest/Base1.pm', 'right result';
is first(sub {/Base2\.pm$/}, @{$home->list_files('lib')}),
'Mojo/BaseTest/Base2.pm', 'right result';
is first(sub {/Base3\.pm$/}, @{$home->list_files('lib')}),
'Mojo/BaseTest/Base3.pm', 'right result';
is_deeply $home->list_files('lib/does_not_exist'), [], 'no files';
is_deeply $home->list_files('lib/myapp.pl'), [], 'no files';
my $files = [
'BaseTest/Base1.pm', 'BaseTest/Base2.pm',
'BaseTest/Base3.pm', 'DeprecationTest.pm',
'LoaderException.pm', 'LoaderException2.pm',
'LoaderTest/A.pm', 'LoaderTest/B.pm',
'LoaderTest/C.pm'
];
is_deeply $home->list_files('lib/Mojo'), $files, 'right files';

done_testing();

0 comments on commit ea8dc33

Please sign in to comment.