root/misc/pmsetup

Revision 1922 (checked in by miyagawa, 14 years ago)

remove bracket

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use ExtUtils::MakeMaker qw(prompt);
5 use FileHandle;
6 use File::Copy;
7 use File::Path;
8 use File::Spec;
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 my @pkg = split /::/, $modname;
27
28 mkdir_chdir(@pkg);
29 mk_makefile_pl($modname, @pkg);
30 my $libdir = mk_libdir_t_dir(@pkg);
31 mk_test_suite($modname);
32 mk_changes($modname);
33 mk_module_template($libdir, $modname, @pkg);
34 mk_readme($modname);
35 mk_manifest();
36 prepare_make();
37
38 END {
39     YAML::DumpFile($path, $config) if $save;
40 }
41
42 sub mkdir_chdir {
43     my @pkg = @_;
44     # mkdir Foo-Bar
45     my $moddir = join('-', @pkg);
46     mkdir $moddir, 0777;
47     chdir $moddir;
48 }
49
50 sub mk_makefile_pl {
51     my($modname, @pkg) = @_;
52
53     # Makefile.PL
54     my $dist = join('-', @pkg);
55     my $path = join('/', @pkg). '.pm';
56     my $mk = FileHandle->new('>Makefile.PL') or die $!;
57     $mk->print(<<MK);
58 use inc::Module::Install;
59 name '$dist';
60 all_from 'lib/$path';
61
62 build_requires 'Test::More';
63 auto_include;
64 WriteAll;
65 MK
66 }
67
68 sub mk_libdir_t_dir {
69     my @pkg = @_;
70
71     # lib/Foo/ & t/
72     my $libdir = 'lib/' . join '/', @pkg[0..$#pkg-1];
73     mkpath([ $libdir, 't' ], 1, 0777);
74     return $libdir;
75 }
76
77 sub mk_test_suite {
78     my $modname = shift;
79
80     # test suite
81     my $test = FileHandle->new(">t/00_compile.t") or die $!;
82     $test->print(<<TEST);
83 use strict;
84 use Test::More tests => 1;
85
86 BEGIN { use_ok '$modname' }
87 TEST
88     ;
89
90     $test = FileHandle->new(">t/99_pod.t") or die $!;
91     $test->print(<<'TEST');
92 use Test::More;
93 eval "use Test::Pod 1.00";
94 plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
95 all_pod_files_ok();
96 TEST
97     ;
98 }
99
100 sub mk_changes {
101     my $modname = shift;
102
103     my $localtime = localtime;
104     my $changes = FileHandle->new("> Changes") or die $!;
105     $changes->print(<<CHANGES);
106 Revision history for Perl extension $modname
107
108 0.01  $localtime
109         - original version
110 CHANGES
111     ;
112 }
113
114 sub mk_module_template {
115     my($libdir, $modname, @pkg) = @_;
116     my $module = FileHandle->new(">$libdir/$pkg[$#pkg].pm") or die $!;
117     $module->print(<<MODULE);
118 package $modname;
119
120 use strict;
121 use 5.8.0;
122 our \$VERSION = '0.01';
123
124 1;
125 __END__
126
127 =head1 NAME
128
129 $modname -
130
131 =head1 SYNOPSIS
132
133   use $modname;
134
135 =head1 DESCRIPTION
136
137 $modname is
138
139 =head1 AUTHOR
140
141 $config->{author} E<lt>$config->{email}E<gt>
142
143 =head1 LICENSE
144
145 This library is free software; you can redistribute it and/or modify
146 it under the same terms as Perl itself.
147
148 =head1 SEE ALSO
149
150 =cut
151 MODULE
152     ;
153 }
154
155 sub mk_manifest {
156     my $mani = FileHandle->new(">MANIFEST.SKIP") or die $!;
157     $mani->print(<<'MANI');
158 \bRCS\b
159 \bCVS\b
160 ^MANIFEST\.
161 ^Makefile$
162 ~$
163 \.old$
164 ^blib/
165 ^pm_to_blib
166 ^MakeMaker-\d
167 \.gz$
168 \.cvsignore
169 MANI
170     ;
171 }
172
173 sub mk_readme {
174     my $mod  = shift;
175     my $file = FileHandle->new(">README") or die $!;
176     $file->print(<<EOF);
177 This is Perl module $mod.
178
179 INSTALLATION
180
181 $mod installation is straightforward. If your CPAN shell is set up,
182 you should just be able to do
183
184     % cpan $mod
185
186 Download it, unpack it, then build it as per the usual:
187
188     % perl Makefile.PL
189     % make && make test
190
191 Then install it:
192
193     % make install
194
195 DOCUMENTATION
196
197 $mod documentation is available as in POD. So you can do:
198
199     % perldoc $mod
200
201 to read the documentation online with your favorite pager.
202
203 $config->{author}
204 EOF
205 }
206
207 sub prepare_make {
208     !system "perl Makefile.PL" or die $?;
209     !system 'make test' or die $?;
210     !system 'make manifest' or die $?;
211     !system 'make distclean' or die $?;
212 }
Note: See TracBrowser for help on using the browser.