Alien/Build/Wizard.pm

filter: Statementstmt 73.5% 86 / 117 Branchbran 32.1% 9 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.0% 21 / 25 Podpod 0.0% 0 / 1 totaltotal 67.8% 116 / 171 CC 17 SCAR 14.0
CC
17
Cov
66%
__ANON__
9.8
generate_content
7.8
__ANON__
6.0
CRAP 4.1
« Alien/Build/Wizard/Detect.pm ↑ Summary Alien/Build/Wizard/Questions.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 package Alien::Build::Wizard 0.07 {
6  
7 4 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶ use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶ use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶ use experimental qw( signatures postderef );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶ use Data::Section::Simple qw( get_data_section );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶ use Alien::Build::Wizard::Detect;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶ use Alien::Build::Wizard::Questions qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶ use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # ABSTRACT: Alien distribution creation wizard
17  
18 has detect => (
19 is => 'ro',
20 isa => 'Alien::Build::Wizard::Detect',
21 lazy => 1,
22 2 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=4 SCAR=16.8
23 2 for(1..20)
24 {
25 2 my $url = $self->chrome->ask(QUESTION_URL);
26  
27 2 ▶ if($url eq '')
Branch: 1 branch
BranchTrueFalseTotal
if ($url eq "") 0 2 2
28 {
29 0 $self->chrome->say("URL is required");
30 0 next;
31 }
32  
33 2 my $detect = eval { Alien::Build::Wizard::Detect->new( uri => $url ) };
34 2 ▶ if(my $error = $@)
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) { } 0 2 2
35 {
36 0 $self->chrome->say("there appears to have been a problem fetching or detecting that tarball.");
37 0 $self->chrome->say("$error");
38 }
39 else
40 {
41 2 return $detect;
42 }
43 }
44 0 die "Bailing unable to get good input";
45 },
46 4 );
47  
48 has chrome => (
49 is => 'ro',
50 isa => 'Alien::Build::Wizard::Chrome',
51 lazy => 1,
52 2 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 2 require Alien::Build::Wizard::Chrome;
54 2 Alien::Build::Wizard::Chrome->new;
55 },
56 4 );
57  
58 has class_name => (
59 is => 'ro',
60 isa => 'Str',
61 lazy => 1,
62 1 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
63 1 $self->chrome->ask(QUESTION_CLASS_NAME, 'Alien::' . $self->detect->name);
64 },
65 4 );
66  
67 has start_url => (
68 is => 'ro',
69 isa => 'URI',
70 lazy => 1,
71 0 ▶ default => sub ($self) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
72 0 ▶ if($self->latest)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->latest) { } 0 0 0
73 {
74 0 my $url = $self->detect->uri->clone;
75 0 my $path = $url->path;
76 0 $path =~ s{/[^/]*?$}{};
77 0 $url->path($path);
78 0 return $url;
79 }
80 else
81 {
82 0 return $self->detect->uri;
83 }
84 },
85 4 );
86  
87 has human_name => (
88 is => 'ro',
89 isa => 'Str',
90 lazy => 1,
91 2 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
92 2 $self->chrome->ask(QUESTION_HUMAN_NAME, $self->detect->name);
93 },
94 4 );
95  
96 has pkg_names => (
97 is => 'ro',
98 isa => 'ArrayRef[Str]',
99 lazy => 1,
100 4 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=1 SCAR=0.0
101 4 [split /\s+/, $self->chrome->ask(QUESTION_PKG_NAMES, join ' ', $self->detect->pkg_config->@*)];
102 },
103 4 );
104  
105 has extract_format => (
106 is => 'ro',
107 isa => 'Str',
108 lazy => 1,
109 1 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=3 SCAR=15.1
110 1 my $basename = Path::Tiny->new($self->detect->uri->path)->basename;
111  
112 # tar format is usually .tar or .tar.gz .tar.bz2 etc.
113 1 ▶ if($basename =~ /\.(tar(\..*)?)$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($basename =~ /\.(tar(\..*)?)$/u) { } 1 0 1
elsif ($basename =~ /\.(.*?)$/u) { } 0 0 0
114 {
115 1 return $1;
116 }
117 # non-greedy to only get the last . for non tars
118 elsif($basename =~ /\.(.*?)$/)
119 {
120 0 return $1;
121 }
122 # fallback on .fixme, user will probably have to update
123 else
124 {
125 0 return 'fixme';
126 }
127 },
128 4 );
129  
130 has build_type => (
131 is => 'ro',
132 isa => 'Str',
133 lazy => 1,
134 1 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=3 SCAR=22.8
135 1 my @types = $self->detect->build_type->@*;
136 0 ▶ if(@types == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (@types == 0) { } 0 0 0
elsif (@types == 1) { } 0 0 0
137 {
138 0 $self->chrome->say("Unable to detect build system used by the package. You can select manual to specify the build commands directly, or select one of the standard build systems");
139 }
140 elsif(@types == 1)
141 {
142 0 $self->chrome->say("The build system was detected as $types[0]; that is probably correct");
143 }
144 else
145 {
146 0 $self->chrome->say("Multiple build systems were detected in the tarball; select the most reliable one of: @types");
147 }
148 0 my $default = $types[0];
149 0 scalar $self->chrome->choose(QUESTION_BUILD_SYSTEM, ['manual','autoconf','cmake','make'], \@types);
150 },
151 4 );
152  
153 has alien_types => (
154 is => 'ro',
155 isa => 'HashRef[Int]',
156 lazy => 1,
157 2 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=2 SCAR=7.5
158 2 while(1)
159 {
160 2 my @types = $self->chrome->choose(QUESTION_ALIEN_TYPE, ['tool','xs','ffi'], ['xs']);
161 2 ▶ unless(@types)
Branch: 1 branch
BranchTrueFalseTotal
unless (@types) 0 2 2
162 {
163 0 $self->chrome->say("You must select at least one type");
164 0 next;
165 }
166 2 my %answer = map { $_ => 1 } @types;
167 2 return \%answer;
168 }
169 }
170 4 );
171  
172 has latest => (
173 is => 'ro',
174 isa => 'Int',
175 lazy => 1,
176 0 ▶ default => sub ($self) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
177 0 my $value = $self->chrome->choose(QUESTION_LATEST, ['latest','specific'], ['latest']);
178 0 ▶ $value eq 'latest' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value eq 'latest' ? : 0 0 0
179 },
180 4 );
181  
182 has prefix => (
183 is => 'ro',
184 isa => 'Str',
185 lazy => 1,
186 0 ▶ default => sub ($self) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
187 0 my $path = $self->detect->uri->path;
188 0 my($file) = $path =~ /\/([^\/]*?)$/;
189 0 my($prefix) = $file =~ /^([^-^\.]+)/;
190 0 $prefix;
191 }
192 4 );
193  
194 3 ▶ sub generate_content ($self)
Subroutine generate_content: called CC=7 SCAR=20.5
Pod undocumented
195 {
196 3 my %files;
197  
198 3 require Template;
199 my $tt = Template->new(
200 FILTERS => {
201 0 ▶ regex_escape => sub ($text) { $text =~ s/\./\\./gr },
Subroutine __ANON__: not called CC=1 SCAR=6.9
202 },
203 3 );
204  
205 3 ▶ my $pod = sub ($name) { "=$name" };
Subroutine __ANON__: called CC=1 SCAR=0.0
206  
207 {
208 3 my $pm = 'lib/' . $self->class_name . ".pm";
209 3 $pm =~ s{::}{/};
210 3 my $template = get_data_section 'Module.pm';
211 3 $template =~ s/\s+$/\n/;
212 3 ▶ die "no template Module.pm" unless $template;
Branch: 1 branch
BranchTrueFalseTotal
unless $template 0 3 3
213 3 ▶ $tt->process(\$template, { wizard => $self, pod => $pod }, \($files{$pm} = '')) or die $tt->error;
Branch: 1 branch
BranchTrueFalseTotal
$tt->process(\$template, {"wizard", $self, "pod", $pod}, \($files{$pm} = "")) or die $tt->error 3 0 3
214 }
215  
216 3 foreach my $path (qw( alienfile t/basic.t ))
217 {
218 3 my $template = get_data_section $path;
219 3 $template =~ s/\s+$/\n/;
220 3 ▶ die "no template $path" unless $template;
Branch: 1 branch
BranchTrueFalseTotal
unless $template 0 3 3
221 3 my $store_path = $path;
222 0 ▶ $store_path = "t/@{[ lc($self->class_name =~ s/::/_/gr) ]}.t" if $path eq 't/basic.t';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "t/basic.t" 0 3 3
223 3 ▶ $tt->process(\$template, { wizard => $self, pod => $pod }, \($files{$store_path} = '')) or die $tt->error;
Branch: 1 branch
BranchTrueFalseTotal
$tt->process(\$template, {"wizard", $self, "pod", $pod}, \($files{$store_path} = "")) or die $tt->error 0 3 3
224 }
225  
226 0 \%files;
227 }
228  
229 }
230  
231 package Alien::Build::Wizard;
232  
233 4 1;
234  
235 =pod
236  
237 =encoding UTF-8
238  
239 =head1 NAME
240  
241 Alien::Build::Wizard - Alien distribution creation wizard
242  
243 =head1 VERSION
244  
245 version 0.07
246  
247 =head1 SYNOPSIS
248  
249 % perldoc Dist::Zilla::MintingProfile::AlienBuild
250  
251 =head1 DESCRIPTION
252  
253 This class is private.
254  
255 =head1 SEE ALSO
256  
257 =over 4
258  
259 =item L<Dist::Zilla::MintingProfile::AlienBuild>
260  
261 =back
262  
263 =head1 AUTHOR
264  
265 Graham Ollis <plicease@cpan.org>
266  
267 =head1 COPYRIGHT AND LICENSE
268  
269 This software is copyright (c) 2021-2022 by Graham Ollis.
270  
271 This is free software; you can redistribute it and/or modify it under
272 the same terms as the Perl 5 programming language system itself.
273  
274 =cut
275  
276 __DATA__
« Alien/Build/Wizard/Detect.pm ↑ Summary Alien/Build/Wizard/Questions.pm »