File Coverage

blib/lib/Path/IsDev/Role/Matcher/Child/Exists/Any/Dir.pm
Criterion Covered Total %
statement 27 31 87.1
branch 3 4 75.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 2 2 100.0
total 41 47 87.2


line stmt bran cond sub pod time code
1 9     9   3748 use 5.008; # utf8
  9         19  
2 9     9   34 use strict;
  9         10  
  9         137  
3 9     9   29 use warnings;
  9         10  
  9         173  
4 9     9   448 use utf8;
  9         15  
  9         34  
5              
6             package Path::IsDev::Role::Matcher::Child::Exists::Any::Dir;
7              
8             our $VERSION = '1.001003';
9              
10             # ABSTRACT: Match if a path contains one of any of a list of directories
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26 9     9   945 use Role::Tiny qw( with );
  9         2854  
  9         37  
27             with 'Path::IsDev::Role::Matcher::Child::Exists::Any';
28              
29              
30              
31              
32              
33              
34              
35              
36              
37             sub child_exists_dir {
38 1     1 1 2 my ( $self, $result_object, $child ) = @_;
39              
40 1         13 my $child_path = $result_object->path->child($child);
41 1         23 my $ctx = { 'child_name' => $child, child_path => "$child_path", tests => [] };
42 1         5 my $tests = $ctx->{tests};
43              
44 1 50       2 if ( -d $child_path ) {
45 1         14 push @{$tests}, { 'child_path_isdir?' => 1 };
  1         2  
46 1         3 $result_object->add_reason( $self, 1, "$child_path is a dir", $ctx );
47 1         10 return 1;
48             }
49 0         0 push @{$tests}, { 'child_path_isdir?' => 0 };
  0         0  
50 0         0 $result_object->add_reason( $self, 0, "$child_path is not a dir", $ctx );
51              
52 0         0 return;
53             }
54              
55              
56              
57              
58              
59              
60              
61              
62              
63             sub child_exists_any_dir {
64 9     9 1 14 my ( $self, $result_object, @children ) = @_;
65 9         15 for my $child (@children) {
66 15 100 66     38 return 1 if $self->child_exists( $result_object, $child ) and $self->child_exists_dir( $result_object, $child );
67             }
68 8         27 return;
69             }
70              
71             1;
72              
73             __END__