X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FCookbook%2FRoles%2FRecipe3.pod;h=c6faf8e9ab981b8b6fc2f96f0392122bb89c51f4;hb=c79239a22fc3b30cac35dec0d704c7da52872aa5;hp=6e38fd28699f45097c908521c3abc20678a2f3a3;hpb=9a823f268a013ac4b86a27873c49385351a01b08;p=gitmo%2FMoose.git diff --git a/lib/Moose/Cookbook/Roles/Recipe3.pod b/lib/Moose/Cookbook/Roles/Recipe3.pod index 6e38fd2..c6faf8e 100644 --- a/lib/Moose/Cookbook/Roles/Recipe3.pod +++ b/lib/Moose/Cookbook/Roles/Recipe3.pod @@ -1,6 +1,30 @@ +package Moose::Cookbook::Roles::Recipe3; =pod +=begin testing SETUP + +{ + # Not in the recipe, but needed for writing tests. + package Employee; + + use Moose; + + has 'name' => ( + is => 'ro', + isa => 'Str', + required => 1, + ); + + has 'work' => ( + is => 'rw', + isa => 'Str', + predicate => 'has_work', + ); +} + +=end testing + =head1 NAME Moose::Cookbook::Roles::Recipe3 - Applying a role to an object instance @@ -26,7 +50,7 @@ Moose::Cookbook::Roles::Recipe3 - Applying a role to an object instance die 'All my employees have work to do!' unless $employee; - $employee->assign_work($work); + $employee->work($work); } package main; @@ -93,4 +117,27 @@ L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. + +=begin testing + +{ + my $lisa = Employee->new( name => 'Lisa' ); + MyApp::Role::Job::Manager->meta->apply($lisa); + + my $homer = Employee->new( name => 'Homer' ); + my $bart = Employee->new( name => 'Bart' ); + my $marge = Employee->new( name => 'Marge' ); + + $lisa->employees( [ $homer, $bart, $marge ] ); + $lisa->assign_work('mow the lawn'); + + ok( $lisa->does('MyApp::Role::Job::Manager'), + 'lisa now does the manager role' ); + + is( $homer->work, 'mow the lawn', + 'homer was assigned a task by lisa' ); +} + +=end testing + =cut