Since
no strict 'refs' only affects the block it's in, it won't affect the rest of your program (past the next curly brace, anyway). I make a practice of putting it in the innermost scope possible. You can do the following instead if you're paranoid. Note that the no strict 'refs' only affects the one line with the assignment. Why would you hesitate to use that? I hope you're not absorbing the 'always use strict everywhere' dogma...
foreach my $field ( keys %orderObjectFields )
{
my $default = $orderObjectFields{$field};
my $closure = sub
{
my $value =
( scalar @_ > 1 ? $_[0]->{$field} = $_[1] : $_[0]->{$fie
+ld} );
$value = $default unless defined $value;
$value;
};
no strict 'refs'; # only affects next statement:
*{ __PACKAGE__ . "::$field" } = $closure;
}