Skip Menu |

This queue is for tickets about the DBIx-Class-Schema-Loader CPAN distribution.

Report information
The Basics
Id: 133527
Status: open
Priority: 0/
Queue: DBIx-Class-Schema-Loader

People
Owner: Nobody in particular
Requestors: filipe.custodio [...] gmail.com
Cc:
AdminCc:

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



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
On 2020-10-13 07:27:46, filipe.custodio@gmail.com wrote: Show quoted text
> 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
This is a bad perlcritic metric. Consider a file that starts like this: use utf8; package Acme::ಠ_ಠ; If the order of these two statements was reversed, the package name would not be declared properly. I would suggest you disable the use of this metric either for your entire project, or exclude dbicdump-generated files from being checked, and if you are so inclined, patch perlcritic itself to exclude the 'utf8' module from being included in this check.
Subject: Re: [rt.cpan.org #133527] "use utf8;" before package declaration causes Perl::Critic RequireExplicitPackage error
Date: Mon, 19 Oct 2020 12:53:16 +0100
To: bug-DBIx-Class-Schema-Loader [...] rt.cpan.org
From: Filipe Custodio <filipe.custodio [...] gmail.com>
Dear Karen, I understand your point. I will check the perlcritic policy. Cheers, Filipe Custódio Show quoted text
> On 13 Oct 2020, at 18:02, Karen Etheridge via RT <bug-DBIx-Class-Schema-Loader@rt.cpan.org> wrote: > > <URL: https://rt.cpan.org/Ticket/Display.html?id=133527 > > > On 2020-10-13 07:27:46, filipe.custodio@gmail.com wrote:
>> 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
> > This is a bad perlcritic metric. Consider a file that starts like this: > > use utf8; > package Acme::ಠ_ಠ; > > If the order of these two statements was reversed, the package name would not be declared properly. > > I would suggest you disable the use of this metric either for your entire project, or exclude dbicdump-generated files from being checked, and if you are so inclined, patch perlcritic itself to exclude the 'utf8' module from being included in this check.