From: Fuji, Goro Date: Thu, 30 Sep 2010 02:38:37 +0000 (+0900) Subject: Update SYNOPSIS of Mouse::Role, urged by ADAMK (RT #61782) X-Git-Tag: 0.78~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=f53666627f7096d534a37800283c40901de381e1 Update SYNOPSIS of Mouse::Role, urged by ADAMK (RT #61782) --- diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index acf5782..7780471 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -141,8 +141,30 @@ This document describes Mouse version 0.77 =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