root/lang/perl/Okina/trunk/okina-starter @ 10457

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