|Problems? Is your data what you think it is?|
Re^3: Introducing Class::InsideOutby xdg (Monsignor)
|on Jan 09, 2006 at 23:20 UTC||Need Help??|
From my AnnoCPAN comment:
These package blocks are only necessary if multiple classes are being defined in the same file, or there are mixed classes and code. (Which is what the synopsis shows.) They keep the lexical variables for each in separate scopes. If a single file holds only a single class, the enclosing file scope is sufficient and the braces aren't necessary.
Perl 6 uses a class declaration with braces. From Apocalypse 12, here's an example of a Perl 6 class:
Since a Perl 5 package statement isn't exactly the same as a Perl 6 class statement, it's potentially confusing to write this:
In Perl 5, the braces are just defining a lexical scope, which inside-out objects happen to use to create encapsulation. But unless there are other lexical scopes in the file that defines the Perl 5 class, the braces aren't necessary and writing them on the same line may make people think it's related to the package statement. As an example, consider this version with the braces moved:
Now consider what happens if the package statement is inside the braces instead:
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.