diff --git a/lib/Module/Reader.pm b/lib/Module/Reader.pm index 89fefb5..3253bef 100644 --- a/lib/Module/Reader.pm +++ b/lib/Module/Reader.pm @@ -115,8 +115,24 @@ sub _find { eval { if (my $found = $self->{found}) { if (defined( my $full = $found->{$file} )) { - my $open = length ref $full ? $self->_open_ref($full, $file) - : $self->_open_file($full, $file); + my $open; + if (length ref $full) { + $open = $self->_open_ref($full, $file); + } + else { + my ($fvol, $fpath, $ffn) = File::Spec->splitpath($full); + my ($vol, $path, $fn) = File::Spec->splitpath($file); + my @fpath = (File::Spec->splitdir($fpath), $ffn); + my @path = (File::Spec->splitdir($path), $fn); + 1 while @fpath && @path && pop @fpath eq pop @path; + my $inc; + if (!@path) { + my $maybe_inc = File::Spec->canonpath(File::Spec->catpath($vol, File::Spec->catdir(@fpath), '')); + ($inc) = grep { File::Spec->canonpath($_) eq $maybe_inc } @{$self->{inc}}; + } + + $open = $self->_open_file($full, $file, $inc); + } push @found, $open if $open; } @@ -475,7 +491,7 @@ avoided unless you are introspecting the F<< C<@INC> hooks|perlfunc/require >>. The raw file handle to the file found. This will be either a file handle to a file found on disk, or something returned by an -F<< C<@INC> hook|perlfunc/require >>. The hook callback, if it exists, will not +L<< C<@INC> hook|perlfunc/require >>. The hook callback, if it exists, will not be taken into account by this method. =head3 read_callback