2 package Module::Install::Catalyst;
7 require Module::Install::Base;
8 @ISA = qw/Module::Install::Base/;
12 use File::Copy::Recursive;
20 qw/Build Build.PL Changes MANIFEST META.yml Makefile.PL Makefile README
21 _build blib lib script t inc .*\.svn \.git _darcs \.bzr \.hg
22 debian build-stamp install-stamp configure-stamp/;
34 if($Module::Install::AUTHOR) {
35 $self->include("File::Copy::Recursive");
39 *** Module::Install::Catalyst
41 $self->catalyst_files;
44 *** Module::Install::Catalyst finished.
57 CATFILES: for my $name ( readdir CATDIR ) {
58 for my $ignore (@IGNORE) {
59 next CATFILES if $name =~ /^$ignore$/;
60 next CATFILES if $name !~ /\w/;
65 my @path = split '-', $self->name;
66 for my $orig (@files) {
67 my $path = File::Spec->catdir( 'blib', 'lib', @path, $orig );
68 File::Copy::Recursive::rcopy( $orig, $path );
74 sub catalyst_ignore_all {
75 my ( $self, $ignore ) = @_;
82 my ( $self, @ignore ) = @_;
83 push @IGNORE, @ignore;
88 # Workaround for a namespace conflict
90 my ( $self, $par ) = @_;
94 my $name = $self->name;
97 my $class_string = join "', '", @CLASSES;
98 $class_string = "'$class_string'" if $class_string;
99 local $Data::Dumper::Indent = 0;
100 local $Data::Dumper::Terse = 1;
101 local $Data::Dumper::Pad = ' ';
102 my $paropts_string = Dumper(\%PAROPTS) || "{ }";
103 $self->postamble(<<EOF);
105 \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# } )"
108 Please run "make catalyst_par" to create the PAR package!
114 sub catalyst_par_core {
115 my ( $self, $core ) = @_;
116 $core ? ( $PAROPTS{'B'} = $core ) : $PAROPTS{'B'}++;
121 sub catalyst_par_classes {
122 my ( $self, @classes ) = @_;
123 push @CLASSES, @classes;
128 sub catalyst_par_engine {
129 my ( $self, $engine ) = @_;
135 sub catalyst_par_multiarch {
136 my ( $self, $multiarch ) = @_;
137 $multiarch ? ( $PAROPTS{'m'} = $multiarch ) : $PAROPTS{'m'}++;
142 sub catalyst_par_options {
143 my ( $self, $optstring ) = @_;
144 eval "use PAR::Packer ()";
146 warn "WARNING: catalyst_par_options ignored - you need PAR::Packer\n"
149 my $p = Getopt::Long::Parser->new(config => ['no_ignore_case']);
151 require Text::ParseWords;
153 local @ARGV = Text::ParseWords::shellwords($optstring);
154 $p->getoptions(\%o, PAR::Packer->options);
156 %PAROPTS = ( %PAROPTS, %o);
162 sub catalyst_par_script {
163 my ( $self, $script ) = @_;
169 sub catalyst_par_usage {
170 my ( $self, $usage ) = @_;
174 package Catalyst::Module::Install;
178 use File::Copy::Recursive 'rmove';
182 my ( $par, $class_name, $opts ) = @_;
184 my $ENGINE = $opts->{ENGINE};
185 my $CLASSES = $opts->{CLASSES} || [];
186 my $USAGE = $opts->{USAGE};
187 my $SCRIPT = $opts->{SCRIPT};
188 my $PAROPTS = $opts->{PAROPTS};
190 my $name = $class_name;
193 $par ||= "$name.par";
194 my $engine = $ENGINE || 'CGI';
198 die "Please install PAR\n" if $@;
199 eval "use PAR::Packer ()";
200 die "Please install PAR::Packer\n" if $@;
201 eval "use App::Packer::PAR ()";
202 die "Please install App::Packer::PAR\n" if $@;
203 eval "use Module::ScanDeps ()";
204 die "Please install Module::ScanDeps\n" if $@;
206 my $root = $FindBin::Bin;
207 $class_name =~ s/-/::/g;
208 my $path = File::Spec->catfile( 'blib', 'lib', split( '::', $class_name ) );
210 unless ( -f $path ) {
211 print qq/Not writing PAR, "$path" doesn't exist\n/;
214 print qq/Writing PAR "$par"\n/;
215 chdir File::Spec->catdir( $root, 'blib' );
217 my $par_pl = 'par.pl';
220 my $version = $Catalyst::VERSION;
221 my $class = $class_name;
224 $classes .= " require $_;\n" for @$CLASSES;
228 my $usage = $USAGE || <<"EOF";
230 [parl] $name\[.par] [script] [arguments]
233 parl $name.par $name\_server.pl -r
237 my $script = $SCRIPT;
238 my $tmp_file = IO::File->new("> $par_pl ");
239 print $tmp_file <<"EOF";
240 if ( \$ENV{PAR_PROGNAME} ) {
241 my \$zip = \$PAR::LibCache{\$ENV{PAR_PROGNAME}}
242 || Archive::Zip->new(__FILE__);
243 my \$script = '$script';
244 \$ARGV[0] ||= \$script if \$script;
245 if ( ( \@ARGV == 0 ) || ( \$ARGV[0] eq '-h' ) || ( \$ARGV[0] eq '-help' )) {
246 my \@members = \$zip->membersMatching('.*script/.*\.pl');
247 my \$list = " Available scripts:\\n";
248 for my \$member ( \@members ) {
249 my \$name = \$member->fileName;
250 \$name =~ /(\\w+\\.pl)\$/;
252 next if \$name =~ /^main\.pl\$/;
253 next if \$name =~ /^par\.pl\$/;
254 \$list .= " \$name\\n";
261 my \$file = shift \@ARGV;
262 \$file =~ s/^.*[\\/\\\\]//;
263 \$file =~ s/\\.[^.]*\$//i;
264 my \$member = eval { \$zip->memberNamed("./script/\$file.pl") };
265 die qq/Can't open perl script "\$file"\n/ unless \$member;
266 PAR::_run_member( \$member, 1 );
271 \$ENV{CATALYST_ENGINE} = '$engine';
274 require Catalyst::Helper;
275 require Catalyst::Test;
276 require Catalyst::Engine::HTTP;
277 require Catalyst::Engine::CGI;
278 require Catalyst::Controller;
279 require Catalyst::Model;
280 require Catalyst::View;
281 require Getopt::Long;
290 local $SIG{__WARN__} = sub { };
291 open my $olderr, '>&STDERR';
292 open STDERR, '>', File::Spec->devnull;
295 # take user defined options first and override them with harcoded defaults
301 # do not replace the whole $opt{'a'} array; just push required default value
302 push @{$opt{'a'}}, grep( !/par.pl/, glob '.' );
304 App::Packer::PAR->new(
305 frontend => 'Module::ScanDeps',
306 backend => 'PAR::Packer',
312 open STDERR, '>&', $olderr;
316 rmove( File::Spec->catfile( 'blib', $par ), $par );