Skip to content

Commit

Permalink
stop using Mojo::Util::files
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 2, 2017
1 parent f6451ce commit 2fbc3f2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/File.pm
Expand Up @@ -11,8 +11,8 @@ use Cwd qw(abs_path getcwd);
use Exporter 'import';
use File::Basename ();
use File::Copy ();
use File::Find;
use File::Path ();
use File::Find ();
use File::Path ();
use File::Spec;
use File::Temp ();
use Mojo::Collection;
Expand All @@ -28,7 +28,7 @@ sub child { path(shift()->to_string, @_) }
sub dirname { path(File::Basename::dirname ${shift()}) }

sub list_tree {
my ($self, $options) = (shift, shift, shift // {});
my ($self, $options) = (shift, shift // {});

# This may break in the future, but is worth it for performance
local $File::Find::skip_pattern = qr/^\./ unless $options->{hidden};
Expand Down
8 changes: 5 additions & 3 deletions lib/Mojo/Home.pm
Expand Up @@ -5,7 +5,8 @@ use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1;
use Cwd qw(abs_path getcwd);
use File::Basename 'dirname';
use File::Spec::Functions qw(abs2rel catdir catfile splitdir);
use Mojo::Util qw(class_to_path files);
use Mojo::File 'path';
use Mojo::Util 'class_to_path';

has parts => sub { [] };

Expand Down Expand Up @@ -38,8 +39,9 @@ sub lib_dir {

sub list_files {
my ($self, $dir, $options) = (shift, shift // '', shift);
$dir = catdir @{$self->parts}, split('/', $dir);
return [map { join '/', splitdir abs2rel($_, $dir) } files $dir, $options];
my $base = path(@{$self->parts}, split('/', $dir));
$base->list_tree($options)->map(sub { join '/', @{$_->to_rel($base)} })
->to_array;
}

sub mojo_lib_dir { catdir dirname(__FILE__), '..' }
Expand Down
6 changes: 4 additions & 2 deletions lib/Mojo/Server/Morbo.pm
Expand Up @@ -5,7 +5,7 @@ use Mojo::Base -base;
# effects of sudden, intense global warming.
# Morbo: Morbo is pleased but sticky."
use Mojo::Server::Daemon;
use Mojo::Util 'files';
use Mojo::File 'path';
use POSIX 'WNOHANG';

has daemon => sub { Mojo::Server::Daemon->new };
Expand All @@ -15,8 +15,10 @@ sub modified_files {
my $self = shift;

my $cache = $self->{cache} ||= {};
my @check
= map { -f $_ && -r _ ? $_ : path($_)->list_tree->each } @{$self->watch};
my @files;
for my $file (map { -f $_ && -r _ ? $_ : files $_ } @{$self->watch}) {
for my $file (@check) {
my ($size, $mtime) = (stat $file)[7, 9];
next unless defined $size and defined $mtime;
my $stats = $cache->{$file} ||= [$^T, $size];
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Util.pm
Expand Up @@ -11,7 +11,6 @@ use Getopt::Long 'GetOptionsFromArray';
use IO::Poll qw(POLLIN POLLPRI);
use List::Util 'min';
use MIME::Base64 qw(decode_base64 encode_base64);
use Mojo::File;
use Symbol 'delete_package';
use Time::HiRes ();

Expand Down Expand Up @@ -131,6 +130,7 @@ sub encode { _encoding($_[0])->encode("$_[1]") }
# DEPRECATED!
sub files {
deprecated 'Mojo::Util::files is DEPRECATED in favor of Mojo::File';
require Mojo::File;
Mojo::File::path(shift)->list_tree(@_)->map('to_string')->each;
}

Expand Down
2 changes: 1 addition & 1 deletion t/mojo/file.t
Expand Up @@ -50,7 +50,7 @@ ok !-d $subdir, 'directory does not exist anymore';
$subdir->make_path;
ok -d $subdir, 'directory exists';

# files
# List tree
is_deeply path('does_not_exist')->list_tree->to_array, [], 'no files';
is_deeply path(__FILE__)->list_tree->to_array, [], 'no files';
my $lib = path(__FILE__)->dirname->child('lib', 'Mojo');
Expand Down

0 comments on commit 2fbc3f2

Please sign in to comment.