############################################################################## # $URL: http://perlcritic.tigris.org/svn/perlcritic/branches/Perl-Critic-backlog/lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitLvalueSubstr.pm $ # $Date: 2009-09-07 16:19:21 -0500 (Mon, 07 Sep 2009) $ # $Author: clonezone $ # $Revision: 3629 $ ############################################################################## package Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr; use 5.006001; use strict; use warnings; use Readonly; use Perl::Critic::Utils qw{ :severities :classification }; use base 'Perl::Critic::Policy'; our $VERSION = '1.105'; #----------------------------------------------------------------------------- Readonly::Scalar my $DESC => q{Lvalue form of "substr" used}; Readonly::Scalar my $EXPL => [ 165 ]; #----------------------------------------------------------------------------- sub supported_parameters { return () } sub default_severity { return $SEVERITY_MEDIUM } sub default_themes { return qw( core maintenance pbp ) } sub applies_to { return 'PPI::Token::Word' } #----------------------------------------------------------------------------- sub violates { my ($self, $elem, undef) = @_; return if $elem ne 'substr'; return if ! is_function_call($elem); my $sib = $elem; while ($sib = $sib->snext_sibling()) { if ( $sib->isa( 'PPI::Token::Operator') && $sib eq q{=} ) { return $self->violation( $DESC, $EXPL, $sib ); } } return; #ok! } 1; #----------------------------------------------------------------------------- __END__ =pod =head1 NAME Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr - Use 4-argument C instead of writing C. =head1 AFFILIATION This Policy is part of the core L distribution. =head1 DESCRIPTION Conway discourages the use of C as an lvalue, instead recommending that the 4-argument version of C be used instead. substr($something, 1, 2) = $newvalue; # not ok substr($something, 1, 2, $newvalue); # ok =head1 CONFIGURATION This Policy is not configurable except for the standard options. =head1 AUTHOR Graham TerMarsch =head1 COPYRIGHT Copyright (c) 2005-2009 Graham TerMarsch. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut # Local Variables: # mode: cperl # cperl-indent-level: 4 # fill-column: 78 # indent-tabs-mode: nil # c-indentation-style: bsd # End: # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :