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.037;
2             # ABSTRACT: distribution builder; installer not included!
3              
4 49     49   40466 use Moose 0.92; # role composition fixes
  49         1014  
  49         575  
5             extends 'Dist::Zilla';
6              
7 49     49   343968 use Dist::Zilla::Pragmas;
  49         134  
  49         498  
8              
9 49     49   390 use File::pushd ();
  49         153  
  49         1364  
10 49     49   245 use Dist::Zilla::Path;
  49         106  
  49         529  
11 49     49   16442 use Module::Runtime 'require_module';
  49         141  
  49         411  
12              
13 49     49   3010 use namespace::autoclean;
  49         122  
  49         537  
14              
15             sub _setup_default_plugins {
16 2     2   7 my ($self) = @_;
17              
18 2 50       23 unless ($self->plugin_named(':DefaultModuleMaker')) {
19 2         789 require Dist::Zilla::Plugin::TemplateModule;
20 2         140 my $plugin = Dist::Zilla::Plugin::TemplateModule->new({
21             plugin_name => ':DefaultModuleMaker',
22             zilla => $self,
23             });
24              
25 2         8 push @{ $self->plugins }, $plugin;
  2         116  
26             }
27             }
28              
29             sub _new_from_profile {
30 2     2   8 my ($class, $profile_data, $arg) = @_;
31 2   50     10 $arg ||= {};
32              
33             my $config_class =
34 2   50     18 $arg->{config_class} ||= 'Dist::Zilla::MVP::Reader::Finder';
35 2         14 require_module($config_class);
36              
37             $arg->{chrome}->logger->log_debug(
38 2         183 { prefix => '[DZ] ' },
39             "reading configuration using $config_class"
40             );
41              
42 2         977 require Dist::Zilla::MVP::Assembler::Zilla;
43 2         34 require Dist::Zilla::MVP::Section;
44             my $assembler = Dist::Zilla::MVP::Assembler::Zilla->new({
45             chrome => $arg->{chrome},
46 2         121 zilla_class => $class,
47             section_class => 'Dist::Zilla::MVP::Section', # make this DZMA default
48             });
49              
50 2         80 for ($assembler->sequence->section_named('_')) {
51 2         169 $_->add_value(name => $arg->{name});
52 2         197 $_->add_value(chrome => $arg->{chrome});
53             $_->add_value(_global_stashes => $arg->{_global_stashes})
54 2 50       170 if $arg->{_global_stashes};
55             }
56              
57 2         195 my $module = String::RewritePrefix->rewrite(
58             { '' => 'Dist::Zilla::MintingProfile::', '=', => '' },
59             $profile_data->[0],
60             );
61 2         210 require_module($module);
62              
63 2         65 my $profile_dir = $module->profile_dir($profile_data->[1]);
64              
65 2 50 33     100 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         18 $profile_dir = path($profile_dir);
69              
70 2         103 $assembler->sequence->section_named('_')->add_value(root => $profile_dir);
71              
72 2         146 my $seq = $config_class->read_config(
73             $profile_dir->child('profile'),
74             {
75             assembler => $assembler
76             },
77             );
78              
79 2         19 my $self = $seq->section_named('_')->zilla;
80              
81 2         24 $self->_setup_default_plugins;
82              
83 2         102 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 20 my ($self, $arg) = @_;
98              
99 1         48 my $name = $self->name;
100 1         7 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         10 my @modules = (
105             { name => $name =~ s/-/::/gr }
106             );
107              
108 1         8 $self->log("making target dir $dir");
109 1         675 $dir->mkpath;
110              
111 1         483 my $wd = File::pushd::pushd($self->root);
112              
113 1         315 $_->before_mint for @{ $self->plugins_with(-BeforeMint) };
  1         15  
114              
115 1         4 for my $module (@modules) {
116             my $minter = $self->plugin_named(
117 1   50     17 $module->{minter_name} || ':DefaultModuleMaker'
118             );
119              
120             $minter->make_module({ name => $module->{name} })
121 1         11 }
122              
123 1         2 $_->gather_files for @{ $self->plugins_with(-FileGatherer) };
  1         6  
124 1         3 $_->set_file_encodings for @{ $self->plugins_with(-EncodingProvider) };
  1         7  
125 1         3 $_->prune_files for @{ $self->plugins_with(-FilePruner) };
  1         6  
126 1         5 $_->munge_files for @{ $self->plugins_with(-FileMunger) };
  1         20  
127              
128 1         17 $self->_check_dupe_files;
129              
130 1         8 $self->log("writing files to $dir");
131              
132 1         475 for my $file (@{ $self->files }) {
  1         50  
133 2         71 $self->_write_out_file($file, $dir);
134             }
135              
136             $_->after_mint({ mint_root => $dir })
137 1         51 for @{ $self->plugins_with(-AfterMint) };
  1         7  
138              
139 1         10 $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.037
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
163             released in the last two to three years. (That is, if the most recently
164             released version is v5.40, then this module should work on both v5.40 and
165             v5.38.)
166              
167             Although it may work on older versions of perl, no guarantee is made that the
168             minimum required version will not be increased. The version may be increased
169             for any reason, and there is no promise that patches will be accepted to
170             lower the minimum required perl.
171              
172             =head1 AUTHOR
173              
174             Ricardo SIGNES 😏 <cpan@semiotic.systems>
175              
176             =head1 COPYRIGHT AND LICENSE
177              
178             This software is copyright (c) 2026 by Ricardo SIGNES.
179              
180             This is free software; you can redistribute it and/or modify it under
181             the same terms as the Perl 5 programming language system itself.
182              
183             =cut