File Coverage

blib/lib/Path/IsDev/Role/Matcher/Child/BaseName/MatchRegexp.pm
Criterion Covered Total %
statement 27 31 87.1
branch 2 4 50.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 36 43 83.7


line stmt bran cond sub pod time code
1 10     10   22151 use 5.008; # utf8
  10         36  
  10         474  
2 10     10   57 use strict;
  10         20  
  10         323  
3 10     10   57 use warnings;
  10         19  
  10         404  
4 10     10   1658 use utf8;
  10         28  
  10         62  
5              
6             package Path::IsDev::Role::Matcher::Child::BaseName::MatchRegexp;
7              
8             our $VERSION = '1.001002';
9              
10             # ABSTRACT: Match when a path has a child file matching an expression
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25 10     10   2053 use Role::Tiny;
  10         6073  
  10         73  
26              
27              
28              
29              
30              
31              
32              
33              
34              
35             sub _this_child_matchregexp {
36 24     24   52 my ( $self, $result_object, $child, $regexp ) = @_;
37 24         85 my $ctx = {
38             'child' => "$child",
39             'child_basename' => $child->basename,
40             expression => $regexp,
41             tests => [],
42             };
43 24         951 my $tests = $ctx->{tests};
44              
45 24 100       79 if ( $child->basename =~ $regexp ) {
46 5         74 push @{$tests}, { 'child_basename_matches_expression?' => 1 };
  5         25  
47 5         19 $result_object->add_reason( $self, 1, $child->basename . " matches $regexp", $ctx );
48 5         55 return 1;
49             }
50 19         215 push @{$tests}, { 'child_basename_matches_expression?' => 0 };
  19         69  
51 19         63 $result_object->add_reason( $self, 0, $child->basename . " does not match $regexp", $ctx );
52 19         232 return;
53             }
54              
55              
56              
57              
58              
59              
60              
61              
62              
63              
64              
65              
66              
67             sub child_basename_matchregexp {
68 0     0 1   my ( $self, $result_object, $regexp ) = @_;
69 0           for my $child ( $result_object->path->children ) {
70 0 0         return 1 if $self->_this_child_matchregexp( $result_object, $child, $regexp );
71             }
72 0           return;
73             }
74              
75             1;
76              
77             __END__
78              
79             =pod
80              
81             =encoding UTF-8
82              
83             =head1 NAME
84              
85             Path::IsDev::Role::Matcher::Child::BaseName::MatchRegexp - Match when a path has a child file matching an expression
86              
87             =head1 VERSION
88              
89             version 1.001002
90              
91             =head1 METHODS
92              
93             =head2 C<child_basename_matchregexp>
94              
95             $class->child_basename_matchregexp( $result_object, $regexp );
96              
97             Given a regexp C<$regexp>, match if any of C<< $result_object->path->children >> match the given regexp.
98              
99             if ( $self->child_basename_matchregexp( $result_object, qr/^Change(.*)$/i ) ) {
100             # result_object->path() contains at least one child that matches the regexp
101             }
102              
103             =head1 PRIVATE METHODS
104              
105             =head2 C<_this_child_matchregexp>
106              
107             if ( $class->_this_child_matchregexp( $result_object, $child_path, $regexp ) ) {
108             ...
109             }
110              
111             =begin MetaPOD::JSON v1.1.0
112              
113             {
114             "namespace":"Path::IsDev::Role::Matcher::Child::BaseName::MatchRegexp",
115             "interface":"role"
116             }
117              
118              
119             =end MetaPOD::JSON
120              
121             =head1 AUTHOR
122              
123             Kent Fredric <kentfredric@gmail.com>
124              
125             =head1 COPYRIGHT AND LICENSE
126              
127             This software is copyright (c) 2014 by Kent Fredric <kentfredric@gmail.com>.
128              
129             This is free software; you can redistribute it and/or modify it under
130             the same terms as the Perl 5 programming language system itself.
131              
132             =cut