Perl Programming/Keywords/package

The package keyword
The package keyword declares the BLOCK or the rest of the compilation unit within the given namespace. The package scope is given by either the supplied BLOCK or from the declaration through the end of the current scope, which may be the enclosing block, eval, or file. In other words, without BLOCK, the scopes are just like with my, our, and state operators. Only overridden or special identifiers such as <tt>ARGV</tt>, <tt>ENV</tt>, and <tt>STDOUT</tt> that qualify into <tt>main::</tt> are exempted.

Only dynamic variables are affected by the <tt>package</tt> keyword. Lexically-scoped created with <tt>my</tt>, <tt>our</tt>, and <tt>state</tt> are exempted. It is allowed to switch into a package at more than one place, as this only determines which default symbol table the compiler uses for the rest of that block. An identifier prefixed by it's package name can access another package, like <tt>$SomePack::var</tt> or <tt>ThatPack::INPUT_HANDLE</tt>. Without the package name, the main package is assumed: <tt>$::sail</tt> is understood as <tt>$main::sail</tt>.

With <tt>VERSION</tt>, the package sets the <tt>$VERSION</tt> variable in the given namespace to a version object with the provided <tt>VERSION</tt>. <tt>VERSION</tt> must be a strict-style version number with at least three components, as defined by the version module, <tt>$VERSION</tt> should be set only once in a package.