File Coverage

blib/lib/Dist/Zilla/Dist/Minter.pm
Criterion Covered Total %
statement 74 79 93.6
branch 3 8 37.5
condition 4 9 44.4
subroutine 9 10 90.0
pod 0 1 0.0
total 90 107 84.1


line stmt bran cond sub pod time code
1             package Dist::Zilla::Dist::Minter 6.029;
2             # ABSTRACT: distribution builder; installer not included!
3              
4 49     49   42522 use Moose 0.92; # role composition fixes
  49         1346  
  49         422  
5             extends 'Dist::Zilla';
6              
7 49     49   353868 use Dist::Zilla::Pragmas;
  49         148  
  49         550  
8              
9 49     49   444 use File::pushd ();
  49         168  
  49         1392  
10 49     49   363 use Dist::Zilla::Path;
  49         148  
  49         572  
11 49     49   16132 use Module::Runtime 'require_module';
  49         157  
  49         439  
12              
13 49     49   3041 use namespace::autoclean;
  49         162  
  49         696  
14              
15             sub _setup_default_plugins {
16 2     2   6 my ($self) = @_;
17              
18 2 50       15 unless ($self->plugin_named(':DefaultModuleMaker')) {
19 2         637 require Dist::Zilla::Plugin::TemplateModule;
20 2         82 my $plugin = Dist::Zilla::Plugin::TemplateModule->new({
21             plugin_name => ':DefaultModuleMaker',
22             zilla => $self,
23             });
24              
25 2         7 push @{ $self->plugins }, $plugin;
  2         62  
26             }
27             }
28              
29             sub _new_from_profile {
30 2     2   10 my ($class, $profile_data, $arg) = @_;
31 2   50     12 $arg ||= {};
32              
33             my $config_class =
34 2   50     16 $arg->{config_class} ||= 'Dist::Zilla::MVP::Reader::Finder';
35 2         12 require_module($config_class);
36              
37             $arg->{chrome}->logger->log_debug(
38 2         139 { prefix => '[DZ] ' },
39             "reading configuration using $config_class"
40             );
41              
42 2         651 require Dist::Zilla::MVP::Assembler::Zilla;
43 2         19 require Dist::Zilla::MVP::Section;
44             my $assembler = Dist::Zilla::MVP::Assembler::Zilla->new({
45             chrome => $arg->{chrome},
46 2         89 zilla_class => $class,
47             section_class => 'Dist::Zilla::MVP::Section', # make this DZMA default
48             });
49              
50 2         55 for ($assembler->sequence->section_named('_')) {
51 2         137 $_->add_value(name => $arg->{name});
52 2         159 $_->add_value(chrome => $arg->{chrome});
53             $_->add_value(_global_stashes => $arg->{_global_stashes})
54 2 50       129 if $arg->{_global_stashes};
55             }
56              
57 2         148 my $module = String::RewritePrefix->rewrite(
58             { '' => 'Dist::Zilla::MintingProfile::', '=', => '' },
59             $profile_data->[0],
60             );
61 2         166 require_module($module);
62              
63 2         47 my $profile_dir = $module->profile_dir($profile_data->[1]);
64              
65 2 50 33     115 warn "expected a string or Path::Tiny but got a Path::Class from $module\n"
66             if ref $profile_dir && $profile_dir->isa('Path::Class');
67              
68 2         9 $profile_dir = path($profile_dir);
69              
70 2         75 $assembler->sequence->section_named('_')->add_value(root => $profile_dir);
71              
72 2         142 my $seq = $config_class->read_config(
73             $profile_dir->child('profile'),
74             {
75             assembler => $assembler
76             },
77             );
78              
79 2         13 my $self = $seq->section_named('_')->zilla;
80              
81 2         18 $self->_setup_default_plugins;
82              
83 2         73 return $self;
84             }
85              
86             sub _mint_target_dir {
87 0     0   0 my ($self) = @_;
88              
89 0         0 my $name = $self->name;
90 0         0 my $dir = path($name);
91 0 0       0 $self->log_fatal("./$name already exists") if -e $dir;
92              
93 0         0 return $dir = $dir->absolute;
94             }
95              
96             sub mint_dist {
97 1     1 0 17 my ($self, $arg) = @_;
98              
99 1         34 my $name = $self->name;
100 1         6 my $dir = $self->_mint_target_dir;
101              
102             # XXX: We should have a way to get more than one module name in, and to
103             # supply plugin names for the minter to use. -- rjbs, 2010-05-03
104 1         9 my @modules = (
105             { name => $name =~ s/-/::/gr }
106             );
107              
108 1         5 $self->log("making target dir $dir");
109 1         445 $dir->mkpath;
110              
111 1         360 my $wd = File::pushd::pushd($self->root);
112              
113 1         209 $_->before_mint for @{ $self->plugins_with(-BeforeMint) };
  1         11  
114              
115 1         4 for my $module (@modules) {
116             my $minter = $self->plugin_named(
117 1   50     13 $module->{minter_name} || ':DefaultModuleMaker'
118             );
119              
120             $minter->make_module({ name => $module->{name} })
121 1         18 }
122              
123 1         3 $_->gather_files for @{ $self->plugins_with(-FileGatherer) };
  1         13  
124 1         4 $_->set_file_encodings for @{ $self->plugins_with(-EncodingProvider) };
  1         4  
125 1         3 $_->prune_files for @{ $self->plugins_with(-FilePruner) };
  1         4  
126 1         4 $_->munge_files for @{ $self->plugins_with(-FileMunger) };
  1         3  
127              
128 1         12 $self->_check_dupe_files;
129              
130 1         5 $self->log("writing files to $dir");
131              
132 1         283 for my $file (@{ $self->files }) {
  1         31  
133 2         45 $self->_write_out_file($file, $dir);
134             }
135              
136             $_->after_mint({ mint_root => $dir })
137 1         33 for @{ $self->plugins_with(-AfterMint) };
  1         7  
138              
139 1         7 $self->log("dist minted in ./$name");
140             }
141              
142             __PACKAGE__->meta->make_immutable;
143             1;
144              
145             __END__
146              
147             =pod
148              
149             =encoding UTF-8
150              
151             =head1 NAME
152              
153             Dist::Zilla::Dist::Minter - distribution builder; installer not included!
154              
155             =head1 VERSION
156              
157             version 6.029
158              
159             =head1 PERL VERSION
160              
161             This module should work on any version of perl still receiving updates from
162             the Perl 5 Porters. This means it should work on any version of perl released
163             in the last two to three years. (That is, if the most recently released
164             version is v5.40, then this module should work on both v5.40 and v5.38.)
165              
166             Although it may work on older versions of perl, no guarantee is made that the
167             minimum required version will not be increased. The version may be increased
168             for any reason, and there is no promise that patches will be accepted to lower
169             the minimum required perl.
170              
171             =head1 AUTHOR
172              
173             Ricardo SIGNES 😏 <cpan@semiotic.systems>
174              
175             =head1 COPYRIGHT AND LICENSE
176              
177             This software is copyright (c) 2022 by Ricardo SIGNES.
178              
179             This is free software; you can redistribute it and/or modify it under
180             the same terms as the Perl 5 programming language system itself.
181              
182             =cut