Subject: | "use utf8;" before package declaration causes Perl::Critic RequireExplicitPackage error |
When dumping a scheme using dbicdump, the header of the resulting files is something like:
use utf8;
package App::Schema;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
The fact that the "use utf8" line is before the package declaration causes a severity 4 error in Perl::Critic static code analysis:
% perlcritic --severity 4 --verbose "[%p] %f:%l:%c:%m\n" App/Schema.pm
[Modules::RequireExplicitPackage] App/Schema.pm:1:1:Code not contained in explicit package
I tracked the issue to lines 1983 - 1987 of source file DBIx::Class::Schema::Loader::Base.pm:
my $schema_text =
qq|use utf8;\n|
. qq|package $schema_class;\n\n|
. qq|# Created by DBIx::Class::Schema::Loader\n|
. qq|# DO NOT MODIFY THE FIRST PART OF THIS FILE\n\n|;
I suggest to swap the order of the two first lines to solve this, as such:
my $schema_text =
qq|package $schema_class;\n|
. qq|use utf8;\n\n|
. qq|# Created by DBIx::Class::Schema::Loader\n|
. qq|# DO NOT MODIFY THE FIRST PART OF THIS FILE\n\n|;
Cheers,
Filipe Custódio