lib/File/Corresponding/Group.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 100% 53 / 53 CC 4 SCAR 4.5
CC
4
Cov
100%
matching_file_fragment_profile
3.0
corresponding
2.0
BEGIN
1.0
CRAP 1.6
« lib/File/Corresponding/Config/Find.pm ↑ Summary lib/File/Corresponding/File/Found.pm »
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 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17  
18 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use Moose::Autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 ▶use File::Corresponding::File::Profile;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 5 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 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 5 );
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 9 ▶ my $self = shift;
Subroutine corresponding: called CC=2 SCAR=6.9
Pod documented
63 9 my ($file) = @_;
64  
65 9 my ($file_base, $fragment, $matching_profile) =
66 $self->matching_file_fragment_profile($file);
67 9 ▶ $matching_profile or return [];
Branch: 1 branch
BranchTrueFalseTotal
$matching_profile or return [] 2 7 9
68  
69 my $found_files =
70 $self->file_profiles
71 20 ▶ ->grep(sub { $_ != $matching_profile })
Subroutine __ANON__: called CC=1 SCAR=0.0
72 13 ▶ ->map(sub { $_->new_found_if_file_exists(
Subroutine __ANON__: called CC=1 SCAR=0.0
73 $matching_profile,
74 $file_base,
75 $fragment,
76 7 ) });
77
78 7 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 11 ▶ my $self = shift;
Subroutine matching_file_fragment_profile: called CC=3 SCAR=11.0
Pod documented
91 11 my ($file) = @_;
92
93 11 for my $profile ($self->file_profiles->flatten) {
94 15 my ($file_base, $file_fragment) = $profile->matching_file_fragment($file);
95 15 ▶ $file_base and return ($file_base, $file_fragment, $profile);
Branch: 1 branch
BranchTrueFalseTotal
$file_base and return $file_base, $file_fragment, $profile 8 7 15
96 }
97
98 3 return ();
99 }
100  
101  
102  
103 5 1;
104  
105  
106  
107 __END__
« lib/File/Corresponding/Config/Find.pm ↑ Summary lib/File/Corresponding/File/Found.pm »