[Moose-commits] r7723 - MooseX-Role-Parameterized/trunk/t

phaylon at code2.0beta.co.uk phaylon at code2.0beta.co.uk
Thu Feb 19 00:55:39 GMT 2009


Author: phaylon
Date: 2009-02-18 16:55:39 -0800 (Wed, 18 Feb 2009)
New Revision: 7723

Added:
   MooseX-Role-Parameterized/trunk/t/150-composite-role-application.t
Log:
added tests for composite role application

Added: MooseX-Role-Parameterized/trunk/t/150-composite-role-application.t
===================================================================
--- MooseX-Role-Parameterized/trunk/t/150-composite-role-application.t	                        (rev 0)
+++ MooseX-Role-Parameterized/trunk/t/150-composite-role-application.t	2009-02-19 00:55:39 UTC (rev 7723)
@@ -0,0 +1,126 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Test::More tests => 9;
+
+do {
+    package MyCompositeRoleA;
+    use MooseX::Role::Parameterized;
+
+    parameter attribute => (
+        isa => 'Str',
+        required => 1,
+    );
+
+    role {
+        my $p = shift;
+
+        has $p->attribute => (
+            is => 'Int',
+        );
+    };
+};
+
+do {
+    package MyCompositeRoleB;
+    use MooseX::Role::Parameterized;
+
+    parameter accessor => (
+        isa => 'Str',
+        required => 1,
+    );
+
+    role {
+        my $p = shift;
+
+        has $p->accessor => (
+            is => 'rw',
+            isa => 'Int',
+        );
+    };
+};
+
+do {
+    package MyDoubleConsumer;
+    use Moose;
+    with MyCompositeRoleA => { attribute => 'foo' },
+         MyCompositeRoleB => { accessor  => 'bar' };
+};
+
+local $@;
+eval {
+    ok(MyDoubleConsumer->can('foo'), 'first role in composite applied successfully');
+    ok(MyDoubleConsumer->can('bar'), 'second role in composite applied successfully');
+}; 
+ok !$@, 'testing composite roles lived';
+
+do {
+    package MyExtendingRole;
+    use MooseX::Role::Parameterized;
+
+    parameter foo => (
+        isa => 'Int',
+    );
+
+    role {
+        my $p = shift;
+
+        with 'MyCompositeRoleA', { attribute => 'bar' };
+
+        has foo => (
+            is => 'rw',
+            default => sub { $p->foo },
+        );
+    };
+};
+
+do {
+    package MyExtendedConsumer;
+    use Moose;
+    with MyCompositeRoleA => { attribute => 'bar' },
+         MyExtendingRole  => { foo => 23 };
+};
+
+local $@;
+eval {
+    ok(MyExtendedConsumer->can('bar'), 'role composed through other role applied successfully');
+    is(MyExtendedConsumer->new->foo, 23, 'role composing other role applied successfully');
+};
+ok !$@, 'testing role through application through other role lived';
+
+do {
+    package MyRoleProxy;
+    use MooseX::Role::Parameterized;
+
+    parameter rolename   => (isa => "Str");
+    parameter roleparams => (isa => "HashRef");
+
+    role {
+        my $p = shift;
+
+        with $p->rolename, $p->roleparams;
+    };
+};
+
+do {
+    package MyProxyConsumer;
+    use Moose;
+    with(
+        MyRoleProxy => { 
+            rolename   => 'MyCompositeRoleA',
+            roleparams => { attribute => 'baz' },
+        },
+        MyCompositeRoleB => {
+            accessor => 'qux',
+        },
+    );
+};
+
+local $@;
+eval {
+    ok(MyProxyConsumer->can('baz'), 'proxied role got applied successfully');
+    ok(MyProxyConsumer->can('qux'), 'other role besides proxied one got applied successfully');
+};
+ok !$@, 'testing proxied roles lived';
+




More information about the Moose-commits mailing list