blib/lib/Dist/Zilla/Util/FileGenerator.pm

filter: Statementstmt 24.1% 21 / 87 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 27.7% 5 / 18 Podpod 100% 4 / 4 totaltotal 19.7% 30 / 152 CC 21 SCAR 30.9
CC
21
Cov
17%
_parse_plugin_entry
72.0
_add_file_exclusions
20.0
_prepare_file
20.0
CRAP 22.1
↑ Summary
1 2 ▶use strictures;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Dist::Zilla::Util::FileGenerator;
4  
5 2 our $VERSION = '0.120090'; # VERSION
6  
7 # ABSTRACT: helper to generate files with little repetition in a PluginBundle
8  
9 #
10 # This file is part of Dist-Zilla-Util-FileGenerator
11 #
12 # This software is Copyright (c) 2012 by Christian Walde.
13 #
14 # This is free software, licensed under:
15 #
16 # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 2004
17 #
18  
19 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use MooseX::HasDefaults::RO;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 ▶sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
23 2 has $_ => ( required => 1 ) for qw( files source );
24  
25 2 has generators_added => ( is => 'rw' );
26  
27 2 has move => ( default => 0 );
28 2 has is_template => ( default => 1 );
29 2 has source_type => ( default => 'module' );
30 2 has generate_before_plugin => ( default => 'Manifest' );
31 2 ▶ has exclusion_keys => ( default => sub { { GatherDir => 'exclude_filename', PruneCruft => 'except' } } );
Subroutine __ANON__: called CC=1 SCAR=0.0
32  
33 2 has prepared_files => ( lazy => 1, builder => "_build_prepared_files" );
34 }
35 2 ->();
36  
37  
38 0 ▶sub combine_with {
Subroutine combine_with: not called CC=2 SCAR=17.9
Pod documented
39 0 my ( $self, @plugins ) = @_;
40  
41 0 $self->generators_added( 0 );
42  
43 0 @plugins = map $self->_add_file_exclusions( $_ ), @plugins;
44 0 @plugins = map $self->_add_generators_copiers( $_ ), @plugins;
45  
46 0 ▶ die "could not find the plugin before which generators should be inserted" if !$self->generators_added;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->generators_added 0 0 0
47 0 $self->generators_added( 0 );
48  
49 0 return @plugins;
50 }
51  
52 0 ▶sub _add_file_exclusions {
Subroutine _add_file_exclusions: not called CC=4 SCAR=30.0
53 0 my ( $self, $entry ) = @_;
54  
55 0 my ( $plugin, $name, $config ) = $self->_parse_plugin_entry( $entry );
56  
57 0 ▶ if ( my $key = $self->exclusion_keys->{$plugin} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = $self->exclusion_keys->{$plugin}) 0 0 0
58 0 ▶ $config->{$key} ||= [];
Condition0%0/2
$config->{$key} ||= []
l!l
00
MC/DC0%0/1
$config->{$key} ||= []
$config->{$key}
Truth table0%0/2
A
A= $config->{$key}
Aresult
11
00
59 0 ▶ $config->{$key} = [ $config->{$key} ] if !ref $config->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config->{$key} 0 0 0
60 0 push @{ $config->{$key} }, $self->file_names;
61  
62 0 return $self->_build_plugin_entry( $plugin, $name, $config );
63 }
64  
65 0 return $entry;
66 }
67  
68 0 ▶sub _add_generators_copiers {
Subroutine _add_generators_copiers: not called CC=2 SCAR=17.9
69 0 my ( $self, $entry ) = @_;
70  
71 0 my ( $plugin, $name, $config ) = $self->_parse_plugin_entry( $entry );
72  
73 0 ▶ return $entry if $plugin ne $self->generate_before_plugin;
Branch: 1 branch
BranchTrueFalseTotal
if $plugin ne $self->generate_before_plugin 0 0 0
74  
75 0 $self->generators_added( 1 );
76  
77 0 return ( $self->generators, $self->copiers, $entry );
78 }
79  
80 0 ▶sub _parse_plugin_entry {
Subroutine _parse_plugin_entry: not called CC=8 SCAR=42.8
81 0 my ( $self, $entry ) = @_;
82  
83 0 ▶ return ( $entry, undef, {} ) if !ref $entry;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $entry 0 0 0
84  
85 0 my @spec = @{$entry};
86 0 ▶ return ( $spec[0], undef, {} ) if @spec == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @spec == 1 0 0 0
87 0 ▶ return ( $spec[0], $spec[1], {} ) if @spec == 2 and !ref $spec[1];
Branch: 1 branch
BranchTrueFalseTotal
if @spec == 2 and not ref $spec[1] 0 0 0
Condition0%0/3
@spec == 2 and not ref $spec[1]
!ll&&!rl&&r
000
MC/DC0%0/2
@spec == 2 and not ref $spec[1]
@spec == 2 not ref $spec[1]
Truth table0%0/3
A and not(B)
A= @spec == 2B= not ref $spec[1]
ABresult
0X0
100
111
88 0 ▶ return ( $spec[0], undef, $spec[1] ) if @spec == 2 and ref $spec[1];
Branch: 1 branch
BranchTrueFalseTotal
if @spec == 2 and ref $spec[1] 0 0 0
Condition0%0/3
@spec == 2 and ref $spec[1]
!ll&&!rl&&r
000
MC/DC0%0/2
@spec == 2 and ref $spec[1]
@spec == 2 ref $spec[1]
Truth table0%0/3
A and B
A= @spec == 2B= ref $spec[1]
ABresult
0X0
100
111
89 0 ▶ return ( $spec[0], $spec[1], $spec[2] ) if @spec == 3;
Branch: 1 branch
BranchTrueFalseTotal
if @spec == 3 0 0 0
90  
91 0 die "weird plugin spec: @spec";
92 }
93  
94 0 ▶sub _build_plugin_entry {
Subroutine _build_plugin_entry: not called CC=2 SCAR=17.9
95 0 my ( $self, $plugin, $name, $config ) = @_;
96  
97 0 my @entry = ( $plugin );
98 0 ▶ push @entry, $name if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
99 0 push @entry, $config;
100  
101 0 return \@entry;
102 }
103  
104 0 ▶sub _build_prepared_files {
Subroutine _build_prepared_files: not called CC=1 SCAR=6.9
105 0 my ( $self ) = @_;
106 0 return [ map $self->_prepare_file( $_ ), @{ $self->files } ];
107 }
108  
109 0 ▶sub _prepare_file {
Subroutine _prepare_file: not called CC=4 SCAR=30.0
110 0 my ( $self, $file ) = @_;
111  
112 0 my %file = ( name => $file );
113 0 ▶ %file = ( name => shift @{$file}, @{$file} ) if ref $file;
Branch: 1 branch
BranchTrueFalseTotal
if ref $file 0 0 0
114  
115 0 for my $key ( qw( move source_type source is_template ) ) {
116 0 ▶ $file{$key} = $self->$key if !exists $file{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $file{$key} 0 0 0
117 }
118  
119 0 return \%file;
120 }
121  
122  
123 0 ▶sub generators {
Subroutine generators: not called CC=1 SCAR=6.9
Pod documented
124 0 my ( $self ) = @_;
125  
126 0 return map $self->_file_generator( $_ ), @{ $self->prepared_files };
127 }
128  
129  
130 0 ▶sub file_names {
Subroutine file_names: not called CC=1 SCAR=6.9
Pod documented
131 0 my ( $self ) = @_;
132 0 return map $_->{name}, @{ $self->prepared_files };
133 }
134  
135  
136 0 ▶sub copiers {
Subroutine copiers: not called CC=1 SCAR=6.9
Pod documented
137 0 my ( $self ) = @_;
138 0 return map $self->_file_copier( $_ ), @{ $self->prepared_files };
139 }
140  
141 0 ▶sub _file_generator {
Subroutine _file_generator: not called CC=3 SCAR=24.8
142 0 my ( $self, $file ) = @_;
143  
144 0 my $content;
145 0 ▶ $content = $self->_module_template( $file->{source}, $file->{name} ) if $file->{source_type} eq 'module';
Branch: 1 branch
BranchTrueFalseTotal
if $file->{"source_type"} eq "module" 0 0 0
146 0 ▶ $content .= $file->{extra_content} if $file->{extra_content};
Branch: 1 branch
BranchTrueFalseTotal
if $file->{"extra_content"} 0 0 0
147  
148 my $generator = [
149 GenerateFile => "Generate-$file->{name}" => {
150 filename => $file->{name},
151 is_template => $file->{is_template},
152 0 content => $content,
153 }
154 ];
155  
156 0 return $generator;
157 }
158  
159 0 ▶sub _module_template {
Subroutine _module_template: not called CC=1 SCAR=6.9
160 0 my ( $self, $class, $file_name ) = @_;
161 0 return $class->data( $file_name );
162 }
163  
164 0 ▶sub _file_copier {
Subroutine _file_copier: not called CC=2 SCAR=17.9
165 0 my ( $self, $file ) = @_;
166  
167 0 ▶ my $op = $file->{move} ? "move" : "copy";
Branch: 1 branch
BranchTrueFalseTotal
$file->{'move'} ? : 0 0 0
168  
169 0 return [ CopyFilesFromBuild => "Copy-$file->{name}" => { $op => $file->{name} } ];
170 }
171  
172 2 1;
173  
174 __END__
↑ Summary