Skip to content

Commit

Permalink
Mojo::File->new is more efficient than Mojo::File::path
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 8, 2017
1 parent f67d11c commit 01b77f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/Mojo/ByteStream.pm
Expand Up @@ -53,7 +53,7 @@ sub slurp {
. ' in favor of Mojo::File::slurp';
require Mojo::File;
my $self = shift;
$$self = Mojo::File::path($$self)->slurp;
$$self = Mojo::File->new($$self)->slurp;
return $self;
}

Expand All @@ -68,7 +68,7 @@ sub spurt {
. ' in favor of Mojo::File::spurt';
require Mojo::File;
my $self = shift;
Mojo::File::path(shift)->spurt($$self);
Mojo::File->new(shift)->spurt($$self);
return $self;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/Home.pm
Expand Up @@ -8,12 +8,12 @@ sub detect {

# Environment variable
my $detected;
if ($ENV{MOJO_HOME}) { $detected = Mojo::File::path($ENV{MOJO_HOME})->to_abs }
if ($ENV{MOJO_HOME}) { $detected = Mojo::File->new($ENV{MOJO_HOME})->to_abs }

# Location of the application class
elsif ($class && (my $path = $INC{my $file = class_to_path $class})) {
$path =~ s/(?:\/b?lib)?\/\Q$file\E$//;
$detected = Mojo::File::path($path)->to_abs;
$detected = Mojo::File->new($path)->to_abs;
}

$$self = $detected->to_string if $detected;
Expand Down Expand Up @@ -51,15 +51,15 @@ sub parts {
deprecated 'Mojo::Home::parts is DEPRECATED';
my $self = shift;
return $self->to_array unless @_;
$$self = Mojo::File::path(@{shift()})->to_string;
$$self = Mojo::File->new(@{shift()})->to_string;
return $self;
}

# DEPRECATED!
sub rel_dir {
deprecated
'Mojo::Home::rel_dir is DEPRECATED in favor of Mojo::Home::rel_file';
Mojo::File::path(@{shift->parts}, split('/', shift))->to_string;
Mojo::File->new(@{shift->parts}, split('/', shift))->to_string;
}

sub rel_file { shift->child(split('/', shift)) }
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Util.pm
Expand Up @@ -132,7 +132,7 @@ sub files {
deprecated
'Mojo::Util::files is DEPRECATED in favor of Mojo::File::list_tree';
require Mojo::File;
Mojo::File::path(shift)->list_tree(@_)->map('to_string')->each;
Mojo::File->new(shift)->list_tree(@_)->map('to_string')->each;
}

sub getopt {
Expand Down Expand Up @@ -252,7 +252,7 @@ sub secure_compare {
sub slurp {
deprecated 'Mojo::Util::slurp is DEPRECATED in favor of Mojo::File::slurp';
require Mojo::File;
Mojo::File::path(shift)->slurp;
Mojo::File->new(shift)->slurp;
}

sub split_cookie_header { _header(shift, 1) }
Expand All @@ -262,7 +262,7 @@ sub split_header { _header(shift, 0) }
sub spurt {
deprecated 'Mojo::Util::spurt is DEPRECATED in favor of Mojo::File::spurt';
require Mojo::File;
Mojo::File::path($_[1])->spurt($_[0]) and return $_[0];
Mojo::File->new($_[1])->spurt($_[0]) and return $_[0];
}

sub tablify {
Expand Down

0 comments on commit 01b77f7

Please sign in to comment.