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: 63965
Status: new
Priority: 0/
Queue: Perl-Critic

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

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



Subject: Exception for special filehandles in InputOutput::RequireBracedFileHandleWithPrint
Download (untitled) / with headers
text/plain 2.4k
After some debate, we've decided in my company that braces around the builtin filehandles is obnoxious, so I customized RequireBracedFileHandleWithPrint for ourselves locally and thought I contribute back in case someone thinks this would work in the core distro (even though it no longer conforms to PBP exactly). I just added a simple boolean switch so you get the following behavior: print $fh $foo; # not ok print {$fh} $foo; # ok print {*STDERR} $foo; # ugly but still ok print STDERR $foo # much better! I didn't add any tests, since the worst thing I could imagine is a false negative if someone wrote something like sub STDERR (@) { ... } and I don't see how you'd ever detect that anyway. --- Perl/Critic/Policy/InputOutput/RequireBracedFileHandleWithPrint.pm 2009-09-07 15:37:07.000000000 -0600 +++ /Perl/Critic/Policy/InputOutput/RequireBracedFileHandleWithPrint.pm 2010-12-15 17:07:49.000000000 -0700 @@ -28,7 +28,16 @@ #----------------------------------------------------------------------------- -sub supported_parameters { return () } +sub supported_parameters { + return ( + { + name => 'exclude_special_filehandles', + description => 'Allows non-braced uses of the special global filehandles (STDIN, STDOUT, etc)', + default_string => '0', + behavior => 'boolean', + }, + ); +} sub default_severity { return $SEVERITY_LOWEST } sub default_themes { return qw( core pbp cosmetic ) } sub applies_to { return 'PPI::Token::Word' } @@ -67,6 +76,9 @@ return if is_perl_builtin($sib[0]); return if exists $POSTFIX_WORDS{ $sib[0] }; + # Allow special filehandles if requested + return if $self->{'_exclude_special_filehandles'} && is_perl_filehandle($sib[0]); + # Second token must be white space return if !$sib[1]->isa('PPI::Token::Whitespace'); @@ -119,7 +131,14 @@ =head1 CONFIGURATION -This Policy is not configurable except for the standard options. +If you find C<print {*STDERR} $foo> to be a little difficult to swallow +or harder to decipher than just C<print STDERR $foo> but still want to +encourage C<print {$fh} $foo> there is an option to exclude the +standard set of special, global filehandles (e.g. STDIN, STDERR, etc): +C<exclude_special_filehandles>. + + [InputOutput::RequireBracedFileHandleWithPrint] + exclude_special_filehandles = 1 =head1 AUTHOR
From: rvandam00 [...] gmail.com
Ugh, here's the diff with formatting intact.
Subject: io_requirebraced.diff
--- Perl/Critic/Policy/InputOutput/RequireBracedFileHandleWithPrint.pm 2009-09-07 15:37:07.000000000 -0600 +++ Perl/Critic/Policy/InputOutput/RequireBracedFileHandleWithPrint.pm 2010-12-15 17:07:49.000000000 -0700 @@ -28,7 +28,16 @@ #----------------------------------------------------------------------------- -sub supported_parameters { return () } +sub supported_parameters { + return ( + { + name => 'exclude_special_filehandles', + description => 'Allows non-braced uses of the special global filehandles (STDIN, STDOUT, etc)', + default_string => '0', + behavior => 'boolean', + }, + ); +} sub default_severity { return $SEVERITY_LOWEST } sub default_themes { return qw( core pbp cosmetic ) } sub applies_to { return 'PPI::Token::Word' } @@ -67,6 +76,9 @@ return if is_perl_builtin($sib[0]); return if exists $POSTFIX_WORDS{ $sib[0] }; + # Allow special filehandles if requested + return if $self->{'_exclude_special_filehandles'} && is_perl_filehandle($sib[0]); + # Second token must be white space return if !$sib[1]->isa('PPI::Token::Whitespace'); @@ -119,7 +131,14 @@ =head1 CONFIGURATION -This Policy is not configurable except for the standard options. +If you find C<print {*STDERR} $foo> to be a little difficult to swallow +or harder to decipher than just C<print STDERR $foo> but still want to +encourage C<print {$fh} $foo> there is an option to exclude the +standard set of special, global filehandles (e.g. STDIN, STDERR, etc): +C<exclude_special_filehandles>. + + [InputOutput::RequireBracedFileHandleWithPrint] + exclude_special_filehandles = 1 =head1 AUTHOR


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.