Problems? Is your data what you think it is? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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 must keep their names aligned. However, when you do align their names, certain Perl features work in your favour - for example, the use statement. use Foo::Bar is defined to load the file Foo/Bar.pm and then call the import method in the Foo::Bar package. This feature is super-handy when the Foo::Bar package happens to be defined within the file Foo/Bar.pm; less so when it isn't. If you know what you're doing, and are aware of the order in which Perl processes things, how use 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. But for the most part, unless you have a specific reason not to, you should try to keep package names and module names aligned.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
In reply to Re: Module's name and file's name
by tobyink
|
|