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.030;
2             # ABSTRACT: distribution builder; installer not included!
3              
4 49     49   43499 use Moose 0.92; # role composition fixes
  49         1424  
  49         461  
5             extends 'Dist::Zilla';
6              
7 49     49   358017 use Dist::Zilla::Pragmas;
  49         136  
  49         548  
8              
9 49     49   467 use File::pushd ();
  49         183  
  49         1460  
10 49     49   384 use Dist::Zilla::Path;
  49         162  
  49         591  
11 49     49   16452 use Module::Runtime 'require_module';
  49         159  
  49         458  
12              
13 49     49   3169 use namespace::autoclean;
  49         162  
  49         657  
14              
15             sub _setup_default_plugins {
16 2     2   7 my ($self) = @_;
17              
18 2 50       24 unless ($self->plugin_named(':DefaultModuleMaker')) {
19 2         694 require Dist::Zilla::Plugin::TemplateModule;
20 2         91 my $plugin = Dist::Zilla::Plugin::TemplateModule->new({
21             plugin_name => ':DefaultModuleMaker',
22             zilla => $self,
23             });
24              
25 2         7 push @{ $self->plugins }, $plugin;
  2         58  
26             }
27             }
28              
29             sub _new_from_profile {
30 2     2   8 my ($class, $profile_data, $arg) = @_;
31 2   50     7 $arg ||= {};
32              
33             my $config_class =
34 2   50     17 $arg->{config_class} ||= 'Dist::Zilla::MVP::Reader::Finder';
35 2         10 require_module($config_class);
36              
37             $arg->{chrome}->logger->log_debug(
38 2         131 { prefix => '[DZ] ' },
39             "reading configuration using $config_class"
40             );
41              
42 2         837 require Dist::Zilla::MVP::Assembler::Zilla;
43 2         16 require Dist::Zilla::MVP::Section;
44             my $assembler = Dist::Zilla::MVP::Assembler::Zilla->new({
45             chrome => $arg->{chrome},
46 2         84 zilla_class => $class,
47             section_class => 'Dist::Zilla::MVP::Section', # make this DZMA default
48             });
49              
50 2         53 for ($assembler->sequence->section_named('_')) {
51 2         151 $_->add_value(name => $arg->{name});
52 2         149 $_->add_value(chrome => $arg->{chrome});
53             $_->add_value(_global_stashes => $arg->{_global_stashes})
54 2 50       125 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         171 require_module($module);
62              
63 2         46 my $profile_dir = $module->profile_dir($profile_data->[1]);
64              
65 2 50 33     110 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         22 $profile_dir = path($profile_dir);
69              
70 2         76 $assembler->sequence->section_named('_')->add_value(root => $profile_dir);
71              
72 2         158 my $seq = $config_class->read_config(
73             $profile_dir->child('profile'),
74             {
75             assembler => $assembler
76             },
77             );
78              
79 2         15 my $self = $seq->section_named('_')->zilla;
80              
81 2         16 $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 32 my ($self, $arg) = @_;
98              
99 1         36 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         9 my @modules = (
105             { name => $name =~ s/-/::/gr }
106             );
107              
108 1         7 $self->log("making target dir $dir");
109 1         512 $dir->mkpath;
110              
111 1         366 my $wd = File::pushd::pushd($self->root);
112              
113 1         269 $_->before_mint for @{ $self->plugins_with(-BeforeMint) };
  1         13  
114              
115 1         5 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         8 }
122              
123 1         3 $_->gather_files for @{ $self->plugins_with(-FileGatherer) };
  1         5  
124 1         4 $_->set_file_encodings for @{ $self->plugins_with(-EncodingProvider) };
  1         6  
125 1         3 $_->prune_files for @{ $self->plugins_with(-FilePruner) };
  1         4  
126 1         3 $_->munge_files for @{ $self->plugins_with(-FileMunger) };
  1         15  
127              
128 1         13 $self->_check_dupe_files;
129              
130 1         10 $self->log("writing files to $dir");
131              
132 1         275 for my $file (@{ $self->files }) {
  1         30  
133 2         49 $self->_write_out_file($file, $dir);
134             }
135              
136             $_->after_mint({ mint_root => $dir })
137 1         33 for @{ $self->plugins_with(-AfterMint) };
  1         6  
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.030
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) 2023 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