X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FRole.pm;h=7780471552ff57e0bf77814bc8c827acc6a42a14;hb=f53666627f7096d534a37800283c40901de381e1;hp=b1a40078c0f14a142ec014c890b6d6416694aba3;hpb=32ec255c44d36d63cce20f5e21386d5cd11396b9;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index b1a4007..7780471 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.75'; +our $VERSION = '0.77'; 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.75 +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