Unix/Linux Go Back    


CentOS 7.0 - man page for perl::critic::policy::regularexpressions::prohibitcapturewithouttest (centos section 3)

Linux & Unix Commands - Search Man Pages
Man Page or Keyword Search:   man
Select Man Page Set:       apropos Keyword Search (sections above)


Perl::Critic::Policy::ReguPerl::Critic::Policy::RegularExpressions::ProhibitCaptureWithoutTest(3)

NAME
       Perl::Critic::Policy::RegularExpressions::ProhibitCaptureWithoutTest - Capture variable
       used outside conditional.

AFFILIATION
       This Policy is part of the core Perl::Critic distribution.

DESCRIPTION
       If a regexp match fails, then any capture variables ($1, $2, ...) will be undefined.
       Therefore it's important to check the return value of a match before using those
       variables.

       This policy checks that the previous regexp for which the capture variable is in-scope is
       either in a conditional or causes an exception or other control transfer (i.e. "next",
       "last", "redo", "return", or sometimes "goto") if the match fails.

       A "goto" is only accepted by this policy if it is a co-routine call (i.e.  "goto &foo") or
       a "goto LABEL" where the label does not fall between the "goto" and the capture variable
       in the scope of the "goto". A computed "goto" (i.e. something like "goto (qw{foo bar
       baz})[$i]") is not accepted by this policy because its target can not be statically
       determined.

       This policy does not check whether that conditional is actually testing a regexp result,
       nor does it check whether a regexp actually has a capture in it.  Those checks are too
       hard.

       This policy also does not check arbitrarily complex conditionals guarding regexp results,
       for pretty much the same reason.  Simple things like

	m/(foo)/ or die "No foo!";
	die "No foo!" unless m/(foo)/;

       will be handled, but something like

	m/(foo) or do {
	  ... lots of complicated calculations here ...
	  die "No foo!";
	};

       are beyond its scope.

CONFIGURATION
       By default, this policy considers "die", "croak", and "confess" to throw exceptions. If
       you have additional subroutines or methods that may be used in lieu of one of these, you
       can configure them in your perlcriticrc as follows:

	[RegularExpressions::ProhibitCaptureWithoutTest]
	exception_source = my_exception_generator

BUGS
       This policy does not recognize named capture variables. Yet.

AUTHOR
       Chris Dolan <cdolan@cpan.org>

COPYRIGHT
       Copyright (c) 2006-2011 Chris Dolan.

       This program is free software; you can redistribute it and/or modify it under the same
       terms as Perl itself.

perl v5.16.3		  Perl::Critic::Policy::RegularExpressions::ProhibitCaptureWithoutTest(3)
Unix & Linux Commands & Man Pages : ©2000 - 2018 Unix and Linux Forums


All times are GMT -4. The time now is 05:11 AM.