| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use ExtUtils::MakeMaker qw(prompt); |
|---|
| 6 | use File::Basename; |
|---|
| 7 | use File::Path; |
|---|
| 8 | use File::Spec; |
|---|
| 9 | use Template; |
|---|
| 10 | use YAML; |
|---|
| 11 | use Config::Pit; |
|---|
| 12 | |
|---|
| 13 | my $config = pit_get( |
|---|
| 14 | 'pmsetup', |
|---|
| 15 | require => { |
|---|
| 16 | author => 'Tokuhiro Matsuno', |
|---|
| 17 | email => 'tokuhirom AAJKLFJEF GMAIL COM', |
|---|
| 18 | } |
|---|
| 19 | ); |
|---|
| 20 | |
|---|
| 21 | my $modname = shift @ARGV or die "Usage: $0 module\n"; |
|---|
| 22 | $modname =~ s/-/::/g; |
|---|
| 23 | |
|---|
| 24 | write_plugin_files($modname, $config); |
|---|
| 25 | |
|---|
| 26 | sub 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 | |
|---|
| 65 | sub 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 | |
|---|
| 90 | original L<http://svn.bulknews.net/repos/public/misc/pmsetup> |
|---|
| 91 | |
|---|
| 92 | =cut |
|---|
| 93 | |
|---|
| 94 | __DATA__ |
|---|
| 95 | --- |
|---|
| 96 | file: Makefile.PL |
|---|
| 97 | template: | |
|---|
| 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 | --- |
|---|
| 111 | file: t/00_compile.t |
|---|
| 112 | template: | |
|---|
| 113 | use strict; |
|---|
| 114 | use Test::More tests => 1; |
|---|
| 115 | |
|---|
| 116 | BEGIN { use_ok '[% module %]' } |
|---|
| 117 | --- |
|---|
| 118 | file: t/97_podspell.t |
|---|
| 119 | template: | |
|---|
| 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 | --- |
|---|
| 136 | file: t/98_perlcritic.t |
|---|
| 137 | template: | |
|---|
| 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 | --- |
|---|
| 144 | file: t/99_pod.t |
|---|
| 145 | template: | |
|---|
| 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 | --- |
|---|
| 151 | file: t/perlcriticrc |
|---|
| 152 | template: | |
|---|
| 153 | [TestingAndDebugging::ProhibitNoStrict] |
|---|
| 154 | allow=refs |
|---|
| 155 | --- |
|---|
| 156 | file: script/$dist-server.pl |
|---|
| 157 | template: | |
|---|
| 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 => \&_handle_request, |
|---|
| 169 | )->run; |
|---|
| 170 | |
|---|
| 171 | sub _handle_request { |
|---|
| 172 | my $c = shift; |
|---|
| 173 | [% module %]->handle_request( $c ); |
|---|
| 174 | } |
|---|
| 175 | --- |
|---|
| 176 | file: lib/$path |
|---|
| 177 | template: | |
|---|
| 178 | package [% module %]; |
|---|
| 179 | use strict; |
|---|
| 180 | use warnings; |
|---|
| 181 | use 5.00800; |
|---|
| 182 | our $VERSION = '0.01'; |
|---|
| 183 | use UNIVERSAL::require; |
|---|
| 184 | use [% module %]::Dispatcher; |
|---|
| 185 | use [% module %]::Config; |
|---|
| 186 | use Okina; |
|---|
| 187 | |
|---|
| 188 | 1; |
|---|
| 189 | --- |
|---|
| 190 | file: lib/$dist/Dispatcher.pm |
|---|
| 191 | template: | |
|---|
| 192 | package [% module %]::Dispatcher; |
|---|
| 193 | use strict; |
|---|
| 194 | use warnings; |
|---|
| 195 | use HTTPx::Dispatcher; |
|---|
| 196 | |
|---|
| 197 | connect '' => { controller => 'Root', action => 'index' }; |
|---|
| 198 | |
|---|
| 199 | 1; |
|---|
| 200 | --- |
|---|
| 201 | file: lib/$dist/Config.pm |
|---|
| 202 | template: | |
|---|
| 203 | package [% module %]::Config; |
|---|
| 204 | use strict; |
|---|
| 205 | use warnings; |
|---|
| 206 | use Okina::Config; |
|---|
| 207 | |
|---|
| 208 | 1; |
|---|
| 209 | --- |
|---|
| 210 | file: lib/$dist/C/Root.pm |
|---|
| 211 | template: | |
|---|
| 212 | package [% module %]::C::Root; |
|---|
| 213 | use strict; |
|---|
| 214 | use warnings; |
|---|
| 215 | use Okina::Controller; |
|---|
| 216 | |
|---|
| 217 | sub index :Private { |
|---|
| 218 | my $c = shift; |
|---|
| 219 | $c->res->body('Okina!'); |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | 1; |
|---|
| 223 | --- |
|---|
| 224 | file: MANIFEST.SKIP |
|---|
| 225 | template: | |
|---|
| 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 | --- |
|---|
| 247 | file: README |
|---|
| 248 | template: | |
|---|
| 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 | --- |
|---|
| 277 | file: .shipit |
|---|
| 278 | chmod: 0644 |
|---|
| 279 | coderepos: 0 |
|---|
| 280 | template: | |
|---|
| 281 | steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN |
|---|
| 282 | svk.tagpattern = release-%v |
|---|
| 283 | --- |
|---|
| 284 | file: .shipit |
|---|
| 285 | chmod: 0644 |
|---|
| 286 | coderepos: 1 |
|---|
| 287 | template: | |
|---|
| 288 | steps = CommitMessageWrap, FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN |
|---|
| 289 | svk.tagpattern = release-%v |
|---|
| 290 | commit_message.format = lang/perl/[% dist %]: %msg |
|---|
| 291 | --- |
|---|
| 292 | file: config.yaml |
|---|
| 293 | template: | |
|---|
| 294 | --- |
|---|
| 295 | engine: |
|---|
| 296 | plugins: |
|---|
| 297 | - module: Interface::Standalone |
|---|
| 298 | conf: |
|---|
| 299 | host: 0.0.0.0 |
|---|
| 300 | port: 14000 |
|---|
| 301 | |
|---|