use warnings;
use Moose::Role;
- sub equal { confess "equal must be implemented" }
+ requires 'equal';
sub no_equal {
my ($self, $other) = @_;
=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.
use strict;
use warnings;
-use Test::More tests => 54;
+use Test::More tests => 52;
use Test::Exception;
BEGIN {
)) {
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';
-}
-
--- /dev/null
+#!/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';
+}
+