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