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