Skip to content

Commit

Permalink
Error location detection with Moo needed changing
Browse files Browse the repository at this point in the history
Newer versions of Moo (see below) put the contructor into the
appropriate package, and don't leave it as part of
"Method::Generate::Constructor", so testing for that package no longer
works.

Instead test for package /^\(eval \d+\)$/ and (eval) as the sub, and
if so, $level++.

The change in Moo that broke the previous fix was:

    commit 84b6760de8224ee3a020207e08c22810530e417e
    Author: Graham Knop <haarg@haarg.org>
    Date:   Thu Apr 14 16:50:30 2016 -0400

        fix croak location for inlined BUILDARGS

included in versions 2.002 or newer.
  • Loading branch information
pmorch committed Nov 29, 2016
1 parent e423d71 commit 0122bc9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/Error/TypeTiny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ sub throw
my ($pkg, $func) = ($1 =~ m{^(.+)::(\w+)$});
$level++ if caller($level) eq ($pkg||"");
}
# Moo's Method::Generate::Constructor puts an eval in the stack trace,
# that is useless for debugging, so show the stack frame one above.
$level++
if (
caller($level) eq "Method::Generate::Constructor" &&
(caller($level))[1] =~ /\(eval \d+\)/
(caller($level))[1] =~ /^\(eval \d+\)$/ &&
# (caller())[3] is $subroutine
(caller($level))[3] eq '(eval)'
);
@ctxt{qw/ package file line /} = caller($level);

Expand Down

0 comments on commit 0122bc9

Please sign in to comment.