File Coverage

blib/lib/Dist/Zilla/PluginBundle/Author/RWSTAUNER/Minter.pm
Criterion Covered Total %
statement 34 34 100.0
branch 1 2 50.0
condition n/a
subroutine 11 11 100.0
pod 0 4 0.0
total 46 51 90.2


line stmt bran cond sub pod time code
1             # vim: set ts=2 sts=2 sw=2 expandtab smarttab:
2             #
3             # This file is part of Dist-Zilla-PluginBundle-Author-RWSTAUNER
4             #
5             # This software is copyright (c) 2010 by Randy Stauner.
6             #
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             #
10 1     1   15044 use strict;
  1         2  
  1         33  
11 1     1   5 use warnings;
  1         3  
  1         89  
12              
13             package Dist::Zilla::PluginBundle::Author::RWSTAUNER::Minter;
14             our $AUTHORITY = 'cpan:RWSTAUNER';
15             # ABSTRACT: RWSTAUNER's Dist::Zilla config for minting
16             $Dist::Zilla::PluginBundle::Author::RWSTAUNER::Minter::VERSION = '6.002';
17 1     1   6 use Moose;
  1         5  
  1         8  
18 1     1   6987 use MooseX::AttributeShortcuts;
  1         196253  
  1         5  
19 1     1   45061 use Git::Wrapper;
  1         3  
  1         42  
20 1     1   5 use Data::Section -setup;
  1         3  
  1         11  
21              
22             with qw(
23             Dist::Zilla::Role::PluginBundle::Easy
24             );
25              
26             has pause_id => (
27               is => 'ro',
28               default => sub { ((ref($_[0]) || $_[0]) =~ /Author::([A-Z]+)/)[0] },
29             );
30              
31             has _git => (
32               is => 'lazy',
33               default => sub { Git::Wrapper->new('.') },
34             );
35              
36             sub git_config {
37 3     3 0 12   my ($self, $key) = @_;
38 3         117   return ($self->_git->config($key))[0];
39             }
40              
41             foreach my $attr ( qw( name email ) ){
42               has "git_$attr" => (
43                 is => 'lazy',
44                 default => sub { $_[0]->git_config("user.$attr") },
45               );
46             }
47              
48             has github_user => (
49               is => 'lazy',
50               default => sub { $_[0]->git_config("github.user") },
51             );
52              
53             around bundle_config => sub {
54               my ($orig, $self, @args) = @_;
55               my @plugins = $self->$orig(@args);
56              
57             # remove bundle prefix since dzil looks this one up by name
58               $_->[0] =~ s/.+?\/(:DefaultModuleMaker)/$1/ for @plugins;
59              
60               return @plugins;
61             };
62              
63             sub configure {
64 1     1 0 6   my ($self) = @_;
65              
66 1 50       38   $self->add_plugins(
67                 [ TemplateModule => ':DefaultModuleMaker', { template => 'Module.template' } ],
68              
69                 [
70                   'Git::Init' => $self->github_user ? {
71                     remote => 'origin git@github.com:' . $self->github_user . '/%N.git',
72                     config => [
73                       'branch.master.remote origin',
74                       'branch.master.merge refs/heads/master',
75                     ],
76                   } : {}
77                 ],
78              
79             #'GitHub::Create',
80              
81                 [
82                   'Run::AfterMint' => {
83                     run => [
84             # create the t/ directory so that it's already there
85             # when i try to create a file beneath
86                       '%x -e "mkdir(shift(@ARGV))" %d%pt',
87                     ],
88                   },
89                 ],
90               );
91              
92 1         218   $self->generate_files( $self->merged_section_data );
93 1         94   $self->generate_mailmap;
94             }
95              
96             sub generate_files {
97 2     2 0 2789   my ($self, $files) = @_;
98 2         21   while( my ($name, $content) = each %$files ){
99 6         411     $content = $$content;
100             # GenerateFile will append a new line
101 6         45     $content =~ s/\n+\z//;
102 6         68     $self->add_plugins(
103                   [
104                     GenerateFile => "Generate-$name" => {
105                       filename => $name,
106                       is_template => 1,
107                       content => $content,
108                     }
109                   ],
110                 );
111               }
112             }
113              
114             sub generate_mailmap {
115 1     1 0 3   my ($self) = @_;
116 1         43   $self->generate_files({
117                 '.mailmap' => \sprintf '%s <%s@cpan.org> <%s>',
118                   $self->git_name, lc($self->pause_id), $self->git_email,
119               });
120             }
121              
122 1     1   1189 no Moose;
  1         3  
  1         9  
