On Fri, Sep 9, 2022 at 3:32 AM Andrew Dunstan <and...@dunslane.net> wrote:

> A better way do do this IMNSHO is to put the eval in a block on its own along 
> with the no critic marker on its own line, like this:
>
> {
>    ## no critic (ProhibitStringyEval)
>    eval ...
> }
>
> perlcritic respects block boundaries for its directives.

I tried that in the attached -- it looks a bit nicer but requires more
explanation. I don't have strong feelings either way.

-- 
John Naylor
EDB: http://www.enterprisedb.com
diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm
index 1546e1b335..052abe322f 100644
--- a/src/backend/catalog/Catalog.pm
+++ b/src/backend/catalog/Catalog.pm
@@ -314,11 +314,14 @@ sub ParseData
 				{
 					# We're treating the input line as a piece of Perl, so we
 					# need to use string eval here. Tell perlcritic we know what
-					# we're doing.
-					#<<< protect next line from perltidy
-					# so perlcritic annotation works
-					eval '$hash_ref = ' . $_;    ## no critic (ProhibitStringyEval)
-					#>>>
+					# we're doing. The separate block for this statement is to
+					# limit the scope of the perlcritic exception, which is on
+					# its own line to keep perltidy from reindenting it.
+					{
+						## no critic (ProhibitStringyEval)
+						eval '$hash_ref = ' . $_;
+					}
+
 					if (!ref $hash_ref)
 					{
 						die "$input_file: error parsing line $.:\n$_\n";

Reply via email to