I'd guess it's to make sure that the scopes don't mix
Yup, good answer. Most of the time you'll have only one namespace, or package in each file, so each namespace is scoped to the file. Here this syntax is used to emulate the multi-file scoping in a more compact and easy to test way.
But isn't this already done by using another name space?
Only with the
package ... BLOCK syntax, (which appeared in perl v5.14). Compare:
package First;
our $var = 1;
package Second;
$var++;
print $First::var;
with
package First
{
our $var = 1;
}
package Second
{
$var++; #doesn't work under strict
print $First::var;
}
The syntax in
this post can be used if you want to be compatible with older versions of perl.