$obj->mo->super() breaks inside a Try::Tiny block #201

Open
nilsonsfj opened this Issue Jun 15, 2011 · 3 comments

Projects

None yet

3 participants

Well, there's not much to say here besides what's in the subject.

The error message I get is: "Can't locate object method "ANON" via package "My::Package" which seems to indicate that when walking up the call stack, it's getting fooled by something injected by Try::Tiny.

Running Perl 5.10.1, on Windows (Strawberry).

Sample (mostly real) code:

method process_message ($data) {
    try {
        given ( $data->{type} ) {
            when ("connect") {
                # ...
            }
            when ("connect_ok") {
                # ...
            }
            default {
                $self->mo->super( $data );
            }
        };
    }
    catch {
        say "$self - Process Message Error: $_ [closing]";
        $self->close_connection;
    };
}

Is this even fixable?

Contributor
exodist commented Jun 15, 2011

Have you checked to be sure this is a bug in perl5i and not a bug in
Try::Tiny? IE Does your test case fail when run in a test file with
Try::Tiny and no perl5i?

Well, maybe I wasn't clear, but the exception is thrown at the $self->mo->super( $data ) line.

If I don't use the "super" method (i.e. call the superclass method explicitly) it works. If I remove the try/catch blocks it also works.

So the problem is an interaction between Try::Tiny and perl5i. Also I guess GitHub mangled the original error message, turning the placeholder ANON into bold text.

Can't locate object method "__ANON__" via package "My::Package" at My/Package.pm line 62

Where line 62 is the line of the "super" call.

Contributor
schwern commented Jun 15, 2011

On 2011.6.15 2:50 PM, nilsonsfj wrote:

Well, there's not much to say here besides what's in the subject.

The error message I get is: "Can't locate object method "ANON"
via package "My::Package" which seems to indicate that when walking
up the call stack, it's getting fooled by something injected by Try::Tiny.

The problem is that try { ... } is syntactic sugar for try(sub { ... }). That
means super() can't figure out what its supposed to be the super of without
some hairy guessing that I'd rather not add.

Its not fixable without changing how try is implemented, which is desirable as
Try::Tiny has a pile of caveats and we're already using Devel::Declare... but
that's another issue.

However, that error message could be better. super() will normally tell you
that "Foo is not a parent class of Bar" but that isn't triggering for some reason.

  1. I do not have super-powers.
    -- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
    http://skippyslist.com/list/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment