Skip to content

Commit

Permalink
the list_files method of Mojo::Home is also not needed anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 4, 2017
1 parent b47363e commit cfb989c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 46 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

7.14 2017-01-04
- Deprecated Mojo::Home::list_files in favor of Mojo::Util::files.
- Deprecated Mojo::Home::rel_dir in favor of Mojo::Home::rel_file.
- Deprecated Mojolicious::Command::rel_dir in favor of
Mojolicious::Command::rel_file.
Expand Down
26 changes: 3 additions & 23 deletions lib/Mojo/Home.pm
Expand Up @@ -36,7 +36,10 @@ sub lib_dir {
return -d $path ? $path : undef;
}

# DEPRECATED!
sub list_files {
deprecated
'Mojo::Home::list_files is DEPRECATED in favor of Mojo::Util::files';
my ($self, $dir, $options) = (shift, shift // '', shift);
$dir = catdir @{$self->parts}, split('/', $dir);
return [map { join '/', splitdir abs2rel($_, $dir) } files $dir, $options];
Expand Down Expand Up @@ -112,29 +115,6 @@ location of the application class, or the current working directory.
Path to C<lib> directory of application.
=head2 list_files
my $files = $home->list_files;
my $files = $home->list_files('foo/bar');
my $files = $home->list_files('foo/bar', {hidden => 1});
Portably list all files recursively in directory relative to the home directory.
# List layouts
say $home->rel_file($_) for @{$home->list_files('templates/layouts')};
These options are currently available:
=over 2
=item hidden
hidden => 1
Include hidden files and directories.
=back
=head2 mojo_lib_dir
my $path = $home->mojo_lib_dir;
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojolicious/Command/test.pm
@@ -1,7 +1,7 @@
package Mojolicious::Command::test;
use Mojo::Base 'Mojolicious::Command';

use Mojo::Util 'getopt';
use Mojo::Util qw(files getopt);

has description => 'Run tests';
has usage => sub { shift->extract_usage };
Expand All @@ -13,8 +13,7 @@ sub run {

if (!@args && (my $home = $self->app->home)) {
die "Can't find test directory.\n" unless -d $home->rel_file('t');
my $files = $home->list_files('t');
/\.t$/ and push @args, $home->rel_file("t/$_") for @$files;
/\.t$/ and push @args, $_ for files $home->rel_file('t');
say qq{Running tests from "}, $home->rel_file('t') . '".';
}

Expand Down
10 changes: 6 additions & 4 deletions lib/Mojolicious/Renderer.pm
@@ -1,12 +1,12 @@
package Mojolicious::Renderer;
use Mojo::Base -base;

use File::Spec::Functions 'catfile';
use File::Spec::Functions qw(abs2rel catfile splitdir);
use Mojo::Cache;
use Mojo::JSON 'encode_json';
use Mojo::Home;
use Mojo::Loader 'data_section';
use Mojo::Util qw(decamelize encode md5_sum monkey_patch slurp);
use Mojo::Util qw(decamelize encode files md5_sum monkey_patch slurp);

has cache => sub { Mojo::Cache->new };
has classes => sub { ['main'] };
Expand Down Expand Up @@ -181,8 +181,10 @@ sub warmup {
my ($index, $templates) = @$self{qw(index templates)} = ({}, {});

# Handlers for templates
s/\.(\w+)$// and push @{$templates->{$_}}, $1
for map { @{Mojo::Home->new($_)->list_files} } @{$self->paths}, $TEMPLATES;
for my $path (@{$self->paths}, $TEMPLATES) {
s/\.(\w+)$// and push @{$templates->{$_}}, $1
for map { join '/', splitdir(abs2rel $_, $path) } files $path;
}

# Handlers and classes for DATA templates
for my $class (reverse @{$self->classes}) {
Expand Down
15 changes: 0 additions & 15 deletions t/mojo/home.t
Expand Up @@ -38,19 +38,4 @@ is $home->rel_file('foo.txt'), catfile(splitdir($FindBin::Bin), 'foo.txt'),
is $home->rel_file('foo/bar.txt'),
catfile(splitdir($FindBin::Bin), 'foo', 'bar.txt'), 'right path';

# List files
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';
my @hidden = ('.hidden.txt', '.test/hidden.txt');
is_deeply $home->list_files('lib/Mojo', {hidden => 1}), [@hidden, @files],
'right files';

done_testing();
2 changes: 1 addition & 1 deletion t/pod_coverage.t
Expand Up @@ -8,4 +8,4 @@ plan skip_all => 'Test::Pod::Coverage 1.04+ required for this test!'
unless eval 'use Test::Pod::Coverage 1.04; 1';

# DEPRECATED!
all_pod_coverage_ok({also_private => [qw(rel_dir is_status_class)]});
all_pod_coverage_ok({also_private => [qw(list_files rel_dir is_status_class)]});

0 comments on commit cfb989c

Please sign in to comment.