root/lang/perl/misc/pmsetup/tokuhirom-pmsetup @ 10679

Revision 10679, 5.7 kB (checked in by tokuhirom, 5 years ago)

スペルチェッカにひっかかるたびに人名登録するのに疲れた。

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use ExtUtils::MakeMaker qw(prompt);
6use File::Basename;
7use File::Path;
8use File::Spec;
9use Template;
10use YAML;
11use Config::Pit;
12
13my $config = pit_get(
14    'pmsetup',
15    require => {
16        author        => 'Tokuhiro Matsuno',
17        email         => 'tokuhirom AAJKLFJEF GMAIL COM',
18        scratch_repos => '//scratch/',
19    }
20);
21
22my $modname = shift @ARGV or die "Usage: $0 module\n";
23   $modname =~ s/-/::/g;
24
25write_plugin_files($modname, $config);
26
27sub write_plugin_files {
28    my($module, $config) = @_;
29
30    my $coderepos = prompt("CodeRepos friendly? [Yn] ", 'y');
31
32    # $module = "Foo::Bar"
33    # $dist   = "Foo-Bar"
34    # $path   = "Foo/Bar.pm"
35    my @pkg  = split /::/, $module;
36    my $dist = join "-", @pkg;
37    my $path = join("/", @pkg) . ".pm";
38
39    mkdir $dist, 0777;
40    chdir $dist;
41    mkdir $_, 0777 for (qw/ trunk tags branches /);
42    chdir 'trunk';
43
44    my @template = YAML::Load(join '', <DATA>);
45    my $vars = { module => $module, dist => $dist, path => $path,
46                 config => $config, localtime => scalar localtime };
47
48    for my $tmpl (@template) {
49        my $file = $tmpl->{file};
50           $file =~ s/(\$\w+)/$1/eeg;
51        if (defined $tmpl->{coderepos}) {
52            if ($coderepos =~ /[Yy]/) {
53                next unless $tmpl->{coderepos};
54            } else {
55                next if $tmpl->{coderepos};
56            }
57        }
58        write_file($file, $tmpl->{template}, $vars);
59        chmod oct($tmpl->{chmod}), $tmpl->{file} if $tmpl->{chmod};
60    }
61
62    !system "perl Makefile.PL" or die $?;
63    !system 'make test' or die $?;
64    !system 'make manifest' or die $?;
65    !system 'make distclean' or die $?;
66
67    # import to svk
68    chdir '..';
69    !system("svk import -m '$dist import' $config->{scratch_repos}/$dist") or die $?;
70    chdir '..';
71    rmtree("$dist");
72    system("svk co $config->{scratch_repos}/$dist/trunk $dist");
73}
74
75sub write_file {
76    my($path, $template, $vars) = @_;
77
78    if (-e $path) {
79        my $ans = prompt("$path exists. Override? [yN] ", 'n');
80        return if $ans !~ /[Yy]/;
81    }
82
83    my $dir = File::Basename::dirname($path);
84    unless (-e $dir) {
85        warn "Creating directory $dir\n";
86        File::Path::mkpath($dir, 1, 0777);
87    }
88
89    my $tt = Template->new;
90    $tt->process(\$template, $vars, \my $content);
91
92    warn "Creating $path\n";
93    open my $out, ">", $path or die "$path: $!";
94    print $out $content;
95    close $out;
96}
97
98=pod
99
100original L<http://svn.bulknews.net/repos/public/misc/pmsetup>
101
102=cut
103
104__DATA__
105---
106file: Makefile.PL
107template: |
108  use inc::Module::Install;
109  name '[% dist %]';
110  all_from 'lib/[% path %]';
111
112  # requires '';
113
114  build_requires 'Test::More';
115  build_requires 'YAML';
116  use_test_base;
117  auto_include;
118  WriteAll;
119---
120file: t/00_compile.t
121template: |
122  use strict;
123  use Test::More tests => 1;
124
125  BEGIN { use_ok '[% module %]' }
126---
127file: t/97_podspell.t
128template: |
129  use Test::More;
130  eval q{ use Test::Spelling };
131  plan skip_all => "Test::Spelling is not installed." if $@;
132  add_stopwords(map { split /[\s\:\-]/ } <DATA>);
133  $ENV{LANG} = 'C';
134  all_pod_files_spelling_ok('lib');
135  __DATA__
136  [% config.author %]
137  [% module %]
138  tokuhirom
139  AAJKLFJEF
140  GMAIL
141  COM
142  Tatsuhiko
143  Miyagawa
144  Kazuhiro
145  Osawa
146  lestrrat
147  typester
148  cho45
149  charsbar
150  coji
151  clouder
152  gunyarakun
153  hio_d
154  hirose31
155  ikebe
156  kan
157  kazeburo
158---
159file: t/98_perlcritic.t
160template: |
161  use strict;
162  use Test::More;
163  eval { use Test::Perl::Critic -profile => 't/perlcriticrc' };
164  plan skip_all => "Test::Perl::Critic is not installed." if $@;
165  all_critic_ok('lib');
166---
167file: t/99_pod.t
168template: |
169  use Test::More;
170  eval "use Test::Pod 1.00";
171  plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
172  all_pod_files_ok();
173---
174file: t/perlcriticrc
175template: |
176  [TestingAndDebugging::ProhibitNoStrict]
177  allow=refs
178---
179file: Changes
180template: |
181  Revision history for Perl extension [% module %]
182
183  0.01    [% localtime %]
184          - original version
185---
186file: lib/$path
187template: |
188  package [% module %];
189  use strict;
190  use warnings;
191  use 5.00800;
192  our $VERSION = '0.01';
193
194  1;
195  __END__
196
197  =encoding utf8
198
199  =head1 NAME
200
201  [% module %] -
202
203  =head1 SYNOPSIS
204
205    use [% module %];
206
207  =head1 DESCRIPTION
208
209  [% module %] is
210
211  =head1 AUTHOR
212
213  [% config.author %] E<lt>[% config.email %]E<gt>
214
215  =head1 SEE ALSO
216
217  =head1 LICENSE
218
219  This library is free software; you can redistribute it and/or modify
220  it under the same terms as Perl itself.
221
222  =cut
223---
224file: MANIFEST.SKIP
225template: |
226  \bRCS\b
227  \bCVS\b
228  ^MANIFEST\.
229  ^Makefile$
230  ~$
231  ^#
232  \.old$
233  ^blib/
234  ^pm_to_blib
235  ^MakeMaker-\d
236  \.gz$
237  \.cvsignore
238  ^t/9\d_.*\.t
239  ^t/perlcritic
240  ^tools/
241  \.svn/
242  ^[^/]+\.yaml$
243  ^[^/]+\.pl$
244  ^\.shipit$
245  \.sw[po]$
246---
247file: README
248template: |
249  This is Perl module [% module %].
250
251  INSTALLATION
252
253  [% module %] installation is straightforward. If your CPAN shell is set up,
254  you should just be able to do
255
256      % cpan [% module %]
257
258  Download it, unpack it, then build it as per the usual:
259
260      % perl Makefile.PL
261      % make && make test
262
263  Then install it:
264
265      % make install
266
267  DOCUMENTATION
268
269  [% module %] documentation is available as in POD. So you can do:
270
271      % perldoc [% module %]
272
273  to read the documentation online with your favorite pager.
274
275  [% config.author %]
276---
277file: .shipit
278chmod: 0644
279coderepos: 0
280template: |
281  steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
282  svk.tagpattern = release-%v
283---
284file: .shipit
285chmod: 0644
286coderepos: 1
287template: |
288  steps = CommitMessageWrap, FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN
289  svk.tagpattern = release-%v
290  commit_message.format = lang/perl/[% dist %]: %msg
Note: See TracBrowser for help on using the browser.