Minilla/Migrate.pm

filter: Statementstmt 32.8% 47 / 143 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 15 / 24 Podpod 0.0% 0 / 8 totaltotal 28.7% 62 / 216 CC 23 SCAR 29.5
CC
23
Cov
26%
migrate_cpanfile
56.0
run
30.0
dist_ini2minil_toml
30.0
CRAP 19.0
« Minilla/Git.pm ↑ Summary Minilla/CLI/Release.pm »
1 package Minilla::Migrate;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use File::pushd;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use TOML 0.92 qw(to_toml);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Minilla::Gitignore;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Minilla::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
14 slurp spew require_optional
15 cmd cmd_perl slurp_utf8 spew_utf8
16 slurp_raw spew_raw
17 1 );
18 1 ▶use Minilla::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Minilla::Git;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Minilla::Project;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 has project => (
25 is => 'lazy',
26 );
27  
28 1 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 0 ▶sub _build_project {
Subroutine _build_project: not called CC=1 SCAR=6.9
31 0 my $self = shift;
32 0 Minilla::Project->new();
33 }
34  
35 0 ▶sub run {
Subroutine run: not called CC=5 SCAR=34.0
Pod undocumented
36 0 my $self = shift;
37  
38 0 ▶ if (!-d '.git') {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d ".git") 0 0 0
39 # init git repo
40 0 infof("Initializing git\n");
41 0 cmd('git', 'init');
42 }
43  
44 0 my $guard = pushd($self->project->dir);
45  
46 # Generate cpanfile from Build.PL/Makefile.PL
47 0 ▶ unless (-f 'cpanfile') {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "cpanfile") 0 0 0
48 0 $self->migrate_cpanfile();
49 }
50  
51 0 $self->generate_license();
52  
53 # TODO move top level *.pm to lib/?
54  
55 0 ▶ if (-f 'dist.ini') {
Branch: 2 branches
BranchTrueFalseTotal
if (-f 'dist.ini') { } 0 0 0
elsif (not -f 'minil.toml') { } 0 0 0
56 0 $self->dist_ini2minil_toml();
57 } elsif (!-f 'minil.toml') {
58 0 $self->project->generate_minil_toml('Default');
59 }
60  
61 0 $self->remove_unused_files();
62 0 $self->migrate_gitignore();
63 0 $self->project->regenerate_files();
64 0 $self->migrate_changes();
65  
66 0 git_add('.');
67 }
68  
69 0 ▶sub migrate_changes {
Subroutine migrate_changes: not called CC=3 SCAR=24.8
Pod undocumented
70 0 my $self = shift;
71  
72 0 ▶ if (-f 'Changes') {
Branch: 1 branch
BranchTrueFalseTotal
if (-f 'Changes') { } 0 0 0
73 # Q. Why :raw?
74 # A. It's for windows. See dzil.
75 0 my $content = slurp_raw('Changes');
76 0 ▶ unless ($content =~ qr!\{\{\$NEXT\}\}!) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content =~ qr/\{\{\$NEXT\}\}/) 0 0 0
77 0 $content =~ s!^(Revision history for Perl extension \S+\n\n)!$1\{\{\$NEXT\}\}\n\n!;
78 }
79 0 spew_raw('Changes', $content);
80 } else {
81 # Q. Why :raw?
82 # A. It's for windows. See dzil.
83 0 require Minilla::Profile::Default;
84 0 Minilla::Profile::Default->new_from_project(
85 $self->project
86 )->render('Changes');
87 }
88 }
89  
90 0 ▶sub rm {
Subroutine rm: not called CC=1 SCAR=6.9
Pod undocumented
91 0 my ($self, $file) = @_;
92 }
93  
94 0 ▶sub dist_ini2minil_toml {
Subroutine dist_ini2minil_toml: not called CC=5 SCAR=34.0
Pod undocumented
95 0 my $self = shift;
96  
97 0 infof("Converting dist.ini to minil.toml\n");
98  
99 0 require_optional( 'Config/MVP/Reader/INI.pm', 'Migrate dzil repo' );
100 0 require_optional( 'Dist/Zilla/MVP/Assembler.pm', 'Migrate dzil repo' );
101 0 require_optional( 'Dist/Zilla/Chrome/Term.pm', 'Migrate dzil repo' );
102 0 my $sequence = Config::MVP::Reader::INI->read_into_assembler(
103 'dist.ini',
104 Dist::Zilla::MVP::Assembler->new(
105 chrome => Dist::Zilla::Chrome::Term->new(),
106 )
107 );
108 0 my $conf = do {
109 # Note. dist.ini using @Milla does not have '_' section.
110 0 my $section = $sequence->section_named('_');
111 0 ▶ $section ? $section->payload : +{};
Branch: 1 branch
BranchTrueFalseTotal
$section ? : 0 0 0
112 };
113  
114 0 my $dst = +{};
115 0 for my $key (qw(name author version license)) {
116 0 ▶ if ( defined(my $val = $conf->{$key}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $val = $conf->{$key})) 0 0 0
117 0 $dst->{$key} = $val;
118 }
119 }
120 0 ▶ if (%$dst) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$dst) 0 0 0
121 0 my $toml = to_toml($dst);
122 0 spew( 'minil.toml' => $toml );
123 0 git_add('minil.toml');
124 }
125 0 git_rm('--quiet', 'dist.ini');
126  
127 0 $self->project->clear_metadata();
128 }
129  
130 0 ▶sub generate_license {
Subroutine generate_license: not called CC=2 SCAR=17.9
Pod undocumented
131 0 my ($self) = @_;
132  
133 0 ▶ unless (-f 'LICENSE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "LICENSE") 0 0 0
134 0 spew_raw('LICENSE', $self->project->metadata->license->fulltext());
135 0 git_add(qw(-f LICENSE));
136 }
137 }
138  
139 0 ▶sub migrate_cpanfile {
Subroutine migrate_cpanfile: not called CC=7 SCAR=40.3
Pod undocumented
140 0 my ($self) = @_;
141  
142 0 my $metafile;
143 0 ▶ if (-f 'Build.PL') {
Branch: 3 branches
BranchTrueFalseTotal
if (-f 'Build.PL') { } 0 0 0
elsif (-f 'Makefile.PL') { } 0 0 0
elsif (-f 'dist.ini') { } 0 0 0
144 0 ▶ if (slurp('Build.PL') =~ /Module::Build::Tiny/) {
Branch: 1 branch
BranchTrueFalseTotal
if (slurp('Build.PL') =~ /Module::Build::Tiny/) { } 0 0 0
145 0 infof("M::B::Tiny was detected. I hope META.json is already exists here\n");
146 0 $metafile = 'META.json';
147 } else {
148 0 cmd_perl('Build.PL');
149 0 $metafile = 'MYMETA.json';
150 }
151 } elsif (-f 'Makefile.PL') {
152 # ExtUtils::MakeMaker or Module::Install's
153 0 cmd_perl('Makefile.PL');
154 0 cmd($Config{make}, 'metafile');
155 0 $metafile = 'MYMETA.json';
156 } elsif (-f 'dist.ini') {
157 0 my %orig = map { $_ => 1 } glob('*/META.yml');
158 0 cmd_perl('-S', 'dzil', 'build');
159 0 ($metafile) = grep { !$orig{$_} } glob('*/META.yml');
160 } else {
161 0 errorf("There is no Build.PL/Makefile.PL/dist.ini: %s\n", Cwd::getcwd());
162 }
163  
164 0 ▶ unless (defined($metafile) && -f $metafile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $metafile and -f $metafile) 0 0 0
Condition0%0/3
defined $metafile and -f $metafile
!ll&&!rl&&r
000
MC/DC0%0/2
defined $metafile and -f $metafile
defined $metafile -f $metafile
Truth table0%0/3
A and B
A= defined $metafileB= -f $metafile
ABresult
0X0
100
111
165 0 errorf("Build.PL/Makefile.PL does not generates %s\n", $metafile);
166 }
167  
168 0 my $meta = CPAN::Meta->load_file($metafile);
169 0 my $prereqs = $meta->effective_prereqs->as_string_hash;
170  
171 0 infof("Using Module::Build (Because this distribution uses xs)\n");
172 0 delete $prereqs->{configure}->{requires}->{'ExtUtils::MakeMaker'};
173 0 delete $prereqs->{configure}->{requires}->{'Module::Build'};
174 0 delete $prereqs->{configure}->{requires}->{'Module::Build::Tiny'};
175  
176 0 my $cpanfile = Module::CPANfile->from_prereqs($prereqs);
177 0 spew('cpanfile', $cpanfile->to_string);
178  
179 0 git_add('cpanfile');
180 }
181  
182 0 ▶sub remove_unused_files {
Subroutine remove_unused_files: not called CC=4 SCAR=30.0
Pod undocumented
183 0 my $self = shift;
184  
185 # Some users put a README.pod symlink for main module.
186 # But it's duplicated to README.md created by Minilla.
187  
188 # remove some unusable files
189 0 for my $file (qw(
190 Makefile.PL
191 MANIFEST
192 MANIFEST.SKIP
193 .shipit
194 xt/97_podspell.t
195 xt/99_pod.t
196 xt/01_podspell.t xt/03_pod.t xt/05_cpan_meta.t
197 xt/04_minimum_version.t xt/06_meta_author.t
198 xt/podspell.t
199 MANIFEST.SKIP.bak
200 MANIFEST.bak
201 README.pod
202 META.yml
203 README
204 MYMETA.json
205 MYMETA.yml
206 inc/Module/Install.pm
207 ), glob('inc/Module/Install/*.pm')) {
208 0 ▶ if (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) 0 0 0
209 0 ▶ if (grep { $_ eq $file } git_ls_files()) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $file;} git_ls_files()) { } 0 0 0
210 # committed file
211 0 git_rm('--quiet', $file);
212 } else {
213 0 unlink $file;
214 }
215 }
216 }
217 }
218  
219 0 ▶sub migrate_gitignore {
Subroutine migrate_gitignore: not called CC=3 SCAR=24.8
Pod undocumented
220 0 my ($self) = @_;
221  
222 0 my @lines;
223  
224 0 ▶ my $gitignore = (
Branch: 1 branch
BranchTrueFalseTotal
-f '.gitignore' ? : 0 0 0
225 -f '.gitignore'
226 ? Minilla::Gitignore->load('.gitignore')
227 : Minilla::Gitignore->new()
228 );
229 0 $gitignore->remove('META.json');
230 0 $gitignore->remove('/META.json');
231 0 $gitignore->remove('LICENSE');
232  
233 # Add some lines
234 0 $gitignore->add(sprintf('/%s-*', $self->project->dist_name));
235 0 for my $fname (qw(
236 /.build
237 /_build_params
238 /Build
239 /Build.bat
240 !Build/
241 !META.json
242 !LICENSE
243 )) {
244 0 $gitignore->add($fname);
245 }
246  
247 0 $gitignore->save('.gitignore');
248  
249 0 git_add(qw(.gitignore));
250 }
251  
252  
253  
254 1 1;
255  
« Minilla/Git.pm ↑ Summary Minilla/CLI/Release.pm »