Subject: | ProhibitAugmentedAssignmentInDeclaration should (optionally) allow the: our $foo ||= ...; idiom |
Using
our $some_unique_variable_name ||= some_expensive_init();
is a common idiom in perl code that needs to be portable to perl versions before the 'state' operator was added.
perl -wle 'sub foo { our $x ||= rand; print $x } foo(); foo(); foo()'
Also, some of the examples given in the docs are misleading. For example the "our $foo *= 2; # same as our $foo = 0;" is only the same as "$foo=0" if $foo had no previous value. Here's an example:
perl -wle 'sub foo { our $call_count += 1; print $call_count } foo(); foo(); foo()'
The same applies to the 'state' example. It's perfectly valid and reasonable behaviour.
Ideally I'd like to see 'our' and 'state' removed from this policy as they are different to 'my' and 'local', but I'd be happy if they were made optional.