return map {
my ($obj, $meth, $elt) = @$_;
+ $obj = ($obj =~ /^\s*\{/) ? "a block" : "object \"$obj\"";
$self->violation(
- "Indirect call of method \"$meth\" on object \"$obj\"",
+ "Indirect call of method \"$meth\" on $obj",
"You really wanted $obj\->$meth",
$elt,
);
use strict;
use warnings;
-my ($tests, $subtests);
+my ($tests, $reports, $subtests);
BEGIN {
$tests = 15;
+ $reports = 25;
$subtests = 3;
}
-use Test::More tests => $tests + $subtests * 25;
+use Test::More tests => $tests + $subtests * $reports;
use Perl::Critic::TestUtils qw/pcritique_with_violations/;
my $policy = 'Dynamic::NoIndirect';
+sub expect {
+ my ($meth, $obj) = @_;
+ $obj = ($obj =~ /^\s*\{/) ? "a block" : "object \"\Q$obj\E\"";
+ qr/^Indirect call of method \"\Q$meth\E\" on $obj/,
+}
+
{
local $/ = "####";
while (<DATA>) {
s/^\s+//s;
- my ($code, $expected) = split /^-+$/m, $_, 2;
+ my ($code, $expected) = split /^-{4,}$/m, $_, 2;
my @expected = eval $expected;
my @violations = eval { pcritique_with_violations($policy, \$code) };
my $pos = $v->location;
my ($meth, $obj, $line, $col) = @$exp;
- like $v->description,
- qr/^Indirect call of method \"\Q$meth\E\" on object \"\Q$obj\E\"/,
- "description $id";
+ like $v->description, expect($meth, $obj), "description $id";
is $pos->[0], $line, "line $id";
is $pos->[1], $col, "column $id";
}