From 8893ac58fc4a4c2621ddd0002487a0f00a45f48c Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Mon, 6 Jan 2014 12:06:29 +0000 Subject: [PATCH] Bug 11479: Remove experimental given/when keywords Replace constructs using given and when by if/else feature now generates compilation warnings in 5.18 and is liable to change behaviour. This patch: * replaces the construct with if/else * reformats the if branching using perltidy to remove the now redundant indent To test: [1] Verify that prove -v t/db_dependent/MarcModificationTemplates.t passes. Signed-off-by: Chris Cormack Signed-off-by: Jonathan Druart Signed-off-by: Galen Charlton (cherry picked from commit 11faf9fde8da48c58e853d5538a8e3bbd2ae41c5) Signed-off-by: Fridolin Somers --- C4/MarcModificationTemplates.pm | 90 ++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/C4/MarcModificationTemplates.pm b/C4/MarcModificationTemplates.pm index 50b77df740..65b52920b9 100644 --- a/C4/MarcModificationTemplates.pm +++ b/C4/MarcModificationTemplates.pm @@ -547,49 +547,59 @@ sub ModifyRecordWithTemplate { ); my $do = 1; - if ( $conditional ) { - for ( $conditional_comparison ) { - when ( /^exists$/ ) { - my $exists = field_exists( $record, $conditional_field, $conditional_subfield ); - $do = $conditional eq 'if' - ? $exists - : not $exists; - } - when ( /^not_exists$/ ) { - my $exists = field_exists( $record, $conditional_field, $conditional_subfield ); - $do = $conditional eq 'if' - ? not $exists - : $exists; - } - when ( /^equals$/ ) { - my $equals = field_equals( $record, $conditional_value, $conditional_field, $conditional_subfield, $conditional_regex ); - $do = $conditional eq 'if' - ? $equals - : not $equals; - } - when ( /^not_equals$/ ) { - my $equals = field_equals( $record, $conditional_value, $conditional_field, $conditional_subfield, $conditional_regex ); - $do = $conditional eq 'if' - ? not $equals - : $equals; - } + if ($conditional) { + if ( $conditional_comparison eq 'exists' ) { + my $exists = field_exists( $record, $conditional_field, + $conditional_subfield ); + $do = + $conditional eq 'if' + ? $exists + : not $exists; + } + elsif ( $conditional_comparison eq 'not_exists' ) { + my $exists = field_exists( $record, $conditional_field, + $conditional_subfield ); + $do = + $conditional eq 'if' + ? not $exists + : $exists; + } + elsif ( $conditional_comparison eq 'equals' ) { + my $equals = field_equals( + $record, $conditional_value, + $conditional_field, $conditional_subfield, + $conditional_regex + ); + $do = + $conditional eq 'if' + ? $equals + : not $equals; + } + elsif ( $conditional_comparison eq 'not_equals' ) { + my $equals = field_equals( + $record, $conditional_value, + $conditional_field, $conditional_subfield, + $conditional_regex + ); + $do = + $conditional eq 'if' + ? not $equals + : $equals; } } - if ( $do ) { - for ( $action ) { - when ( /^copy_field$/ ) { - copy_field( @params ); - } - when ( /^update_field$/ ) { - update_field( @params ); - } - when ( /^move_field$/ ) { - move_field( @params ); - } - when ( /^delete_field$/ ) { - delete_field( @params ); - } + if ($do) { + if ( $action eq 'copy_field' ) { + copy_field(@params); + } + elsif ( $action eq 'update_field' ) { + update_field(@params); + } + elsif ( $action eq 'move_field' ) { + move_field(@params); + } + elsif ( $action eq 'delete_field' ) { + delete_field(@params); } } -- 2.39.5