File Coverage

blib/lib/lib/relative/to/ParentContaining.pm
Criterion Covered Total %
statement 25 25 100.0
branch 4 4 100.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 35 35 100.0


line stmt bran cond sub pod time code
1             package lib::relative::to::ParentContaining;
2              
3 5     5   1393 use strict;
  5         10  
  5         127  
4 5     5   20 use warnings;
  5         9  
  5         106  
5            
6 5     5   400 use parent 'lib::relative::to';
  5         268  
  5         43  
7              
8 5     5   295 use File::Spec;
  5         17  
  5         161  
9 5     5   29 use Cwd qw(abs_path);
  5         7  
  5         903  
10              
11             sub _find {
12 11     11   41 my($class, $parent_contains, @args) = @_;
13 11         21 my $caller = $lib::relative::to::called_from;
14              
15 11         618 my $candidate = $class->parent_dir(abs_path($caller));
16              
17 11         72 while($candidate) {
18 30         125 my $target = File::Spec->catdir($candidate, $parent_contains);
19 30 100       1442 if(-e $target) {
    100          
20 9         30 return map { File::Spec->catdir($candidate, $_) } @args
  12         102  
21             } elsif($candidate eq $class->parent_dir($candidate)) {
22 2         21 die(__PACKAGE__ . ": Couldn't _find $parent_contains in any parent directory of $caller\n");
23             } else {
24 19         44 $candidate = $class->parent_dir($candidate);
25             }
26             }
27             }
28              
29             1;
30              
31             =head1 NAME
32              
33             lib::relative::to:ParentContaining:
34              
35             =head1 SYNOPSIS
36              
37             use lib::relative::to
38             ParentContaining => 'MANIFEST', qw(lib t/lib);
39              
40             =head1 DESCRIPTION
41              
42             A plugin for L for finding a parent (or grandparent, or ...) directory which contains some particular file or directory and then adding some directories under it to C<@INC>. It is a fatal error to not find a suitable parent directory.