pf-tools/pf-tools: Update/Common.pm: factorisation subs on_{action}
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Mon Dec 15 14:04:04 UTC 2014
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/c01be7865bfb
changeset: 1385:c01be7865bfb
user: melkor <melkor at sitadelle.com>
date: Mon Dec 15 15:04:01 2014 +0100
description:
Update/Common.pm: factorisation subs on_{action}
diffstat:
lib/PFTools/Update/ADDFILE.pm | 4 -
lib/PFTools/Update/Common.pm | 95 +++++++++++++++++-------------------------
2 files changed, 39 insertions(+), 60 deletions(-)
diffs (141 lines):
diff -r dc18a323f292 -r c01be7865bfb lib/PFTools/Update/ADDFILE.pm
--- a/lib/PFTools/Update/ADDFILE.pm Mon Dec 15 13:38:11 2014 +0100
+++ b/lib/PFTools/Update/ADDFILE.pm Mon Dec 15 15:04:01 2014 +0100
@@ -208,9 +208,7 @@
print_diff_color(@diff);
}
}
- print "on_config ...\n";
do_on_config( $ref_section, $options, $hash_subst ) or return;
- print "before_change ...\n";
do_before_change( $ref_section, $options, $hash_subst ) or return;
if ( !$options->{'simul'} ) {
@@ -230,9 +228,7 @@
do_chownmod( $ref_section, $dest, $options );
}
if ($diff) {
- print "after_change ...\n";
do_after_change( $ref_section, $options, $hash_subst ) or return;
- print "on_noaction ...\n";
do_on_noaction( $ref_section, $options, $hash_subst ) or return;
}
}
diff -r dc18a323f292 -r c01be7865bfb lib/PFTools/Update/Common.pm
--- a/lib/PFTools/Update/Common.pm Mon Dec 15 13:38:11 2014 +0100
+++ b/lib/PFTools/Update/Common.pm Mon Dec 15 15:04:01 2014 +0100
@@ -218,75 +218,58 @@
sub do_on_config {
my ( $ref_section, $options, $hash_subst ) = @_;
- if ( $ref_section->{'actiongroup'} ) {
- if ( $options->{'verbose'} ) {
- Log( q{Triggering actiongroup } . $ref_section->{'actiongroup'} );
- }
- return 1;
- }
- if ( !$options->{'simul'}
- && defined( $ref_section->{'on_config'} ) )
- {
- return exec_cmd(
- subst_vars( $ref_section->{'on_config'}, $hash_subst ) );
- }
- return 1;
+ return __do_trigger_action (q{on_config}, $ref_section, $options, $hash_subst);
}
sub do_before_change {
my ( $ref_section, $options, $hash_subst ) = @_;
+ return __do_trigger_action (q{before_change}, $ref_section, $options, $hash_subst, { not_if => [ q{on_noaction} ] } );
+}
+
+sub do_after_change {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ return __do_trigger_action (q{after_change}, $ref_section, $options, $hash_subst, { not_if => [ q{on_noaction} ] } );
+}
+
+sub do_on_noaction {
+ my ( $ref_section, $options, $hash_subst ) = @_;
+
+ return __do_trigger_action (q{on_noaction}, $ref_section, $options, $hash_subst, { only_if => [ q{on_noaction} ] } );
+}
+
+sub __do_trigger_action {
+ my ( $trigger_name, $ref_section, $options, $hash_subst, $depends_trigger ) = @_;
+
+ if ($depends_trigger->{not_if} ne 'ARRAY' or !grep { m{ \A simul \z }xms } @{$depends_trigger->{not_if}}) {
+ push @{$depends_trigger->{not_if}}, 'simul';
+ }
+
if ( $ref_section->{'actiongroup'} ) {
if ( $options->{'verbose'} ) {
Log( q{Triggering actiongroup } . $ref_section->{'actiongroup'} );
}
return 1;
}
- if ( !$options->{'simul'}
- && !$options->{'noaction'}
- && defined( $ref_section->{'before_change'} ) )
- {
+
+ if ( defined $ref_section->{$trigger_name} ) {
+ print qq{$trigger_name ...\n};
+
+ foreach my $depend_trigger ( @{$depends_trigger->{not_if}} ) {
+ return 1 if $options->{$depend_trigger};
+ }
+
+ if ( ref @{$depends_trigger->{only_if}} eq 'ARRAY' ) {
+ foreach my $depend_trigger ( @{$depends_trigger->{only_if}} ) {
+ return if !$options->{$depend_trigger};
+ }
+ }
+
return exec_cmd(
- subst_vars( $ref_section->{'before_change'}, $hash_subst ) );
+ subst_vars( $ref_section->{$trigger_name}, $hash_subst ) );
}
- return 1;
-}
-
-sub do_after_change {
- my ( $ref_section, $options, $hash_subst ) = @_;
-
- if ( $ref_section->{'actiongroup'} ) {
- if ( $options->{'verbose'} ) {
- Log( q{Triggering actiongroup } . $ref_section->{'actiongroup'} );
- }
- return 1;
- }
- if ( !$options->{'simul'}
- && defined( $ref_section->{'after_change'} )
- && !$options->{'noaction'} )
- {
- return exec_cmd(
- subst_vars( $ref_section->{'after_change'}, $hash_subst ) );
- }
- return 1;
-}
-
-sub do_on_noaction {
- my ( $ref_section, $options, $hash_subst ) = @_;
-
- if ( $ref_section->{'actiongroup'} ) {
- if ( $options->{'verbose'} ) {
- Log( q{Triggering actiongroup } . $ref_section->{'actiongroup'} );
- }
- return 1;
- }
- if ( !$options->{'simul'}
- && defined( $ref_section->{'on_noaction'} )
- && $options->{'noaction'} )
- {
- return exec_cmd(
- subst_vars( $ref_section->{'on_noaction'}, $hash_subst ) );
- }
+
return 1;
}
More information about the pf-tools-commits
mailing list