Perl-Critic-Grape
    
    
  
  
  
view release on metacpan or search on metacpan
			}
		},
		"configure": {
			"requires": {
				"Module::Build::Tiny": "0.044"
			}
		},
		"build": {
			"requires": {
				"Perl::Critic": "1.156",
				"Ref::Util": "0.204",
				"Test::More": "1.302209"
			}
		}
	},
	"resources" : {
		"bugtracker": {"web":"https://github.com/blb8/perl-critic-grape/issues"},
		"repository": {"url":"git://github.com/blb8/perl-critic-grape.git"}
	},
	"dynamic_config": 1,
	"generated_by": "Brian Blackmore",
lib/Perl/Critic/Policy/References/ProhibitRefChecks.pm view on Meta::CPAN
__END__
=pod
=head1 NAME
Perl::Critic::Policy::References::ProhibitRefChecks - Write C<is_arrayref($var)> instead of C<ref($var) eq 'ARRAY'>.
=head1 DESCRIPTION
Checking references manually is less efficient that using L<Ref::Util> and prone to typos.
	if(ref($var) eq 'ARRYA') # oops!
	if(is_arrayref($var))    # ok
	if(ref($var) ne 'HASH')  # no
	if(!is_hashref($var))    # ok
	if(ref($var))            # no
	if(is_ref($var))         # ok
lib/Perl/Critic/Policy/References/ProhibitRefChecks.pm view on Meta::CPAN
	eq = code
	ne = code my::module
As a special scenario, checks of the form C<ref(...) eq ref(...)> can be permitted with C<eq = ref>.  The same works for C<ne = ref>.
Regular expression matches are violations by default.  To permit checks of the form C<ref(...) =~ /pattern/> or C<!~>:
	[References::ProhibitRefChecks]
	regexp = 1
Since L<Ref::Util> provides C<is_ref>, in the default configuration the bare C<ref> call is rarely needed.  To specifically permit using direct C<ref(...)> calls:
	[References::ProhibitRefChecks]
	bareref = 1
=head1 NOTES
Comparisons to stored values or constants are not supported:  C<ref(...) eq $thing> and C<ref(...) eq HASH()> are violations.
Lexicographic comparison via C<ref(...) cmp "string"> is a violation.
t/perl/critic/policy/references/prohibitrefchecks.t view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use Perl::Critic;
use Perl::Critic::Policy::References::ProhibitRefChecks;
use PPI;
use Ref::Util;
use Test::More tests=>12;
my $failure=qr/Do not perform manual ref/;
subtest 'decompose'=>sub {
	plan tests=>33;
	my $decompose=sub {
		my ($code)=@_;
		my $doc=PPI::Document->new(\$code);
t/perl/critic/policy/references/prohibitrefchecks.t view on Meta::CPAN
		'ref($href->{k}) =~ /CODE/'      => ['=~','/CODE/'],
		'ref($href->{k}) eq "CODE" && 1' => ['eq','code'],
		'ref($href->{k}) eq "CODE"'      => ['eq','code'],
		'ref($href->{k}) eq ref $y'      => ['eq','ref'],
		'ref($href->{k}) ne "CODE"?1:0'  => ['ne','code'],
		'ref($href->{k})'                => [undef],
	);
	while(my ($code,$expect)=each %tests) { is_deeply([&$decompose($code)],$expect,"decompose:  $code") }
};
subtest 'Valid Ref::Util'=>sub {
	plan tests=>384;
	my $critic=Perl::Critic->new(-profile=>'NONE',-only=>1,-severity=>1);
	$critic->add_policy(-policy=>'Perl::Critic::Policy::References::ProhibitRefChecks');
	foreach my $whitespace ('',' ') {
	foreach my $parens (0,1) {
	foreach my $var ('$var','$array[0]','$hash{key}','$$sref','$$aref[0]','$$href{key}','$aref->[0]','$href->{key}') {
	foreach my $op (' ','!') {
	foreach my $type (qw/is_arrayref is_hashref is_scalarref is_coderef is_globref is_formatref/) {
		my $code=sprintf('%s%s%s%s%s%s'
			,$op
( run in 0.403 second using v1.01-cache-2.11-cpan-c333fce770f )