[Catalyst-commits] r10503 - in Catalyst-Devel/1.00/branches: . par_options/lib/Module/Install

kmx at dev.catalyst.perl.org kmx at dev.catalyst.perl.org
Thu Jun 11 19:01:10 GMT 2009


Author: kmx
Date: 2009-06-11 19:01:10 +0000 (Thu, 11 Jun 2009)
New Revision: 10503

Added:
   Catalyst-Devel/1.00/branches/par_options/
Modified:
   Catalyst-Devel/1.00/branches/par_options/lib/Module/Install/Catalyst.pm
Log:
C::Devel - new branche catalyst_par_options (push more options into PAR creation process)

Copied: Catalyst-Devel/1.00/branches/par_options (from rev 10501, Catalyst-Devel/1.00/trunk)

Modified: Catalyst-Devel/1.00/branches/par_options/lib/Module/Install/Catalyst.pm
===================================================================
--- Catalyst-Devel/1.00/trunk/lib/Module/Install/Catalyst.pm	2009-06-11 07:27:56 UTC (rev 10501)
+++ Catalyst-Devel/1.00/branches/par_options/lib/Module/Install/Catalyst.pm	2009-06-11 19:01:10 UTC (rev 10503)
@@ -10,6 +10,8 @@
 use FindBin;
 use File::Copy::Recursive 'rcopy';
 use File::Spec ();
+use Getopt::Long;
+use Data::Dumper;
 
 my $SAFETY = 0;
 
@@ -18,10 +20,9 @@
   _build blib lib script t inc \.svn \.git _darcs \.bzr \.hg/;
 our @CLASSES   = ();
 our $ENGINE    = 'CGI';
-our $CORE      = 0;
-our $MULTIARCH = 0;
 our $SCRIPT    = '';
 our $USAGE     = '';
+our %PAROPTS   = ();
 
 =head1 NAME
 
@@ -112,9 +113,13 @@
     $usage =~ s/"/\\"/g;
     my $class_string = join "', '", @CLASSES;
     $class_string = "'$class_string'" if $class_string;
+    local $Data::Dumper::Indent = 0;
+    local $Data::Dumper::Terse = 1;
+    local $Data::Dumper::Pad = ' ';
+    my $paropts_string = Dumper(\%PAROPTS) || "{ }";
     $self->postamble(<<EOF);
 catalyst_par :: all
-\t\$(NOECHO) \$(PERL) -Ilib -Minc::Module::Install -MModule::Install::Catalyst -e"Catalyst::Module::Install::_catalyst_par( '$par', '$name', { CLASSES => [$class_string], CORE => $CORE, ENGINE => '$ENGINE', MULTIARCH => $MULTIARCH, SCRIPT => '$SCRIPT', USAGE => q#$usage# } )"
+\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# } )"
 EOF
     print <<EOF;
 Please run "make catalyst_par" to create the PAR package!
@@ -127,7 +132,7 @@
 
 sub catalyst_par_core {
     my ( $self, $core ) = @_;
-    $core ? ( $CORE = $core ) : $CORE++;
+    $core ? ( $PAROPTS{'B'} = $core ) : $PAROPTS{'B'}++;
 }
 
 =head2 catalyst_par_classes(@clases)
@@ -154,9 +159,49 @@
 
 sub catalyst_par_multiarch {
     my ( $self, $multiarch ) = @_;
-    $multiarch ? ( $MULTIARCH = $multiarch ) : $MULTIARCH++;
+    $multiarch ? ( $PAROPTS{'m'} = $multiarch ) : $PAROPTS{'m'}++;
 }
 
+=head2 catalyst_par_options($optstring)
+
+This command can be used in Makefile.PL to customise the PAR creation process.
+The parameter "$optstring" contains a string with arguments in identical syntax
+as arguments of B<pp> command from L<PAR::Packer> package.
+
+Example:
+
+    # part of your Makefile.PL
+    
+    catalyst_par_options("-v -f Bleach -z 9");
+    # verbose mode; use filter 'Bleach'; zip with compression level 9
+    catalyst;
+
+Note1: There is no reason to use catalyst_par_options() command multiple times
+as you can spacify in "$optstring" as many options as you want. Still, it
+is supported to call catalyst_par_options(...) more than once - in that case the
+specified options are merged (however it does merge arrays with values specified
+by parameters -a -A -X -f -F -I -l -M).
+
+Note2: By default the options "-x=1 -p=1 -n=0 -o=<appname>.par" are set. You can
+override them by catalyst_par_options(); however B<don't change them> unless you 
+exactly know what you are doing.
+
+=cut
+
+sub catalyst_par_options {
+    my ( $self, $optstring ) = @_;
+    my %o = ();
+    eval "use PAR::Packer ()";
+    if ($@) {
+        warn "WARNING: catalyst_par_options ignored - you need PAR::Packer\n"
+    }
+    else {
+        Getopt::Long::Configure ("no_ignore_case");
+        Getopt::Long::GetOptionsFromString($optstring, \%o, PAR::Packer->options);
+        %PAROPTS = ( %PAROPTS, %o);
+    }	 
+}
+
 =head2 catalyst_par_script($script)
 
 =cut
@@ -189,8 +234,7 @@
     my $CLASSES   = $opts->{CLASSES} || [];
     my $USAGE     = $opts->{USAGE};
     my $SCRIPT    = $opts->{SCRIPT};
-    my $MULTIARCH = $opts->{MULTIARCH};
-    my $CORE      = $opts->{CORE};
+    my $PAROPTS   = $opts->{PAROPTS};
 
     my $name = $class_name;
     $name =~ s/::/_/g;
@@ -299,11 +343,13 @@
         'x' => 1,
         'n' => 0,
         'o' => $par,
-        'a' => [ grep( !/par.pl/, glob '.' ) ],
         'p' => 1,
-        'B' => $CORE,
-        'm' => $MULTIARCH
+        %{$PAROPTS},
+        # user defined options override the harcoded defaults
     );
+    # do not replace the whole $opt{'a'} array; just push required default value
+    push @{$opt{'a'}}, grep( !/par.pl/, glob '.' );  
+
     App::Packer::PAR->new(
         frontend  => 'Module::ScanDeps',
         backend   => 'PAR::Packer',




More information about the Catalyst-commits mailing list