pboyd / MooseX-Test-Role

Test functions for Moose roles
2 stars 5 forks source link

add scalars for methods as a shortcut #4

Closed simbabque closed 9 years ago

simbabque commented 9 years ago

If there are a lot of methods (e.g. accessors) in a class that are required in a role and those need to be set over and over when creating a test role-object, one needs to repeat foo => sub { "foo" } a lot. To make that less tedious, it will now check if the thing assigned to a method name is a scalar (not a ref) and in that case wrap it in an anonymous sub. That makes it similar to what Moose does when declaring a scalar as a default value for an attribute.

It will still break when you assign something other than a coderef or a scalar, e.g. a hashref.

pboyd commented 9 years ago

Thanks for the patch. I pushed it out to CPAN just now.