File Coverage

blib/lib/Dist/Zilla/Plugin/DistINI.pm
Criterion Covered Total %
statement 42 43 97.6
branch 1 2 50.0
condition n/a
subroutine 9 9 100.0
pod 0 2 0.0
total 52 56 92.8


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::DistINI 6.037;
2             # ABSTRACT: a plugin to add a dist.ini to newly-minted dists
3              
4 2     2   2331 use Moose;
  2         5  
  2         16  
5             with qw(Dist::Zilla::Role::FileGatherer);
6              
7 2     2   11982 use Dist::Zilla::Pragmas;
  2         3  
  2         20  
8              
9 2     2   714 use Dist::Zilla::File::FromCode;
  2         22  
  2         135  
10              
11 2     2   16 use MooseX::Types::Moose qw(ArrayRef Str);
  2         3  
  2         32  
12 2     2   12389 use Dist::Zilla::Path;
  2         4  
  2         25  
13              
14 2     2   820 use namespace::autoclean;
  2         6  
  2         18  
15              
16             #pod =head1 DESCRIPTION
17             #pod
18             #pod This plugins produces a F<dist.ini> file in a new dist, specifying the required
19             #pod core attributes from the dist being minted.
20             #pod
21             #pod This plugin is dead simple and pretty stupid, but should get better as dist
22             #pod minting facilities improve. For example, it will not specify any plugins.
23             #pod
24             #pod In the meantime, you may be happier with a F<dist.ini> template.
25             #pod
26             #pod =attr append_file
27             #pod
28             #pod This parameter may be a filename in the profile's directory to append to the
29             #pod generated F<dist.ini> with things like plugins. In other words, if your make
30             #pod this file, called F<plugins.ini>:
31             #pod
32             #pod [@Basic]
33             #pod [NextRelease]
34             #pod [@Git]
35             #pod
36             #pod ...and your F<profile.ini> includes:
37             #pod
38             #pod [DistINI]
39             #pod append_file = plugins.ini
40             #pod
41             #pod ...then the generated C<dist.ini> in a newly-minted dist will look something
42             #pod like this:
43             #pod
44             #pod name = My-New-Dist
45             #pod author = E. Xavier Ample <example@example.com>
46             #pod license = Perl_5
47             #pod copyright_holder = E. Xavier Ample
48             #pod copyright_year = 2010
49             #pod
50             #pod [@Basic]
51             #pod [NextRelease]
52             #pod [@Git]
53             #pod
54             #pod =cut
55              
56 2     2 0 732 sub mvp_multivalue_args { qw(append_file) }
57              
58             has append_file => (
59             is => 'ro',
60             isa => ArrayRef[ Str ],
61             default => sub { [] },
62             );
63              
64             sub gather_files {
65 1     1 0 5 my ($self, $arg) = @_;
66              
67 1         66 my $zilla = $self->zilla;
68              
69 1         4 my $postlude = '';
70              
71 1         2 for (@{ $self->append_file }) {
  1         46  
72 1         41 my $fn = $self->zilla->root->child($_);
73              
74 1         73 $postlude .= path($fn)->slurp_utf8;
75             }
76              
77             my $code = sub {
78 1     1   5 my @core_attrs = qw(name authors copyright_holder);
79              
80 1         53 my $license = ref $zilla->license;
81 1 50       6 if ($license =~ /^Software::License::(.+)$/) {
82 1         4 $license = $1;
83             } else {
84 0         0 $license = "=$license";
85             }
86              
87 1         4 my $content = '';
88 1         35 $content .= sprintf "name = %s\n", $zilla->name;
89 1         3 $content .= sprintf "author = %s\n", $_ for @{ $zilla->authors };
  1         41  
90 1         3 $content .= sprintf "license = %s\n", $license;
91 1         14 $content .= sprintf "copyright_holder = %s\n", $zilla->copyright_holder;
92 1         56 $content .= sprintf "copyright_year = %s\n", (localtime)[5] + 1900;
93 1         3 $content .= "\n";
94              
95 1         7 $content .= $postlude;
96 1         1909 };
97              
98 1         69 my $file = Dist::Zilla::File::FromCode->new({
99             name => 'dist.ini',
100             code => $code,
101             });
102              
103 1         7 $self->add_file($file);
104             }
105              
106             __PACKAGE__->meta->make_immutable;
107             1;
108              
109             __END__
110              
111             =pod
112              
113             =encoding UTF-8
114              
115             =head1 NAME
116              
117             Dist::Zilla::Plugin::DistINI - a plugin to add a dist.ini to newly-minted dists
118              
119             =head1 VERSION
120              
121             version 6.037
122              
123             =head1 DESCRIPTION
124              
125             This plugins produces a F<dist.ini> file in a new dist, specifying the required
126             core attributes from the dist being minted.
127              
128             This plugin is dead simple and pretty stupid, but should get better as dist
129             minting facilities improve. For example, it will not specify any plugins.
130              
131             In the meantime, you may be happier with a F<dist.ini> template.
132              
133             =head1 PERL VERSION
134              
135             This module should work on any version of perl still receiving updates from
136             the Perl 5 Porters. This means it should work on any version of perl
137             released in the last two to three years. (That is, if the most recently
138             released version is v5.40, then this module should work on both v5.40 and
139             v5.38.)
140              
141             Although it may work on older versions of perl, no guarantee is made that the
142             minimum required version will not be increased. The version may be increased
143             for any reason, and there is no promise that patches will be accepted to
144             lower the minimum required perl.
145              
146             =head1 ATTRIBUTES
147              
148             =head2 append_file
149              
150             This parameter may be a filename in the profile's directory to append to the
151             generated F<dist.ini> with things like plugins. In other words, if your make
152             this file, called F<plugins.ini>:
153              
154             [@Basic]
155             [NextRelease]
156             [@Git]
157              
158             ...and your F<profile.ini> includes:
159              
160             [DistINI]
161             append_file = plugins.ini
162              
163             ...then the generated C<dist.ini> in a newly-minted dist will look something
164             like this:
165              
166             name = My-New-Dist
167             author = E. Xavier Ample <example@example.com>
168             license = Perl_5
169             copyright_holder = E. Xavier Ample
170             copyright_year = 2010
171              
172             [@Basic]
173             [NextRelease]
174             [@Git]
175              
176             =head1 AUTHOR
177              
178             Ricardo SIGNES 😏 <cpan@semiotic.systems>
179              
180             =head1 COPYRIGHT AND LICENSE
181              
182             This software is copyright (c) 2026 by Ricardo SIGNES.
183              
184             This is free software; you can redistribute it and/or modify it under
185             the same terms as the Perl 5 programming language system itself.
186              
187             =cut