blib/lib/App/perlimports/Config.pm

filter: Statementstmt 100% 76 / 76 Branchbran 80.0% 8 / 10 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 19 / 19 Podpod 100% 1 / 1 totaltotal 96.4% 108 / 112 CC 8 SCAR 7.0
CC
8
Cov
97%
_aggregate
5.0
__ANON__
2.1
__ANON__
2.1
CRAP 2.0
« test-data/lib/Local/ImportException.pm ↑ Summary blib/lib/App/perlimports/ExportInspector.pm »
1 package App::perlimports::Config;
2  
3 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use MooX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 our $VERSION = '0.000067';
7  
8 18 ▶use List::Util qw( uniq );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use Types::Common::Numeric qw( PositiveOrZeroInt );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use Types::Standard qw( ArrayRef Bool HashRef InstanceOf Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 18 has cache => (
14 is => 'ro',
15 isa => Bool,
16 lazy => 1,
17 default => 0,
18 );
19  
20 has _ignore_modules => (
21 is => 'ro',
22 isa => ArrayRef,
23 init_arg => 'ignore_modules',
24 lazy => 1,
25 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 18 );
27  
28 18 has _ignore_modules_filename => (
29 is => 'ro',
30 isa => Str,
31 init_arg => 'ignore_modules_filename',
32 predicate => '_has_ignore_modules_filename',
33 );
34  
35 has _ignore_modules_pattern => (
36 is => 'ro',
37 isa => ArrayRef [Str],
38 init_arg => 'ignore_modules_pattern',
39 lazy => 1,
40 predicate => '_has_ignore_modules_pattern',
41 7 ▶ coerce => sub { return ref $_[0] ? $_[0] : [ $_[0] ] },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 7 7
42 18 );
43  
44 18 has _ignore_modules_pattern_filename => (
45 is => 'ro',
46 isa => Str,
47 init_arg => 'ignore_modules_pattern_filename',
48 predicate => '_has_ignore_modules_pattern_filename',
49 );
50  
51 18 has ignore => (
52 is => 'ro',
53 isa => ArrayRef,
54 lazy => 1,
55 builder => '_build_ignore',
56 );
57  
58 18 has ignore_pattern => (
59 is => 'ro',
60 isa => ArrayRef,
61 lazy => 1,
62 builder => '_build_ignore_pattern',
63 );
64  
65 has libs => (
66 is => 'ro',
67 isa => ArrayRef,
68 lazy => 1,
69 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
70 18 );
71  
72 has log_filename => (
73 is => 'ro',
74 isa => Str,
75 lazy => 1,
76 9 ▶ default => sub { q{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
77 18 );
78  
79 has log_level => (
80 is => 'ro',
81 isa => Str,
82 lazy => 1,
83 2 ▶ default => sub { 'error' },
Subroutine __ANON__: called CC=1 SCAR=0.0
84 18 );
85  
86 has _never_export_modules => (
87 is => 'ro',
88 isa => ArrayRef,
89 init_arg => 'never_export_modules',
90 lazy => 1,
91 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
92 18 );
93  
94 18 has _never_export_modules_filename => (
95 is => 'ro',
96 isa => Str,
97 init_arg => 'never_export_modules_filename',
98 predicate => '_has_never_export_modules_filename',
99 );
100  
101 18 has never_export => (
102 is => 'ro',
103 isa => ArrayRef,
104 lazy => 1,
105 builder => '_build_never_export',
106 );
107  
108 has _perltidy_options => (
109 is => 'ro',
110 isa => HashRef,
111 lazy => 1,
112 9 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
113 9 require Perl::Tidy; ## no perlimports
114 9 my %opts;
115 9 Perl::Tidy::perltidy(
116 dump_options => \%opts,
117 dump_options_type => 'full',
118 argv => q{},
119 );
120 9 return \%opts;
121 },
122 18 );
123  
124 has indent => (
125 is => 'ro',
126 isa => PositiveOrZeroInt,
127 lazy => 1,
128 9 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
129 9 ▶ return $_[0]->_perltidy_options->{'indent-columns'} // 4;
Condition50%1/2
$_[0]->_perltidy_options->{"indent-columns"} // 4
l!l
90
MC/DC0%0/1
$_[0]->_perltidy_options->{"indent-columns"} // 4
$_[0]->_perltidy_options->{"indent-columns"}
Truth table50%1/2
A
A= $_[0]->_perltidy_options->{"indent-columns"}
Aresult
11
00
130 },
131 18 );
132  
133 18 has pad_brackets => (
134 is => 'ro',
135 isa => Bool,
136 lazy => 1,
137 default => 0,
138 );
139  
140 18 has padding => (
141 is => 'ro',
142 isa => Bool,
143 lazy => 1,
144 default => 1,
145 );
146  
147 18 has preserve_duplicates => (
148 is => 'ro',
149 isa => Bool,
150 lazy => 1,
151 default => 1,
152 );
153  
154 18 has preserve_require => (
155 is => 'ro',
156 isa => Bool,
157 lazy => 1,
158 default => 1,
159 );
160  
161 18 has preserve_unused => (
162 is => 'ro',
163 isa => Bool,
164 lazy => 1,
165 default => 1,
166 );
167  
168 18 has sort => (
169 is => 'ro',
170 isa => Bool,
171 lazy => 1,
172 default => 0,
173 );
174  
175 18 has tidy_whitespace => (
176 is => 'ro',
177 isa => Bool,
178 lazy => 1,
179 default => 1,
180 );
181  
182 18 with 'App::perlimports::Role::Logger';
183  
184 9 ▶sub _build_ignore {
Subroutine _build_ignore: called CC=1 SCAR=0.0
185 9 my $self = shift;
186 9 return $self->_aggregate(
187 $self->_ignore_modules,
188 '_ignore_modules_filename'
189 );
190 }
191  
192 9 ▶sub _build_ignore_pattern {
Subroutine _build_ignore_pattern: called CC=1 SCAR=0.0
193 9 my $self = shift;
194 9 return $self->_aggregate(
195 $self->_ignore_modules_pattern,
196 '_ignore_modules_pattern_filename'
197 );
198 }
199  
200 9 ▶sub _build_never_export {
Subroutine _build_never_export: called CC=1 SCAR=0.0
201 9 my $self = shift;
202 9 return $self->_aggregate(
203 $self->_never_export_modules,
204 '_never_export_modules_filename'
205 );
206 }
207  
208 27 ▶sub _aggregate {
Subroutine _aggregate: called CC=5 SCAR=16.1
209 27 my $self = shift;
210 27 ▶ my $list = shift || [];
Condition100%2/2
shift() || []
l!l
252
MC/DC100%1/1
shift() || []
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
211 27 my $accessor = shift;
212  
213 27 my $predicate = '_has' . $accessor;
214  
215 27 ▶ return $list if !$self->$predicate;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$predicate 6 21 27
216  
217 21 my $filename = $self->$accessor;
218 21 ▶ return $list if !$filename; # could be an empty string
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 20 1 21
219  
220 1 ▶ die "File $filename not found" unless -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $filename 0 1 1
221  
222 1 return [ uniq( @{$list}, path($filename)->lines( { chomp => 1 } ) ) ];
223 }
224  
225 4 ▶sub create_config {
Subroutine create_config: called CC=2 SCAR=6.9
Pod documented
226 4 shift; # $class
227 4 my $filename = shift;
228  
229 4 ▶ if ( -e $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $filename) 2 2 4
230 2 die "$filename already exists";
231 }
232  
233 2 my @toml = <DATA>;
234 2 path($filename)->spew(@toml);
235 }
236  
237 18 1;
238  
239 # ABSTRACT: Generic configuration options for C<perlimports>
240  
241 =pod
242  
243 =encoding UTF-8
244  
245 =head1 NAME
246  
247 App::perlimports::Config - Generic configuration options for C<perlimports>
248  
249 =head1 VERSION
250  
251 version 0.000067
252  
253 =head1 DESCRIPTION
254  
255 This module isn't really meant to provide a public interface.
256  
257 =head2 create_config( $filename )
258  
259 This class method creates a L<perlimports> config file at the provided
260 filename. Dies if the file already exists.
261  
262 =head1 AUTHOR
263  
264 Olaf Alders <olaf@wundercounter.com>
265  
266 =head1 COPYRIGHT AND LICENSE
267  
268 This software is copyright (c) 2020 by Olaf Alders.
269  
270 This is free software; you can redistribute it and/or modify it under
271 the same terms as the Perl 5 programming language system itself.
272  
273 =cut
274  
275 __DATA__
« test-data/lib/Local/ImportException.pm ↑ Summary blib/lib/App/perlimports/ExportInspector.pm »