<?xml version="1.0" encoding="windows-1252"?>
<node id="1014782" title="Re: Module's name and file's name" created="2013-01-22 15:34:22" updated="2013-01-22 15:34:22">
<type id="11">
note</type>
<author id="757127">
tobyink</author>
<data>
<field name="doctext">
&lt;p&gt;Modules (i.e. ".pm" files containing Perl code) and packages (i.e. namespaces that subs and variables can be defined in) are two different things. There is no rule that says you &lt;em&gt;must&lt;/em&gt; keep their names aligned.&lt;/p&gt;

&lt;p&gt;However, when you do align their names, certain Perl features work in your favour - for example, the &lt;c&gt;use&lt;/c&gt; statement. &lt;c&gt;use Foo::Bar&lt;/c&gt; is defined to load the file &lt;c&gt;Foo/Bar.pm&lt;/c&gt; and then call the &lt;c&gt;import&lt;/c&gt; method in the &lt;c&gt;Foo::Bar&lt;/c&gt; package. This feature is super-handy when the &lt;c&gt;Foo::Bar&lt;/c&gt; package happens to be defined within the file &lt;c&gt;Foo/Bar.pm&lt;/c&gt;; less so when it isn't.&lt;/p&gt;

&lt;p&gt;If you know what you're doing, and are aware of the order in which Perl processes things, how &lt;c&gt;use&lt;/c&gt; works, etc, then it's sometimes possible to break the alignment in useful ways. For example, keeping several small packages in the same file can make sense - it will improve load speed, they can share lexical variables, etc.&lt;/p&gt;

&lt;p&gt;But for the most part, unless you have a specific reason not to, you should try to keep package names and module names aligned.&lt;/p&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-757127"&gt;
&lt;small&gt;&lt;small&gt;&lt;tt&gt;package Cow { use Moo; has name =&gt; (is =&gt; 'lazy', default =&gt; sub { 'Mooington' }) } say Cow-&gt;new-&gt;name&lt;/tt&gt;&lt;/small&gt;&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1014776</field>
<field name="parent_node">
1014776</field>
</data>
</node>
