| 1 |
#!/usr/bin/env perl |
|---|
| 2 |
use strict; |
|---|
| 3 |
use warnings; |
|---|
| 4 |
use ExtUtils::MakeMaker qw(prompt); |
|---|
| 5 |
use File::Basename; |
|---|
| 6 |
use File::Path; |
|---|
| 7 |
use File::Spec; |
|---|
| 8 |
use Template; |
|---|
| 9 |
use YAML; |
|---|
| 10 |
|
|---|
| 11 |
my $path = File::Spec->catfile($ENV{HOME}, "/.pmsetuprc"); |
|---|
| 12 |
my $config = eval { YAML::LoadFile($path) } || {}; |
|---|
| 13 |
|
|---|
| 14 |
my $save; |
|---|
| 15 |
while (! $config->{author}) { |
|---|
| 16 |
$config->{author} = prompt("Your name: ", ''); |
|---|
| 17 |
$save++; |
|---|
| 18 |
} |
|---|
| 19 |
|
|---|
| 20 |
while (! $config->{email}) { |
|---|
| 21 |
$config->{email} = prompt("Your email: ", ''); |
|---|
| 22 |
$save++; |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
my $modname = shift @ARGV or die "Usage: $0 module\n"; |
|---|
| 26 |
$modname =~ s/-/::/g; |
|---|
| 27 |
|
|---|
| 28 |
write_plugin_files($modname, $config); |
|---|
| 29 |
|
|---|
| 30 |
END { |
|---|
| 31 |
YAML::DumpFile($path, $config) if $save; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
sub write_plugin_files { |
|---|
| 35 |
my($module, $config) = @_; |
|---|
| 36 |
|
|---|
| 37 |
# $module = "Foo::Bar" |
|---|
| 38 |
# $dist = "Foo-Bar" |
|---|
| 39 |
# $path = "Foo/Bar.pm" |
|---|
| 40 |
my @pkg = split /::/, $module; |
|---|
| 41 |
my $dist = join "-", @pkg; |
|---|
| 42 |
my $path = join("/", @pkg) . ".pm"; |
|---|
| 43 |
|
|---|
| 44 |
mkdir $dist, 0777; |
|---|
| 45 |
chdir $dist; |
|---|
| 46 |
|
|---|
| 47 |
my @template = YAML::Load(join '', <DATA>); |
|---|
| 48 |
my $vars = { module => $module, dist => $dist, path => $path, |
|---|
| 49 |
config => $config, localtime => scalar localtime, year => (localtime)[5] + 1900 }; |
|---|
| 50 |
|
|---|
| 51 |
for my $tmpl (@template) { |
|---|
| 52 |
my $file = $tmpl->{file}; |
|---|
| 53 |
$file =~ s/(\$\w+)/$1/eeg; |
|---|
| 54 |
write_file($file, $tmpl->{template}, $vars); |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
!system "perl Makefile.PL NO_MYMETA=1" or die $?; |
|---|
| 58 |
!system 'make manifest' or die $?; |
|---|
| 59 |
!system 'make test' or die $?; |
|---|
| 60 |
!system 'make distclean' or die $?; |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
sub write_file { |
|---|
| 64 |
my($path, $template, $vars) = @_; |
|---|
| 65 |
|
|---|
| 66 |
if (-e $path) { |
|---|
| 67 |
my $ans = prompt("$path exists. Override? [yN] ", 'n'); |
|---|
| 68 |
return if $ans !~ /[Yy]/; |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
my $dir = File::Basename::dirname($path); |
|---|
| 72 |
unless (-e $dir) { |
|---|
| 73 |
warn "Creating directory $dir\n"; |
|---|
| 74 |
File::Path::mkpath($dir, 1, 0777); |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
my $tt = Template->new; |
|---|
| 78 |
$tt->process(\$template, $vars, \my $content); |
|---|
| 79 |
|
|---|
| 80 |
warn "Creating $path\n"; |
|---|
| 81 |
open my $out, ">", $path or die "$path: $!"; |
|---|
| 82 |
print $out $content; |
|---|
| 83 |
close $out; |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
__DATA__ |
|---|
| 87 |
--- |
|---|
| 88 |
file: Makefile.PL |
|---|
| 89 |
template: | |
|---|
| 90 |
use inc::Module::Install; |
|---|
| 91 |
all_from 'lib/[% path %]'; |
|---|
| 92 |
readme_from('lib/[% path %]'); |
|---|
| 93 |
build_requires 'Test::More', 0.88; |
|---|
| 94 |
test_requires 'Test::Requires'; |
|---|
| 95 |
auto_set_repository(); |
|---|
| 96 |
auto_provides; |
|---|
| 97 |
WriteAll; |
|---|
| 98 |
|
|---|
| 99 |
--- |
|---|
| 100 |
file: t/00_compile.t |
|---|
| 101 |
template: | |
|---|
| 102 |
use strict; |
|---|
| 103 |
use Test::More tests => 1; |
|---|
| 104 |
|
|---|
| 105 |
BEGIN { use_ok '[% module %]' } |
|---|
| 106 |
--- |
|---|
| 107 |
file: xt/pod.t |
|---|
| 108 |
template: | |
|---|
| 109 |
use Test::More; |
|---|
| 110 |
eval "use Test::Pod 1.00"; |
|---|
| 111 |
plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; |
|---|
| 112 |
all_pod_files_ok(); |
|---|
| 113 |
--- |
|---|
| 114 |
file: Changes |
|---|
| 115 |
template: | |
|---|
| 116 |
Revision history for Perl extension [% module %] |
|---|
| 117 |
|
|---|
| 118 |
0.01 [% localtime %] |
|---|
| 119 |
- original version |
|---|
| 120 |
--- |
|---|
| 121 |
file: lib/$path |
|---|
| 122 |
template: | |
|---|
| 123 |
package [% module %]; |
|---|
| 124 |
|
|---|
| 125 |
use strict; |
|---|
| 126 |
use 5.008_001; |
|---|
| 127 |
our $VERSION = '0.01'; |
|---|
| 128 |
|
|---|
| 129 |
1; |
|---|
| 130 |
__END__ |
|---|
| 131 |
|
|---|
| 132 |
=encoding utf-8 |
|---|
| 133 |
|
|---|
| 134 |
=for stopwords |
|---|
| 135 |
|
|---|
| 136 |
=head1 NAME |
|---|
| 137 |
|
|---|
| 138 |
[% module %] - |
|---|
| 139 |
|
|---|
| 140 |
=head1 SYNOPSIS |
|---|
| 141 |
|
|---|
| 142 |
use [% module %]; |
|---|
| 143 |
|
|---|
| 144 |
=head1 DESCRIPTION |
|---|
| 145 |
|
|---|
| 146 |
[% module %] is |
|---|
| 147 |
|
|---|
| 148 |
=head1 AUTHOR |
|---|
| 149 |
|
|---|
| 150 |
[% config.author %] E<lt>[% config.email %]E<gt> |
|---|
| 151 |
|
|---|
| 152 |
=head1 COPYRIGHT |
|---|
| 153 |
|
|---|
| 154 |
Copyright [% year %]- [% config.author %] |
|---|
| 155 |
|
|---|
| 156 |
=head1 LICENSE |
|---|
| 157 |
|
|---|
| 158 |
This library is free software; you can redistribute it and/or modify |
|---|
| 159 |
it under the same terms as Perl itself. |
|---|
| 160 |
|
|---|
| 161 |
=head1 SEE ALSO |
|---|
| 162 |
|
|---|
| 163 |
=cut |
|---|
| 164 |
--- |
|---|
| 165 |
file: MANIFEST.SKIP |
|---|
| 166 |
template: | |
|---|
| 167 |
\bRCS\b |
|---|
| 168 |
\bCVS\b |
|---|
| 169 |
\.svn/ |
|---|
| 170 |
\.git/ |
|---|
| 171 |
^MANIFEST\. |
|---|
| 172 |
^Makefile$ |
|---|
| 173 |
~$ |
|---|
| 174 |
\.old$ |
|---|
| 175 |
^blib/ |
|---|
| 176 |
^pm_to_blib |
|---|
| 177 |
^MakeMaker-\d |
|---|
| 178 |
\.gz$ |
|---|
| 179 |
\.cvsignore |
|---|
| 180 |
\.shipit |
|---|
| 181 |
MYMETA |
|---|
| 182 |
--- |
|---|
| 183 |
file: README |
|---|
| 184 |
template: | |
|---|
| 185 |
This is Perl module [% module %]. |
|---|
| 186 |
|
|---|
| 187 |
INSTALLATION |
|---|
| 188 |
|
|---|
| 189 |
[% module %] installation is straightforward. If your CPAN shell is set up, |
|---|
| 190 |
you should just be able to do |
|---|
| 191 |
|
|---|
| 192 |
% cpan [% module %] |
|---|
| 193 |
|
|---|
| 194 |
Download it, unpack it, then build it as per the usual: |
|---|
| 195 |
|
|---|
| 196 |
% perl Makefile.PL |
|---|
| 197 |
% make && make test |
|---|
| 198 |
|
|---|
| 199 |
Then install it: |
|---|
| 200 |
|
|---|
| 201 |
% make install |
|---|
| 202 |
|
|---|
| 203 |
DOCUMENTATION |
|---|
| 204 |
|
|---|
| 205 |
[% module %] documentation is available as in POD. So you can do: |
|---|
| 206 |
|
|---|
| 207 |
% perldoc [% module %] |
|---|
| 208 |
|
|---|
| 209 |
to read the documentation online with your favorite pager. |
|---|
| 210 |
|
|---|
| 211 |
[% config.author %] |
|---|
| 212 |
--- |
|---|
| 213 |
file: .shipit |
|---|
| 214 |
template: | |
|---|
| 215 |
steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN |
|---|
| 216 |
git.push_to = origin |
|---|
| 217 |
--- |
|---|
| 218 |
file: .gitignore |
|---|
| 219 |
template: | |
|---|
| 220 |
MYMETA.* |
|---|
| 221 |
META.yml |
|---|
| 222 |
Makefile |
|---|
| 223 |
inc/ |
|---|
| 224 |
pm_to_blib |
|---|
| 225 |
*~ |
|---|