Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 25150
Status: resolved
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: RENEEB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.03
Fixed in: (no value)



Subject: package declaration vs. filename
When I test this script with Perl-Critic-1.03: #!/usr/bin/perl package MyTest; use strict; print "mytest\n"; package main; use strict; print "main\n"; I get this message: Package declaration must match filename at line 3, column 1. Correct the filename or package statement. As this is a script and no module, I think this error is not really an error!
I'm a little confused: If this is not a module, then why declare the "MyTest" package? In conjunction with ProhibitMultiplePackages, the intent of these policies is to ensure that every file has exactly one package, and that the file name matches the package name. That way, it is easy to trace dependencies and locate the code for any given package. However, if you insist on putting multiple packages in scripts, then you can satisfy this policy by placing "package main;" as the first package in the file. I tend to think that having the "main" package appear at the top of the file also improves readability. Please let me know if I have misunderstood your request. Thanks. -Jeff
Hi Jeff, your explanation makes sense to me. Thanks! Cheers, Renee On Mo. 05. Mär. 2007, 13:55:11, THALJEF wrote: Show quoted text
> I'm a little confused: If this is not a module, then why declare > the "MyTest" package? In conjunction with
ProhibitMultiplePackages, Show quoted text
> the intent of these policies is to ensure that every file has
exactly Show quoted text
> one package, and that the file name matches the package name. That > way, it is easy to trace dependencies and locate the code for any > given package. > > However, if you insist on putting multiple packages in scripts, then > you can satisfy this policy by placing "package main;" as the first > package in the file. I tend to think that having the "main" package > appear at the top of the file also improves readability. > > Please let me know if I have misunderstood your request. Thanks. > > -Jeff >