File Coverage

blib/lib/Path/IsDev/Role/Matcher/Child/Exists/Any.pm
Criterion Covered Total %
statement 27 31 87.1
branch 2 4 50.0
condition n/a
subroutine 6 7 85.7
pod 2 2 100.0
total 37 44 84.0


line stmt bran cond sub pod time code
1 24     24   9544 use 5.008; # utf8
  24         50  
2 24     24   229 use strict;
  24         29  
  24         394  
3 24     24   71 use warnings;
  24         48  
  24         477  
4 24     24   517 use utf8;
  24         37  
  24         91  
5              
6             package Path::IsDev::Role::Matcher::Child::Exists::Any;
7              
8             our $VERSION = '1.001003';
9              
10             # ABSTRACT: Match if any of a list of children exists
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14 24     24   1665 use Role::Tiny;
  24         3116  
  24         114  
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27              
28              
29              
30              
31              
32              
33              
34              
35             sub child_exists {
36 111     111 1 115 my ( $self, $result_object, $child ) = @_;
37              
38 111         2031 my $child_path = $result_object->path->child($child);
39              
40 111         3207 my $ctx = { 'child_name' => $child, child_path => "$child_path", tests => [] };
41 111         488 my $tests = $ctx->{tests};
42              
43 111 100       217 if ( -e $child_path ) {
44 12         225 push @{$tests}, { 'child_path_exists?' => 1 };
  12         34  
45 12         57 $result_object->add_reason( $self, 1, "$child exists", $ctx );
46 12         88 return 1;
47             }
48 99         2022 push @{$tests}, { 'child_path_exists?' => 0 };
  99         224  
49 99         332 $result_object->add_reason( $self, 0, "$child does not exist", $ctx );
50 99         475 return;
51             }
52              
53              
54              
55              
56              
57              
58              
59              
60              
61             sub child_exists_any {
62 0     0 1   my ( $self, $result_object, @children ) = @_;
63 0           for my $child (@children) {
64 0 0         return 1 if $self->child_exists( $result_object, $child );
65             }
66 0           return;
67             }
68              
69             1;
70              
71             __END__