From: Shawn M Moore Date: Thu, 14 Jun 2012 16:15:50 +0000 (-0500) Subject: First pass at Moose->throw_exception X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=52640601f7e94671c75a230170decc80cfd91d1a;p=gitmo%2FMoose.git First pass at Moose->throw_exception --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 568bdd7..d84217b 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -46,6 +46,27 @@ sub throw_error { goto \&confess } +sub throw_exception { + shift; + + my %args; + if (@_ == 1) { + $args{message} = shift; + } + else { + %args = @_; + } + + my $roles = delete($args{roles}); + + my $metaclass = Moose::Meta::Class->create_anon_class( + superclasses => ['Throwable::Error'], + ($roles ? (roles => $roles) : ()), + ); + + $metaclass->name->throw(\%args); +} + sub extends { my $meta = shift;