in reply to Why to wrap Perl classes inside a Perl script into blocks
I'd guess it's to make sure that the scopes don't mixYup, 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:
withpackage First; our $var = 1; package Second; $var++; print $First::var;
The syntax in this post can be used if you want to be compatible with older versions of perl.package First { our $var = 1; } package Second { $var++; #doesn't work under strict print $First::var; }
|
|---|