http://www.perlmonks.org?node_id=675049

glide has asked for the wisdom of the Perl Monks concerning the following question:

Hi!

I'm trying to use the Moose with exceptions. But with the Error I'm having problems with conflicting methods.

example:
package MyA; use Moose; use Error qw(:try); 1;
and when I run
perl -e 'use lib $ENV{PWD}; use MyA;' Prototype mismatch: sub MyA::with (@) vs (&;$) at MyA.pm line 4
Any one it's using Moose with exceptions? Witch package do you use?

many thanks

Replies are listed 'Best First'.
Re: Moose and exceptions
by stvn (Monsignor) on Mar 19, 2008 at 19:19 UTC

    This question got answered in #moose on IRC, but just so that Perlmonks has the answer, here you go.

    The conflict is in the Moose export &with and the Error export &with. There are a couple of solutions possible:

    • Since Moose uses Sub::Exporter it is possible to rename &with in the export, like so:
      package Foo::Role; use Moose::Role; package Foo; use Moose with => { -as => "moose_with" }; use Error qw(:try) moose_with("Foo::Role"); Foo->does("Foo::Role") # returns true
    • Or, use a different Exception module, Exception::Class is an excellent choice and known to work work just fine with Moose.

    -stvn

      It's nice to see the flexibility of the Moose. But, imho, that kind of change in the interface, will affect the maintainability of the code.

      Probably the use of the Exception::Class will be a better approach.

      many thanks
        It's nice to see the flexibility of the Moose.

        I can take no credit, we are simply riding on the shoulders of Sub::Exporter.

        But, imho, that kind of change in the interface, will affect the maintainability of the code.

        I completely agree, this is a case of "just cause you can do it, doesn't mean you should".

        -stvn