From: Moritz Bunkus Date: Thu, 18 Nov 2010 13:03:17 +0000 (+0100) Subject: Hilfsfunktion call_sub_if X-Git-Tag: release-2.6.3~25^2~53 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=c73b26581660fe0d06ac40a37a93277018174005;p=kivitendo-erp.git Hilfsfunktion call_sub_if --- diff --git a/SL/DB/Object.pm b/SL/DB/Object.pm index 71e0a3939..a2db47f48 100644 --- a/SL/DB/Object.pm +++ b/SL/DB/Object.pm @@ -84,6 +84,16 @@ sub call_sub { return $self->$sub(@_); } +sub call_sub_if { + my $self = shift; + my $sub = shift; + my $check = shift; + + $check = $check->($self) if ref($check) eq 'CODE'; + + return $check ? $self->$sub(@_) : $self; +} + 1; __END__ @@ -145,6 +155,16 @@ name is a composite, e.g. my $chart_id = $buchungsgruppe->call_sub(($is_sales ? "income" : "expense") . "_accno_id_${taxzone_id}"); +=item C + +Calls the sub C<$name> on C<$self> with the arguments C<@args> if +C<$check> is trueish. If C<$check> is a code reference then it will be +called with C<$self> as the only argument and its result determines +whether or not C<$name> is called. + +Returns the sub's result if the check is positive and C<$self> +otherwise. + =back =head1 AUTHOR