X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FRole.pm;h=fe42f6f11d6537ff3b972eb67540a67b6a13e5c4;hb=0fa8ff59baf87e6a53f19175ed5869dbc1225128;hp=acf5782ba35e7ba8e28fcb428c961c36e433b22f;hpb=26f0aa174f72fdf5fd803278212b7cefa83c8734;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index acf5782..fe42f6f 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -1,7 +1,7 @@ package Mouse::Role; use Mouse::Exporter; # enables strict and warnings -our $VERSION = '0.77'; +our $VERSION = '0.78'; use Carp qw(confess); use Scalar::Util qw(blessed); @@ -137,12 +137,34 @@ Mouse::Role - The Mouse Role =head1 VERSION -This document describes Mouse version 0.77 +This document describes Mouse version 0.78 =head1 SYNOPSIS - package MyRole; - use Mouse::Role; + package Comparable; + use Mouse::Role; # the package is now a Mouse role + + # Declare methods that are required by this role + requires qw(compare); + + # Define methods this role provides + sub equals { + my($self, $other) = @_; + return $self->compare($other) == 0; + } + + # and later + package MyObject; + use Mouse; + with qw(Comparable); # Now MyObject can equals() + + sub compare { + # ... + } + + my $foo = MyObject->new(); + my $bar = MyObject->new(); + $obj->equals($bar); # yes, it is comparable =head1 KEYWORDS