Navigation Menu

Skip to content

Commit

Permalink
fix blib handling in Mojo::Home
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 22, 2017
1 parent 504b09e commit 95b3769
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

7.27 2017-02-17
7.27 2017-02-22
- Fixed blib handling in Mojo::Home.

7.26 2017-02-15
- Fixed bug in Mojo::IOLoop::Subprocess where starting multiple subprocesses
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Home.pm
Expand Up @@ -14,7 +14,8 @@ sub detect {
elsif ($class && (my $path = $INC{my $file = class_to_path $class})) {
$home = Mojo::File->new($path)->to_array;
splice @$home, (my @dummy = split('/', $file)) * -1;
pop @$home if @$home && ($home->[-1] eq 'blib' || $home->[-1] eq 'lib');
pop @$home if @$home && $home->[-1] eq 'lib';
pop @$home if @$home && $home->[-1] eq 'blib';
}

$$self = Mojo::File->new(@$home)->to_abs->to_string if $home;
Expand Down
9 changes: 5 additions & 4 deletions t/mojo/home.t
Expand Up @@ -32,10 +32,11 @@ use Mojo::Home;
is_deeply $home->to_array, $fake->to_array, 'right path detected';
}

# Specific class detection (with "blib")
# Specific class detection (with "blib/lib")
{
my $fake = path->to_abs->child('does_not_exist_3');
local $INC{'My/Class.pm'} = $fake->child('blib', 'My', 'Class.pm')->to_string;
local $INC{'My/Class.pm'}
= $fake->child('blib', 'lib', 'My', 'Class.pm')->to_string;
my $home = Mojo::Home->new->detect('My::Class');
is_deeply $home->to_array, $fake->to_array, 'right path detected';
}
Expand All @@ -47,9 +48,9 @@ use Mojo::Home;
is_deeply $home->to_array, path->to_array, 'right path detected';
}

# Specific class detection (relative "blib")
# Specific class detection (relative "blib/lib")
{
local $INC{'My/Class.pm'} = path('blib', 'My', 'Class.pm')->to_string;
local $INC{'My/Class.pm'} = path('blib', 'lib', 'My', 'Class.pm')->to_string;
my $home = Mojo::Home->new->detect('My::Class');
is_deeply $home->to_array, path->to_array, 'right path detected';
}
Expand Down

0 comments on commit 95b3769

Please sign in to comment.