So that we can warn or die with the correct error message. This is required because caller() can't be trusted at compile time.
# define sv_catpvn_nomg sv_catpvn
#endif
+#ifndef mPUSHu
+# define mPUSHu(U) PUSHs(sv_2mortal(newSVuv(U)))
+#endif
+
#ifndef HvNAME_get
# define HvNAME_get(H) HvNAME(H)
#endif
SV *code = indirect_detag(hint);
if (hint) {
+ SV *file;
+ line_t line;
dSP;
+
onamesv = sv_mortalcopy(onamesv);
mnamesv = sv_mortalcopy(mnamesv);
+#ifdef USE_ITHREADS
+ file = newSVpv(CopFILE(&PL_compiling), 0);
+#else
+ file = sv_mortalcopy(CopFILESV(&PL_compiling));
+#endif
+ line = CopLINE(&PL_compiling);
+
ENTER;
SAVETMPS;
PUSHMARK(SP);
- EXTEND(SP, 2);
+ EXTEND(SP, 4);
PUSHs(onamesv);
PUSHs(mnamesv);
+ PUSHs(file);
+ mPUSHu(line);
PUTBACK;
call_sv(code, G_VOID);
=item *
-If the key/value pair C<< hook => $hook >> comes first, C<$hook> will be called for each error with the object name as C<$_[0]> and the method name as C<$_[1]>.
+If the key/value pair C<< hook => $hook >> comes first, C<$hook> will be called for each error with the object name as C<$_[0]>, the method name as C<$_[1]>, the current file as C<$_[2]> and the line number as C<$_[3]>.
=item *
=cut
-my $msg = sub { "Indirect call of method \"$_[1]\" on object \"$_[0]\"" };
+my $msg = sub {
+ "Indirect call of method \"$_[1]\" on object \"$_[0]\" at $_[2] line $_[3].\n"
+};
sub unimport {
shift;
sub expect {
my ($pkg) = @_;
- return qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"/;
+ return qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"\s+at\s+\(eval\s+\d+\)\s+line\s+\d+/;
}
{
my $x = new Hooked;
$x = new AlsoNotReached;
HERE
- is $@, "hook:Hooked:new\n", 'calls the specified hook';
+ like $@, qr/^hook:Hooked:new:\(eval\s+\d+\):\d+$/, 'calls the specified hook';
}
sub expect {
my ($pkg) = @_;
- return qr/^warn:Indirect call of method "(?:new|meh|$pkg$pkg)" on object "(?:$pkg|newnew|\$(?:[xyz_\$]|(?:sploosh::)?sploosh|(?:main::)?bloop))"/
+ qr/^warn:Indirect\s+call\s+of\s+method\s+
+ "(?:new|meh|$pkg$pkg)"
+ \s+on\s+object\s+
+ "(?:$pkg|newnew|\$(?:[xyz_\$]|(?:sploosh::)?sploosh|(?:main::)?bloop))"
+ \s+at\s+\(eval\s+\d+\)\s+line\s+\d+
+ /x
}
{
is($@, "ok\n", "use indirect, defined: $_");
eval "die qq{the code compiled but it shouldn't have\n}; $prefix; no indirect; $_";
- like($@, qr/^warn:Indirect\s+call\s+of\s+method\s+"meh"\s+on\s+object\s+"Dongs"/, "no indirect, defined: $_");
+ like($@, qr/^warn:Indirect\s+call\s+of\s+method\s+"meh"\s+on\s+object\s+"Dongs"\s+at\s+\(eval\s+\d+\)\s+line\s+\d+/, "no indirect, defined: $_");
}
}
}
sub expect {
my ($pkg) = @_;
- return qr/^warn:Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"/;
+ return qr/^warn:Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"\s+at\s+\(eval\s+\d+\)\s+line\s+\d+/;
}
{
sub expect {
my ($pkg) = @_;
- return qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"/;
+ return qr/^Indirect\s+call\s+of\s+method\s+"new"\s+on\s+object\s+"$pkg"\s+at\s+\(eval\s+\d+\)\s+line\s+\d+/;
}
{