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