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.029;
2             # ABSTRACT: a plugin to add a dist.ini to newly-minted dists
3              
4 2     2   2195 use Moose;
  2         5  
  2         20  
5             with qw(Dist::Zilla::Role::FileGatherer);
6              
7 2     2   14541 use Dist::Zilla::Pragmas;
  2         4  
  2         20  
8              
9 2     2   551 use Dist::Zilla::File::FromCode;
  2         7  
  2         115  
10              
11 2     2   20 use MooseX::Types::Moose qw(ArrayRef Str);
  2         6  
  2         23  
12 2     2   10660 use Dist::Zilla::Path;
  2         5  
  2         19  
13              
14 2     2   617 use namespace::autoclean;
  2         6  
  2         15  
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 530 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 11 my ($self, $arg) = @_;
66              
67 1         40 my $zilla = $self->zilla;
68              
69 1         3 my $postlude = '';
70              
71 1         3 for (@{ $self->append_file }) {
  1         32  
72 1         30 my $fn = $self->zilla->root->child($_);
73              
74 1         59 $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         35 my $license = ref $zilla->license;
81 1 50       7 if ($license =~ /^Software::License::(.+)$/) {
82 1         4 $license = $1;
83             } else {
84 0         0 $license = "=$license";
85             }
86              
87 1         3 my $content = '';
88 1         25 $content .= sprintf "name = %s\n", $zilla->name;
89 1         2 $content .= sprintf "author = %s\n", $_ for @{ $zilla->authors };
  1         32  
90 1         4 $content .= sprintf "license = %s\n", $license;
91 1         20 $content .= sprintf "copyright_holder = %s\n", $zilla->copyright_holder;
92 1         57 $content .= sprintf "copyright_year = %s\n", (localtime)[5] + 1900;
93 1         4 $content .= "\n";
94              
95 1         6 $content .= $postlude;
96 1         1507 };
97              
98 1         50 my $file = Dist::Zilla::File::FromCode->new({
99             name => 'dist.ini',
100             code => $code,
101             });
102              
103 1         6 $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.029
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 released
137             in the last two to three years. (That is, if the most recently released
138             version is v5.40, then this module should work on both v5.40 and v5.38.)
139              
140             Although it may work on older versions of perl, no guarantee is made that the
141             minimum required version will not be increased. The version may be increased
142             for any reason, and there is no promise that patches will be accepted to lower
143             the minimum required perl.
144              
145             =head1 ATTRIBUTES
146              
147             =head2 append_file
148              
149             This parameter may be a filename in the profile's directory to append to the
150             generated F<dist.ini> with things like plugins. In other words, if your make
151             this file, called F<plugins.ini>:
152              
153             [@Basic]
154             [NextRelease]
155             [@Git]
156              
157             ...and your F<profile.ini> includes:
158              
159             [DistINI]
160             append_file = plugins.ini
161              
162             ...then the generated C<dist.ini> in a newly-minted dist will look something
163             like this:
164              
165             name = My-New-Dist
166             author = E. Xavier Ample <example@example.com>
167             license = Perl_5
168             copyright_holder = E. Xavier Ample
169             copyright_year = 2010
170              
171             [@Basic]
172             [NextRelease]
173             [@Git]
174              
175             =head1 AUTHOR
176              
177             Ricardo SIGNES 😏 <cpan@semiotic.systems>
178              
179             =head1 COPYRIGHT AND LICENSE
180              
181             This software is copyright (c) 2022 by Ricardo SIGNES.
182              
183             This is free software; you can redistribute it and/or modify it under
184             the same terms as the Perl 5 programming language system itself.
185              
186             =cut