Posted on 2008-08-11 14:23:23-07 by maqsoum
Moose can't seem to coexist with Error.pm

use Error qw(:try);
use MyExceptionClassDescendentOfErrorSimple;
use Moose;

try {
_CallMethod();
}
catch MyExceptionClassDescendentOfErrorSimple with {
my $ex = shift;
print "ex";
}

This will not compile, if I remove 'use Moose', it works fine. Has anyone used moose with exception another exception handling module ? If moose is a complete object system, it ought to allow the use of an exception mecganism !
Direct Responses: 8536 | Write a response
Posted on 2008-08-11 16:42:50-07 by stvn in response to 8535
Re: Moose can't seem to coexist with Error.pm

I just created this runnable example, and it works just fine on my system (perl 5.8.6, Moose 0.55, Class::MOP 0.64 and Error 0.17015).

#!/usr/bin/perl use strict; use warnings; use Error qw(:try); use Moose; try { throw Error::Simple ("Whoops"); } catch Error::Simple with { my $ex = shift; print "$ex"; }

If you have a more detailed case which exhibits your issue, please submit it in a bug report on rt.cpan.org and we can take a look. It is also helpful if you can include a self-contained runnable example and the actual error you are seeing as well, without these I can only guess as to the problem you are having.

Has anyone used moose with exception another exception handling module ?

Yes, it is used regularly with Exception::Class without issue, and I suspect with Error.pm too, otherwise I am sure someone would have raised the issues before now.

- Stevan

Direct Responses: 9208 | Write a response
Posted on 2008-11-03 21:03:23-08 by bugmenot in response to 8536
Re: Moose can't seem to coexist with Error.pm
Moose doesn't export to main - so that example works. This fails:
package test; use strict; use warnings; use Error qw(:try); use Moose; try { throw Error::Simple ("Whoops"); } catch Error::Simple with { my $ex = shift; print "$ex"; }

with (no pun intended):

Prototype mismatch: sub test::with (&;$) vs none at lib/Sub/Exporter.pm line 896

so the "with"-methods seem to collide.

Direct Responses: 11373 | Write a response
Posted on 2009-08-27 17:49:11-07 by guaguanco in response to 9208
Re: Moose can't seem to coexist with Error.pm
I've confirmed this with the latest versions of Moose and Error:
--------------------------------------------------------------------- #!/usr/bin/perl -w # test-Error1 package Test; use strict; use warnings; use Moose; use Error qw(:try); try { throw_something(); } catch Error::Simple with { my $e = shift; print "caught $e\n"; } otherwise { print "Huh?\n"; }; sub throw_something { throw Error::Simple("Hi!"); } --------------------------------------------------------------------- yields: thiazole:Moose> test-Error1 Subroutine Test::with redefined at ./test-Error1 line 9 Prototype mismatch: sub Test::with: none vs (&;$) at ./test-Error1 line 9 caught Hi! at ./test-Error1 line 28. thiazole:Moose>
Here a workaround (a hack, since it slightly changes the semantics of the Error module, but it works):
--------------------------------------------------------------------------------------- # MooseError.pm BEGIN { use Error qw(:try); my ($pack) = __PACKAGE__; my $oldsym = $pack . '::with'; my $newsym = $pack . '::with_handler'; eval qq { *$newsym = *$oldsym; undef *$oldsym; }; }; 1; --------------------------------------------------------------------- #!/usr/bin/perl -w #test-Error2 package Test; use strict; use warnings; use MooseError; use Moose; try { throw_something(); } catch Error::Simple with_handler { my $e = shift; print "caught $e\n"; } otherwise { print "Huh?\n"; }; sub throw_something { throw Error::Simple("Hi!"); } --------------------------------------------------------------------- thiazole:Moose> test-Error2 caught Hi! at ./test-Error2 line 28. thiazole:Moose>
Direct Responses: 11374 | Write a response
Posted on 2009-08-27 18:43:48-07 by stvn in response to 11373
Re: Moose can't seem to coexist with Error.pm
You can also tell Moose to export with under another name. I do not recall exactly how this is done but Moose just uses Sub::Exporter under the hood so you can likely check those docs.
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.