Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

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

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

People
Owner: Nobody in particular
Requestors: bailey [...] mail.newman.upenn.edu
Cc:
AdminCc:

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



The canned default list of allowed pragmata has aged out a bit, and in particular doesn't allow for the C<use 5.xxx> statement used to enable features in perl >= 5.010. Patch updates the default list of allowed pragmata to include this and the C<feature> pragma. While I'm here, the patch also picks up your TODO and add trivial changes to make the list of allowed pragmata configurable.
Subject: ExceptForPragmata.pm.diff
--- ExceptForPragmata.pm.orig 2007-12-30 11:27:26.000000000 -0500 +++ ExceptForPragmata.pm 2010-08-03 22:53:56.000000000 -0400 @@ -22,9 +22,16 @@ who that is. Good encapsulation and common decency require your module to keep its innards to itself. -Sure, that's swell for code that has effect at a package level, but some -statements are lexical. This policy makes allowance for just one of those -cases: turning on strictures, warnings, and diagnostics. +Sure, that's swell for code that has effect at a package level, but +some statements are lexical. This policy makes allowance for some of +those cases. By default, it permits turning on strictures, warnings, +features, and diagnostics, as well as requiring a minimum Perl +version. + +This default list can be changed via the C<allowed_pragmata> +configuration parameter, which is a space-separated list of pragma +names to be permitted. In this list, the name C<perlversion> is +special: it allows a C<use 5.xxx> statement. This module understands the C<exempt_scripts> configuration parameter just like L<Perl::Critic::Policy::Modules::RequireExplicitPackage>. @@ -50,17 +57,32 @@ #Set config, if defined $self->{_exempt_scripts} = defined $args{exempt_scripts} ? $args{exempt_scripts} : 1; + if (defined $args{allowed_pragmata}) { + $self->{_allowed_pragmata} = {}; + $self->{_allowed_version} = 0; + foreach my $p (split /\s+/, $args{allowed_pragmata}) { + if ($p eq 'perlversion') { + $self->{_allowed_version} = 1; + } + else { + $self->{_allowed_pragmata}->{$p} = 1; + } + } + } + else { + $self->{_allowed_pragmata} = + { + diagnostics => 1, + feature => 1, + strict => 1, + warnings => 1, + }; + $self->{_allowed_version} = 1; + } return $self; } -# TODO: Make this configurable. -- rjbs, 2006-11-07 -my %allowed_pragmata = ( - diagnostics => 1, - strict => 1, - warnings => 1, -); - sub violates { my ($self, $elem, $doc) = @_; @@ -77,7 +99,8 @@ my @non_packages = grep { not( $_->isa('PPI::Statement::Include') && $_->type eq 'use' - && exists $allowed_pragmata{ $_->module } + && ( $_->version && $self->{_allowed_version} || + exists $self->{_allowed_pragmata}{ $_->module } ) ) } grep { !$_->isa('PPI::Statement::Package') } @{$stmnts_ref}; return if !@non_packages;
Subject: Better . . .
On Tue Aug 03 22:59:30 2010, CBAIL wrote: Show quoted text
> The canned default list of allowed pragmata has aged out a bit, and in > particular doesn't allow for the C<use 5.xxx> statement used to enable > features in perl >= 5.010. Patch updates the default list of allowed > pragmata to include this and the C<feature> pragma. > > While I'm here, the patch also picks up your TODO and add trivial > changes to make the list of allowed pragmata configurable.
Missed tests in last night's patch; the attached revision includes additional tests. Along the way, it also converts ExceptForPragmata.pm to use the new P::C config mechanism, and removes a couple calls to the deprecated is_script() function.
Subject: ExceptForPragmata_config.dif

Message body not shown because it is not plain text.

Thanks, applied! -- rjbs