Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Why to wrap Perl classes inside a Perl script into blocks

by Eily (Monsignor)
on Jun 01, 2015 at 17:05 UTC ( [id://1128603]=note: print w/replies, xml ) Need Help??


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 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1128603]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-03-29 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found