ghetto project init
[p5sagit/Distar.git] / bin / distar-init
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings FATAL => 'all';
5 use File::Path qw(mkpath);
6
7 my $project = $ARGV[0] or die "No project name passed";
8
9 my @parts = split('-', $project);
10
11 my $lib_file = join('/', 'lib', @parts).".pm";
12
13 my $author = $ENV{DISTAR_INIT_AUTHOR} or die "DISTAR_INIT_AUTHOR unset";
14
15 mkpath "${project}/maint";
16
17 mkpath join('/', $project, 'lib', @parts[0..$#parts-1]);
18
19 open my $mpl_main, '>', "${project}/Makefile.PL"
20   or die "couldn't open Makefile.PL: $!";
21
22 print $mpl_main sprintf(<<'END', $project, $lib_file);
23 use strict;
24 use warnings FATAL => 'all';
25 use ExtUtils::MakeMaker;
26
27 (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
28
29 WriteMakefile(
30   NAME => '%s',
31   VERSION_FROM => '%s'
32 );
33 END
34
35 close($mpl_main);
36
37 open my $mpl_maint, '>', "${project}/maint/Makefile.PL.include"
38   or die "couldn't open maint/Makefile.PL.include: $!";
39
40 print $mpl_maint sprintf(<<'END', $author);
41 BEGIN {
42   -e 'Distar'
43     or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git")
44 }
45 use lib 'Distar/lib';
46 use Distar;
47
48 author '%s';
49 END
50
51 close($mpl_maint);
52
53 open my $pm, '>', "${project}/${lib_file}"
54   or die "Couldn't open .pm file: $!";
55
56 my $package_name = join('::', @parts);
57
58 my $year = 1900+(localtime)[5];
59
60 my $mod_text = sprintf(<<'END', $package_name, $package_name, $author, $year, $package_name);
61  package %s;
62
63  our $VERSION = '0.000001'; # 0.0.1
64
65  $VERSION = eval $VERSION;
66
67  1;
68
69  =head1 NAME
70
71  %s - Description goes here
72
73  =head1 SYNOPSIS
74
75  =head1 DESCRIPTION
76
77  =head1 AUTHOR
78
79   %s
80
81  =head1 CONTRIBUTORS
82
83  None yet - maybe this software is perfect! (ahahahahahahahahaha)
84
85  =head1 COPYRIGHT
86
87  Copyright (c) %s the %s L</AUTHOR> and L</CONTRIBUTORS>
88  as listed above.
89  
90  =head1 LICENSE
91  
92  This library is free software and may be distributed under the same terms
93  as perl itself.
94 END
95
96 $mod_text =~ s/^ //mg;
97
98 print $pm $mod_text;
99
100 close $mod_text;
101
102 chdir($project); system("git init");