123             __PACKAGE__->meta->make_immutable;
124             1;
125              
126             =pod
127            
128             =encoding UTF-8
129            
130             =for :stopwords Randy Stauner ACKNOWLEDGEMENTS RWSTAUNER's PluginBundle
131            
132             =head1 NAME
133            
134             Dist::Zilla::PluginBundle::Author::RWSTAUNER::Minter - RWSTAUNER's Dist::Zilla config for minting
135            
136             =head1 VERSION
137            
138             version 6.002
139            
140             =head1 SYNOPSIS
141            
142             ; profile.ini
143            
144             [@Author::RWSTAUNER::Minter]
145            
146             =head1 DESCRIPTION
147            
148             Configure L<Dist::Zilla> to mint a new dist.
149            
150             =for Pod::Coverage configure
151             git_config
152             generate_files
153             generate_mailmap
154            
155             =head1 ROUGHLY EQUIVALENT
156            
157             This bundle is roughly equivalent to the following (generated) F<profile.ini>:
158            
159             [TemplateModule / :DefaultModuleMaker]
160             template = Module.template
161            
162             [Git::Init]
163             config = branch.master.remote origin
164             config = branch.master.merge refs/heads/master
165             remote = origin git@github.com:rwstauner/%N.git
166            
167             [Run::AfterMint]
168             run = %x -e "mkdir(shift(@ARGV))" %d%pt
169            
170             [GenerateFile / Generate-Changes]
171             content = Revision history for {{$dist->name}}
172             content = {{ '{{$NEXT}}' }}
173             content = - Initial release
174             filename = Changes
175             is_template = 1
176            
177             [GenerateFile / Generate-README.mkdn]
178             content = # NAME
179             content = {{ (my $n = $dist->name) =~ s/-/::/g; $n }} - undef
180             content = # COPYRIGHT AND LICENSE
181             content = This software is copyright (c) {{ (localtime)[5]+1900 }} by {{ $dist->copyright_holder }}.
182             content = This is free software; you can redistribute it and/or modify it under
183             content = the same terms as the Perl 5 programming language system itself.
184             filename = README.mkdn
185             is_template = 1
186            
187             [GenerateFile / Generate-.gitignore]
188             content = /{{$dist->name}}*
189             content = /.build
190             content = /cover_db/
191             content = /nytprof*
192             content = /tags
193             filename = .gitignore
194             is_template = 1
195            
196             [GenerateFile / Generate-dist.ini]
197             content = {{
198             content = $license = ref $dist->license;
199             content = if ( $license =~ /^Software::License::(.+)$/ ) {
200             content = $license = $1;
201             content = } else {
202             content = $license = "=$license";
203             content = }
204             content = $authors = join( "\n", map { "author = $_" } @{ $dist->authors } );
205             content = $copyright_year = (localtime)[5] + 1900;
206             content = '';
207             content = }}name = {{ $dist->name }}
208             content = {{ $authors }}
209             content = license = {{ $license }}
210             content = copyright_holder = {{ join( ', ', map { (/^(.+) <.+>/)[0] }@{ $dist->authors } ) }}
211             content = copyright_year = {{ $copyright_year }}
212             content = [@Author::RWSTAUNER]
213             filename = dist.ini
214             is_template = 1
215            
216             [GenerateFile / Generate-LICENSE]
217             content = This is free software; you can redistribute it and/or modify it under
218             content = the same terms as the Perl 5 programming language system itself.
219             filename = LICENSE
220             is_template = 1
221            
222             [GenerateFile / Generate-.mailmap]
223             content = Randy Stauner <rwstauner@cpan.org> <randy@magnificent-tears.com>
224             filename = .mailmap
225             is_template = 1
226            
227             =head1 SEE ALSO
228            
229             =over 4
230            
231             =item *
232            
233             L<Dist::Zilla::MintingProfile::Author::RWSTAUNER>
234            
235             =item *
236            
237             L<Dist::Zilla::Role::PluginBundle::Easy>
238            
239             =back
240            
241             =head1 AUTHOR
242            
243             Randy Stauner <rwstauner@cpan.org>
244            
245             =head1 COPYRIGHT AND LICENSE
246            
247             This software is copyright (c) 2010 by Randy Stauner.
248            
249             This is free software; you can redistribute it and/or modify it under
250             the same terms as the Perl 5 programming language system itself.
251            
252             =cut
253              
254             __DATA__
255             __[ .gitignore ]__
256             /{{$dist->name}}*
257             /.build
258             /cover_db/
259             /nytprof*
260             /tags
261             __[ dist.ini ]__
262             {{
263             $license = ref $dist->license;
264             if ( $license =~ /^Software::License::(.+)$/ ) {
265             $license = $1;
266             } else {
267             $license = "=$license";
268             }
269            
270             $authors = join( "\n", map { "author = $_" } @{ $dist->authors } );
271             $copyright_year = (localtime)[5] + 1900;
272             '';
273             }}name = {{ $dist->name }}
274             {{ $authors }}
275             license = {{ $license }}
276             copyright_holder = {{ join( ', ', map { (/^(.+) <.+>/)[0] }@{ $dist->authors } ) }}
277             copyright_year = {{ $copyright_year }}
278            
279             [@Author::RWSTAUNER]
280             __[ Changes ]__
281             Revision history for {{$dist->name}}
282            
283             {{ '{{$NEXT}}' }}
284            
285             - Initial release
286             __[ LICENSE ]__
287            
288             This is free software; you can redistribute it and/or modify it under
289             the same terms as the Perl 5 programming language system itself.
290            
291             __[ README.mkdn ]__
292             # NAME
293            
294             {{ (my $n = $dist->name) =~ s/-/::/g; $n }} - undef
295            
296             # COPYRIGHT AND LICENSE
297            
298             This software is copyright (c) {{ (localtime)[5]+1900 }} by {{ $dist->copyright_holder }}.
299            
300             This is free software; you can redistribute it and/or modify it under
301             the same terms as the Perl 5 programming language system itself.
302