From: Graham Knop Date: Fri, 30 Mar 2012 20:36:43 +0000 (-0400) Subject: fix error propagation when creating broken method modifiers X-Git-Tag: v1.000_900~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=385f50873b724645e2fea1da9d53baea5f6d782c;p=gitmo%2FRole-Tiny.git fix error propagation when creating broken method modifiers --- diff --git a/lib/Role/Tiny.pm b/lib/Role/Tiny.pm index e484c92..8ddc074 100644 --- a/lib/Role/Tiny.pm +++ b/lib/Role/Tiny.pm @@ -158,11 +158,13 @@ sub _composable_package_for { ) { push @mod_base, "sub ${modified} { shift->next::method(\@_) }"; } + my $e; { local $@; eval(my $code = join "\n", "package ${base_name};", @mod_base); - die "Evaling failed: $@\nTrying to eval:\n${code}" if $@; + $e = "Evaling failed: $@\nTrying to eval:\n${code}" if $@; } + die $e if $e; $me->_install_modifiers($composed_name, $modifiers); $COMPOSED{role}{$composed_name} = 1; return $composed_name; diff --git a/t/role-tiny.t b/t/role-tiny.t index fdc23fd..db84ada 100644 --- a/t/role-tiny.t +++ b/t/role-tiny.t @@ -61,6 +61,13 @@ BEGIN { sub extra1 { 'role extra' } } +BEGIN { + package BrokenRole; + use Role::Tiny; + + around 'broken modifier' => sub { my $orig = shift; $orig->(@_) }; +} + sub try_apply_to { my $to = shift; exception { Role::Tiny->apply_role_to_package($to, 'MyRole') } @@ -95,5 +102,9 @@ is exception { isa_ok($new_class, 'MyClass'); is($new_class->extra1, 'role extra', 'method from role'); +ok(exception { + $new_class = Role::Tiny->create_class_with_roles('MyClass', 'BrokenRole'); +}, 'exception caught creating class with broken modifier in a role'); + done_testing;