-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTx.pm
208 lines (145 loc) · 4.38 KB
/
RTx.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
use strict;
use warnings;
package Module::Starter::Plugin::RTx;
use base 'Module::Starter::Simple';
use Carp;
our $VERSION = '0.03';
sub create_MI_RTx_Makefile_PL {
my $self = shift;
my $main_module = shift || $self->{main_module};
my $fname = File::Spec->catfile( $self->{basedir}, 'Makefile.PL' );
$self->{main_module_file} = join( '/', 'lib', split /::/, $main_module ) . '.pm';
$self->create_file(
$fname,
<<EOF
use inc::Module::Install;
RTx('$self->{distro}');
all_from('$self->{main_module_file}');
&WriteAll;
EOF
);
$self->progress("Created $fname");
return 'Makefile.PL';
}
sub create_build {
my $self = shift;
# get the builders
my @builders = @{ $self->get_builders };
my $builder_set = Module::Starter::BuilderSet->new();
# Remove mutually exclusive and unsupported builders
@builders = $builder_set->check_compatibility(@builders);
# compile some build instructions, create a list of files generated
# by the builders' create_* methods, and call said methods
return (
files => [ $self->create_MI_RTx_Makefile_PL ],
instructions => join( "\n\n", $self->build_instructions ),
manifest_method => 'create_MI_MANIFEST',
);
}
sub build_instructions {
my $self = shift;
my $module = shift || $self->{main_module};
my @out;
push @out, 'To install this module, run the following commands:';
my @commands = (
'perl Makefile.PL',
'make',
'make install',
"make initdb # only if there is etc/initialdata and it hasn't been run before",
);
push @out, join( "\n", map { " $_" } @commands );
push @out,
"add $module to \@Plugins in RT's etc/RT_SiteConfig.pm:",
" Set( \@Plugins, qw(... $module) );";
return @out;
}
sub create_distro {
my $either = shift;
( ref $either ) or $either = $either->new(@_);
my $self = $either;
my $modules = $self->{modules} || [];
my @modules = map { split /,/ } @{$modules};
croak "No modules specified.\n" unless @modules;
for (@modules) {
croak "Invalid module name: $_" unless /\A[a-z_]\w*(?:::[\w]+)*\Z/i;
}
croak "Must specify an author\n" unless $self->{author};
croak "Must specify an email address\n" unless $self->{email};
( $self->{email_obfuscated} = $self->{email} ) =~ s/@/ at /;
$self->{license} ||= 'perl';
$self->{ignores_type} ||= 'generic';
$self->{main_module} = $modules[0];
if ( not $self->{distro} ) {
$self->{distro} = $self->{main_module};
$self->{distro} =~ s/::/-/g;
}
$self->{basedir} = $self->{dir} || $self->{distro};
$self->create_basedir;
$self->create_modules(@modules);
$self->create_ignores;
my %build_results = $self->create_build();
$self->create_Changes;
$self->create_README;
$self->create_MANIFEST( $build_results{'manifest_method'} );
return;
}
sub create_README {
my $self = shift;
chdir $self->{basedir};
symlink( $self->{main_module_file}, 'README.pod' );
chdir '..';
}
sub _module_header {
my $self = shift;
my $module = shift;
my $rtname = shift;
my $content = <<EOF;
use warnings;
use strict;
package $module;
our \$VERSION = "0.01";
EOF
return $content;
}
sub module_guts {
my $self = shift;
my $module = shift;
my $rtname = shift;
# Sub-templates
my $header = $self->_module_header( $module, $rtname );
my $install = join "\n\n", $self->build_instructions;
my $license = $self->_module_license( $module, $rtname );
my $content = <<"HERE";
$header
1;
__END__
\=head1 NAME
$module - The great new $module!
\=head1 VERSION
Version 0.01
\=head1 INSTALLATION
$install
\=head1 AUTHOR
$self->{author}, <$self->{email_obfuscated}>
$license
HERE
return $content;
}
1;
__END__
=head1 NAME
Module::Starter::Plugin::RTx - Module::Starter for RT extensions
=head1 SYNOPSIS
use Module::Starter 'Module::Starter::Plugin::RTx';
Module::Starter->create_distro(%args);
=head1 DESCRIPTION
This is a plugin for Module::Starter that builds you a skeleton
RTx module.
=head1 SEE ALSO
L<Module::Starter>
=head1 AUTHOR
sunnavy <[email protected]>
=head1 LICENCE AND COPYRIGHT
Copyright 2011 [email protected]
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.