1 package Module::Install::Catalyst;
6 require Module::Install::Base;
7 @ISA = qw/Module::Install::Base/;
11 use File::Copy::Recursive 'rcopy';
13 use Getopt::Long qw(GetOptionsFromString :config no_ignore_case);
19 qw/Build Build.PL Changes MANIFEST META.yml Makefile.PL Makefile README
20 _build blib lib script t inc .*\.svn \.git _darcs \.bzr \.hg
21 debian build-stamp install-stamp configure-stamp/;
30 Module::Install::Catalyst - Module::Install extension for Catalyst
34 use inc::Module::Install;
37 all_from 'lib/MyApp.pm';
39 requires 'Catalyst::Runtime' => '5.7014';
41 catalyst_ignore('.*temp');
42 catalyst_ignore('.*tmp');
48 L<Module::Install> extension for Catalyst.
54 Calls L<catalyst_files> and L<catalyst_par>. Should be the last catalyst*
55 command called in C<Makefile.PL>.
62 *** Module::Install::Catalyst
64 $self->catalyst_files;
67 *** Module::Install::Catalyst finished.
73 Collect a list of all files a Catalyst application consists of and copy it
74 inside the blib/lib/ directory. Files and directories that match the modules
75 ignore list are excluded (see L<catalyst_ignore> and L<catalyst_ignore_all>).
86 CATFILES: for my $name ( readdir CATDIR ) {
87 for my $ignore (@IGNORE) {
88 next CATFILES if $name =~ /^$ignore$/;
89 next CATFILES if $name !~ /\w/;
94 my @path = split '-', $self->name;
95 for my $orig (@files) {
96 my $path = File::Spec->catdir( 'blib', 'lib', @path, $orig );
97 rcopy( $orig, $path );
101 =head2 catalyst_ignore_all(\@ignore)
103 This function replaces the built-in default ignore list with the given list.
107 sub catalyst_ignore_all {
108 my ( $self, $ignore ) = @_;
112 =head2 catalyst_ignore(\@ignore)
114 Add a regexp to the list of ignored patterns. Can be called multiple times.
118 sub catalyst_ignore {
119 my ( $self, @ignore ) = @_;
120 push @IGNORE, @ignore;
123 =head2 catalyst_par($name)
127 # Workaround for a namespace conflict
129 my ( $self, $par ) = @_;
133 my $name = $self->name;
136 my $class_string = join "', '", @CLASSES;
137 $class_string = "'$class_string'" if $class_string;
138 local $Data::Dumper::Indent = 0;
139 local $Data::Dumper::Terse = 1;
140 local $Data::Dumper::Pad = ' ';
141 my $paropts_string = Dumper(\%PAROPTS) || "{ }";
142 $self->postamble(<<EOF);
144 \t\$(NOECHO) \$(PERL) -Ilib -Minc::Module::Install -MModule::Install::Catalyst -e"Catalyst::Module::Install::_catalyst_par( '$par', '$name', { CLASSES => [$class_string], PAROPTS => $paropts_string, ENGINE => '$ENGINE', SCRIPT => '$SCRIPT', USAGE => q#$usage# } )"
147 Please run "make catalyst_par" to create the PAR package!
151 =head2 catalyst_par_core($core)
155 sub catalyst_par_core {
156 my ( $self, $core ) = @_;
157 $core ? ( $PAROPTS{'B'} = $core ) : $PAROPTS{'B'}++;
160 =head2 catalyst_par_classes(@clases)
164 sub catalyst_par_classes {
165 my ( $self, @classes ) = @_;
166 push @CLASSES, @classes;
169 =head2 catalyst_par_engine($engine)
173 sub catalyst_par_engine {
174 my ( $self, $engine ) = @_;
178 =head2 catalyst_par_multiarch($multiarch)
182 sub catalyst_par_multiarch {
183 my ( $self, $multiarch ) = @_;
184 $multiarch ? ( $PAROPTS{'m'} = $multiarch ) : $PAROPTS{'m'}++;
187 =head2 catalyst_par_options($optstring)
189 This command can be used in Makefile.PL to customise the PAR creation process.
190 The parameter "$optstring" contains a string with arguments in identical syntax
191 as arguments of B<pp> command from L<PAR::Packer> package.
195 # part of your Makefile.PL
197 catalyst_par_options("--verbose=2 -f Bleach -z 9");
198 # verbose mode; use filter 'Bleach'; zip with compression level 9
201 Note1: There is no reason to use catalyst_par_options() command multiple times
202 as you can spacify in "$optstring" as many options as you want. Still, it
203 is supported to call catalyst_par_options() more than once. In that case the
204 specified options are merged (collisions are handled on principle "later wins").
205 BEWARE: you are discouraged from using parameters -a -A -X -f -F -I -l -M in
206 multiple catalyst_par_options() as they are not merged but replaced as you would
209 Note2: By default the options "-x -p -o=<appname>.par" are set and option "-n"
210 is unset. This default always overrides whatever you specify by
211 catalyst_par_options().
215 sub catalyst_par_options {
216 my ( $self, $optstring ) = @_;
218 eval "use PAR::Packer ()";
220 warn "WARNING: catalyst_par_options ignored - you need PAR::Packer\n"
223 GetOptionsFromString($optstring, \%o, PAR::Packer->options);
224 %PAROPTS = ( %PAROPTS, %o);
228 =head2 catalyst_par_script($script)
232 sub catalyst_par_script {
233 my ( $self, $script ) = @_;
237 =head2 catalyst_par_usage($usage)
241 sub catalyst_par_usage {
242 my ( $self, $usage ) = @_;
246 package Catalyst::Module::Install;
250 use File::Copy::Recursive 'rmove';
254 my ( $par, $class_name, $opts ) = @_;
256 my $ENGINE = $opts->{ENGINE};
257 my $CLASSES = $opts->{CLASSES} || [];
258 my $USAGE = $opts->{USAGE};
259 my $SCRIPT = $opts->{SCRIPT};
260 my $PAROPTS = $opts->{PAROPTS};
262 my $name = $class_name;
265 $par ||= "$name.par";
266 my $engine = $ENGINE || 'CGI';
270 die "Please install PAR\n" if $@;
271 eval "use PAR::Packer ()";
272 die "Please install PAR::Packer\n" if $@;
273 eval "use App::Packer::PAR ()";
274 die "Please install App::Packer::PAR\n" if $@;
275 eval "use Module::ScanDeps ()";
276 die "Please install Module::ScanDeps\n" if $@;
278 my $root = $FindBin::Bin;
279 $class_name =~ s/-/::/g;
280 my $path = File::Spec->catfile( 'blib', 'lib', split( '::', $class_name ) );
282 unless ( -f $path ) {
283 print qq/Not writing PAR, "$path" doesn't exist\n/;
286 print qq/Writing PAR "$par"\n/;
287 chdir File::Spec->catdir( $root, 'blib' );
289 my $par_pl = 'par.pl';
292 my $version = $Catalyst::VERSION;
293 my $class = $class_name;
296 $classes .= " require $_;\n" for @$CLASSES;
300 my $usage = $USAGE || <<"EOF";
302 [parl] $name\[.par] [script] [arguments]
305 parl $name.par $name\_server.pl -r
309 my $script = $SCRIPT;
310 my $tmp_file = IO::File->new("> $par_pl ");
311 print $tmp_file <<"EOF";
312 if ( \$ENV{PAR_PROGNAME} ) {
313 my \$zip = \$PAR::LibCache{\$ENV{PAR_PROGNAME}}
314 || Archive::Zip->new(__FILE__);
315 my \$script = '$script';
316 \$ARGV[0] ||= \$script if \$script;
317 if ( ( \@ARGV == 0 ) || ( \$ARGV[0] eq '-h' ) || ( \$ARGV[0] eq '-help' )) {
318 my \@members = \$zip->membersMatching('.*script/.*\.pl');
319 my \$list = " Available scripts:\\n";
320 for my \$member ( \@members ) {
321 my \$name = \$member->fileName;
322 \$name =~ /(\\w+\\.pl)\$/;
324 next if \$name =~ /^main\.pl\$/;
325 next if \$name =~ /^par\.pl\$/;
326 \$list .= " \$name\\n";
333 my \$file = shift \@ARGV;
334 \$file =~ s/^.*[\\/\\\\]//;
335 \$file =~ s/\\.[^.]*\$//i;
336 my \$member = eval { \$zip->memberNamed("./script/\$file.pl") };
337 die qq/Can't open perl script "\$file"\n/ unless \$member;
338 PAR::_run_member( \$member, 1 );
343 \$ENV{CATALYST_ENGINE} = '$engine';
346 require Catalyst::Helper;
347 require Catalyst::Test;
348 require Catalyst::Engine::HTTP;
349 require Catalyst::Engine::CGI;
350 require Catalyst::Controller;
351 require Catalyst::Model;
352 require Catalyst::View;
353 require Getopt::Long;
362 local $SIG{__WARN__} = sub { };
363 open my $olderr, '>&STDERR';
364 open STDERR, '>', File::Spec->devnull;
367 # take user defined options first and override them with harcoded defaults
373 # do not replace the whole $opt{'a'} array; just push required default value
374 push @{$opt{'a'}}, grep( !/par.pl/, glob '.' );
376 App::Packer::PAR->new(
377 frontend => 'Module::ScanDeps',
378 backend => 'PAR::Packer',
384 open STDERR, '>&', $olderr;
388 rmove( File::Spec->catfile( 'blib', $par ), $par );
394 Catalyst Contributors, see Catalyst.pm
398 This library is free software. You can redistribute it and/or modify it under
399 the same terms as Perl itself.