From: Graham Knop Date: Mon, 15 Jul 2013 00:46:04 +0000 (-0400) Subject: extra testing for extending create_class_with_roles X-Git-Tag: v1.003000~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d08f8b3a4538da568c97c9ff4af826c8765ca30f;p=gitmo%2FRole-Tiny.git extra testing for extending create_class_with_roles --- diff --git a/t/subclass.t b/t/subclass.t index 14a4e27..e1fd793 100644 --- a/t/subclass.t +++ b/t/subclass.t @@ -60,4 +60,49 @@ $backcompat_called = 0; is $backcompat_called, 0, 'overridden role_application_steps prevents backcompat attempt'; +{ + package RoleExtension3; + use base 'Role::Tiny'; + + sub _composable_package_for { + my ($self, $role) = @_; + my $composed_name = 'Role::Tiny::_COMPOSABLE::'.$role; + return $composed_name if $Role::Tiny::COMPOSED{role}{$composed_name}; + no strict 'refs'; + *{"${composed_name}::extra_sub"} = sub {}; + $self->SUPER::_composable_package_for($role); + } +} + +{ + package Class2; + sub foo {} +} +{ + package Role3; + $INC{'Role3.pm'} = __FILE__; + use Role::Tiny; + requires 'extra_sub'; +} +ok eval { RoleExtension3->create_class_with_roles('Class2', 'Role3') }, + 'requires is satisfied by subs generated by _composable_package_for'; + +{ + package Role4; + $INC{'Role4.pm'} = __FILE__; + use Role::Tiny; + requires 'extra_sub2'; +} +ok !eval { RoleExtension3->create_class_with_roles('Class2', 'Role4'); }, + 'requires checked properly during create_class_with_roles'; + +{ + package Role5; + $INC{'Role5.pm'} = __FILE__; + use Role::Tiny; + around extra_sub2 => sub { my $orig = shift; $orig->(@_); }; +} +ok !eval { RoleExtension3->create_class_with_roles('Class3', 'Role4'); }, + 'requires checked properly during create_class_with_roles'; + done_testing;