File Coverage

blib/lib/Path/IsDev/Role/Matcher/Child/Exists/Any/File.pm
Criterion Covered Total %
statement 32 32 100.0
branch 4 4 100.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 2 2 100.0
total 48 48 100.0


line stmt bran cond sub pod time code
1 20     20   150900 use 5.008; # utf8
  20         74  
  20         1780  
2 20     20   117 use strict;
  20         43  
  20         614  
3 20     20   144 use warnings;
  20         36  
  20         1345  
4 20     20   1981 use utf8;
  20         55  
  20         132  
5              
6             package Path::IsDev::Role::Matcher::Child::Exists::Any::File;
7              
8             our $VERSION = '1.001002';
9              
10             # ABSTRACT: Match if a path contains one of any of a list of files
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26 20     20   3779 use Role::Tiny qw( with );
  20         5943  
  20         122  
27             with 'Path::IsDev::Role::Matcher::Child::Exists::Any';
28              
29              
30              
31              
32              
33              
34              
35              
36              
37             sub child_exists_file {
38 11     11 1 34 my ( $self, $result_object, $child ) = @_;
39              
40 11         266 my $child_path = $result_object->path->child($child);
41 11         560 my $ctx = { 'child_name' => $child, child_path => "$child_path", tests => [] };
42 11         100 my $tests = $ctx->{tests};
43              
44             # For now, yes, files, not things usable as files
45             ## no critic (ValuesAndExpressions::ProhibitFiletest_f)
46 11 100       39 if ( -f $child_path ) {
47 9         301 push @{$tests}, { 'child_path_isfile?' => 1 };
  9         234  
48 9         39 $result_object->add_reason( $self, 1, "$child_path is a file", $ctx );
49 9         114 return 1;
50             }
51 2         60 push @{$tests}, { 'child_path_isfile?' => 1 };
  2         8  
52 2         9 $result_object->add_reason( $self, 0, "$child_path is not a file", $ctx );
53              
54 2         22 return;
55             }
56              
57              
58              
59              
60              
61              
62              
63              
64              
65             sub child_exists_any_file {
66 77     77 1 485 my ( $self, $result_object, @children ) = @_;
67 77         305 for my $child (@children) {
68 96 100 100     574 return 1 if $self->child_exists( $result_object, $child ) and $self->child_exists_file( $result_object, $child );
69             }
70 68         350 return;
71             }
72              
73             1;
74              
75             __END__
76              
77             =pod
78              
79             =encoding UTF-8
80              
81             =head1 NAME
82              
83             Path::IsDev::Role::Matcher::Child::Exists::Any::File - Match if a path contains one of any of a list of files
84              
85             =head1 VERSION
86              
87             version 1.001002
88              
89             =head1 METHODS
90              
91             =head2 C<child_exists_file>
92              
93             $class->child_exists_file( $result_object, $childname );
94              
95             Return match if C<$childname> exists as a file child of C<< $result_object->path >>
96              
97             =head2 C<child_exists_any_file>
98              
99             $class->child_exists_any_file( $result_object, @childnames );
100              
101             Return match if any of C<@childnames> exist under C<< $result_object->path >> and are files.
102              
103             =begin MetaPOD::JSON v1.1.0
104              
105             {
106             "namespace":"Path::IsDev::Role::Matcher::Child::Exists::Any::File",
107             "interface":"role",
108             "does":"Path::IsDev::Role::Matcher::Child::Exists::Any"
109             }
110              
111              
112             =end MetaPOD::JSON
113              
114             =head1 AUTHOR
115              
116             Kent Fredric <kentfredric@gmail.com>
117              
118             =head1 COPYRIGHT AND LICENSE
119              
120             This software is copyright (c) 2014 by Kent Fredric <kentfredric@gmail.com>.
121              
122             This is free software; you can redistribute it and/or modify it under
123             the same terms as the Perl 5 programming language system itself.
124              
125             =cut