blib/lib/File/Corresponding/Group.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran n/a Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 52 CC 1 SCAR 6.9
CC
1
Cov
0%
corresponding
2.0
matching_file_fragment_profile
2.0
BEGIN
2.0
CRAP 2.0
1  
2 =head1 NAME
3  
4 File::Corresponding::Group - A group of File::Profile objects
5  
6 =head1 DESCRIPTION
7  
8 A group of File::Profile objects which define which files belong
9 together.
10  
11 =cut
12  
13 package File::Corresponding::Group;
14 use Moose;
15  
16  
17  
18 use Data::Dumper;
19 use File::Path;
20 use Path::Class;
21 use Moose::Autobox;
22  
23 use File::Corresponding::File::Profile;
24  
25  
26  
27 =head1 PROPERTIES
28  
29 =head2 name
30  
31 Name/description of this File Group. It should describe what's common
32 between the files in the group.
33  
34 =cut
35 has 'name' => (is => 'ro', isa => 'Str', default => "");
36  
37  
38  
39  
40 =head2 file_profiles
41  
42 Array ref with File::Profile objects that make up the group.
43  
44 =cut
45 has 'file_profiles' => (
46 is => 'rw',
47 isa => 'ArrayRef[File::Corresponding::File::Profile]',
48 default => sub { [] },
49 );
50  
51  
52  
53 =head1 METHODS
54  
55 =head2 corresponding($file) : ArrayRef[File::Corresponding::File::Found]
56  
57 Find files corresponding to $file (given the config in
58 ->file_profiles) and return found @$files.
59  
60 =cut
61 sub corresponding {
62 my $self = shift;
63 my ($file) = @_;
64  
65 my ($file_base, $fragment, $matching_profile) =
66 $self->matching_file_fragment_profile($file);
67 $matching_profile or return [];
68  
69 my $found_files =
70 $self->file_profiles
71 ->grep(sub { $_ != $matching_profile })
72 ->map(sub { $_->new_found_if_file_exists(
73 $matching_profile,
74 $file_base,
75 $fragment,
76 ) });
77
78 return $found_files;
79 }
80  
81  
82  
83 =head2 matching_file_fragment_profile($file) : $file_fragment, File::Corresponding::File::Profile | ()
84  
85 Return two item list with the $file_fragment and first profile that
86 matches $file, or an empty list if there is no match.
87  
88 =cut
89 sub matching_file_fragment_profile {
90 my $self = shift;
91 my ($file) = @_;
92
93 for my $profile ($self->file_profiles->flatten) {
94 my ($file_base, $file_fragment) = $profile->matching_file_fragment($file);
95 $file_base and return ($file_base, $file_fragment, $profile);
96 }
97
98 return ();
99 }
100  
101  
102  
103 1;
104  
105  
106  
107 __END__