error_tests
Stevan Little [Thu, 13 Apr 2006 20:50:58 +0000 (20:50 +0000)]
lib/Moose/Role.pm
t/007_basic.t
t/043_role_composition_errors.t [new file with mode: 0644]

index afd0a4c..ecc016f 100644 (file)
@@ -109,7 +109,7 @@ Moose::Role - The Moose Role
   use warnings;
   use Moose::Role;
   
-  sub equal { confess "equal must be implemented" }
+  requires 'equal';
   
   sub no_equal { 
       my ($self, $other) = @_;
@@ -150,24 +150,12 @@ Currently, the role support has a number of caveats. They are as follows:
 
 =item *
 
-There is no support for Roles consuming other Roles. The details of this 
-are not totally worked out yet, but it will mostly follow what is set out 
-in the Perl 6 Synopsis 12.
-
-=item *
-
 At this time classes I<can> consume more than one Role, but they are simply 
 applied one after another in the order you ask for them. This is incorrect 
 behavior, the roles should be merged first, and conflicts determined, etc. 
 However, if your roles do not have any conflicts, then things will work just 
 fine.
 
-=item * 
-
-I want to have B<required> methods, which is unlike Perl 6 roles, and more 
-like the original Traits on which roles are based. This would be similar 
-in behavior to L<Class::Trait>. These are not yet implemented or course.
-
 =item *
 
 Roles cannot use the C<extends> keyword, it will throw an exception for now. 
index 90c5ceb..bcafd6b 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 54;
+use Test::More tests => 52;
 use Test::Exception;
 
 BEGIN {
@@ -161,15 +161,3 @@ foreach my $method_name (qw(
                         )) {
     ok($currency_meta->has_method($method_name), '... US::Currency has_method ' . $method_name);
 }
-
-# check some errors
-
-{
-    package Foo;
-    use strict;
-    use warnings;
-    use Moose;
-    ::dies_ok { with('Eq') } '... no equal_to method implemented by Foo';
-    ::dies_ok { with('Ord') } '... no compare method implemented by Foo';    
-}
-
diff --git a/t/043_role_composition_errors.t b/t/043_role_composition_errors.t
new file mode 100644 (file)
index 0000000..09569f9
--- /dev/null
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+use Test::Exception;
+
+BEGIN {  
+    use_ok('Moose');               
+}
+
+{
+    package Foo::Role;
+    use strict;
+    use warnings;
+    use Moose::Role;
+    
+    requires 'foo';
+}
+
+# classes which does not implement required method
+{
+    package Foo::Class;
+    use strict;
+    use warnings;
+    use Moose;
+    
+    ::dies_ok { with('Foo::Role') } '... no foo method implemented by Foo::Class';
+}
+
+# class which does implement required method
+{
+    package Bar::Class;
+    use strict;
+    use warnings;
+    use Moose;
+    
+    ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Class';
+    
+    sub foo { 'Bar::Class::foo' }
+}
+
+# role which does implement required method
+{
+    package Bar::Role;
+    use strict;
+    use warnings;
+    use Moose::Role;
+    
+    ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Role';
+    
+    sub foo { 'Bar::Role::foo' }
+}
+
+# role which does not implement required method
+{
+    package Baz::Role;
+    use strict;
+    use warnings;
+    use Moose;
+    
+    ::dies_ok { with('Foo::Role') } '... no foo method implemented by Baz::Role';
+}
+