extra testing for extending create_class_with_roles
Graham Knop [Mon, 15 Jul 2013 00:46:04 +0000 (20:46 -0400)]
t/subclass.t

index 14a4e27..e1fd793 100644 (file)
@@ -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;