|
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>
|