From: Shawn M Moore Date: Wed, 26 Nov 2008 04:19:45 +0000 (+0000) Subject: Make sure we can pass references to roles X-Git-Tag: 0.05~62 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dc0320140b18124b5548a05507a4854413330b62;p=gitmo%2FMooseX-Role-Parameterized.git Make sure we can pass references to roles --- diff --git a/t/011-reference-parameters.t b/t/011-reference-parameters.t new file mode 100644 index 0000000..313396b --- /dev/null +++ b/t/011-reference-parameters.t @@ -0,0 +1,77 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 8; + +do { + package MyRole::Delegator; + use MooseX::Role::Parameterized; + + parameter handles => ( + is => 'rw', + required => 1, + ); + + role { + my $p = shift; + + has attr => ( + is => 'rw', + isa => 'MyClass::WithMethods', + handles => $p->handles, + ); + }; +}; + +do { + package MyClass::WithMethods; + + sub foo { "foo" } + sub bar { "bar" } + sub baz { "baz" } +}; + +do { + package MyArrayConsumer; + use Moose; + with 'MyRole::Delegator' => { + handles => ['foo', 'bar'], + }; +}; + +can_ok(MyArrayConsumer => 'foo', 'bar'); +cant_ok(MyArrayConsumer => 'baz'); + +do { + package MyRegexConsumer; + use Moose; + with 'MyRole::Delegator' => { + handles => qr/^ba/, + }; +}; + +can_ok(MyRegexConsumer => 'bar', 'baz'); +cant_ok(MyRegexConsumer => 'foo'); + +do { + package MyHashConsumer; + use Moose; + with 'MyRole::Delegator' => { + handles => { + my_foo => 'foo', + his_baz => 'baz', + }, + }; +}; + +can_ok(MyHashConsumer => 'my_foo', 'his_baz'); +cant_ok(MyHashConsumer => qw/foo bar baz/); + +sub cant_ok { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my $instance = shift; + for my $method (@_) { + ok(!$instance->can($method), "$instance cannot $method"); + } +} +