Skip to content

Instantly share code, notes, and snippets.

/arrays.diff Secret

Created January 11, 2017 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6b3af8384efb3a7fc1a6e9205dfbf460 to your computer and use it in GitHub Desktop.
Save anonymous/6b3af8384efb3a7fc1a6e9205dfbf460 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/Home.pm b/lib/Mojo/Home.pm
index c5cf0fbe1..e46c49c8f 100644
--- a/lib/Mojo/Home.pm
+++ b/lib/Mojo/Home.pm
@@ -12,9 +12,10 @@ sub detect {
# Location of the application class (Windows mixes backslash and slash)
elsif ($class && (my $path = $INC{my $file = class_to_path $class})) {
- $path =~ s!\\!/!g;
- $path =~ s!(?:(?:^|/)b?lib)?/\Q$file\E$!!;
- $detected = Mojo::File->new($path)->to_abs;
+ my $parts = Mojo::File->new($path)->to_array;
+ pop @$parts for 1 .. @{Mojo::File->new($file)};
+ pop @$parts if @$parts && ($parts->[-1] eq 'blib' || $parts->[-1] eq 'lib');
+ $detected = Mojo::File->new(@$parts)->to_abs;
}
$$self = $detected->to_string if $detected;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment