Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Moose and exceptions

by glide (Pilgrim)
on Mar 19, 2008 at 18:19 UTC ( #675049=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on Moose and exceptions
Select or Download Code
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://675049]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-04-20 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (488 votes), past polls