use strict;
use warnings;
-use Test::More tests => 91;
+use Test::More;
use Test::Exception;
-
# -------------------------------------------------------------------
# HASH handles
# -------------------------------------------------------------------
has 'foo' => (
is => 'rw',
default => sub { Foo->new },
- handles => { 'foo_bar' => 'bar', foo_baz => 'baz' }
+ handles => {
+ 'foo_bar' => 'bar',
+ foo_baz => 'baz',
+ 'foo_bar_to_20' => [ bar => 20 ],
+ },
);
}
is($bar->foo->bar, 25, '... bar->foo->bar returned the right result');
is($bar->foo_bar, 25, '... and bar->foo_bar delegated correctly again');
+# curried handles
+$bar->foo_bar_to_20;
+is($bar->foo_bar, 20, '... correctly curried a single argument');
+
# -------------------------------------------------------------------
# ARRAY handles
# -------------------------------------------------------------------
handles => 'Foo::Bar',
);
+ package Foo::OtherThing;
+ use Moose;
+ use Moose::Util::TypeConstraints;
+
+ has 'other_thing' => (
+ is => 'rw',
+ isa => 'Foo::Baz',
+ handles => Moose::Util::TypeConstraints::find_type_constraint('Foo::Bar'),
+ );
}
{
is($foo->thing->baz, 'Foo::Baz::BAZ', '... got the right value');
}
+{
+ my $foo = Foo::OtherThing->new(other_thing => Foo::Baz->new);
+ isa_ok($foo, 'Foo::OtherThing');
+ isa_ok($foo->other_thing, 'Foo::Baz');
+
+ ok($foo->meta->has_method('foo'), '... we have the method we expect');
+ ok($foo->meta->has_method('bar'), '... we have the method we expect');
+ ok(!$foo->meta->has_method('baz'), '... we dont have the method we expect');
+
+ is($foo->foo, 'Foo::Baz::FOO', '... got the right value');
+ is($foo->bar, 'Foo::Baz::BAR', '... got the right value');
+ is($foo->other_thing->baz, 'Foo::Baz::BAZ', '... got the right value');
+}
# -------------------------------------------------------------------
# AUTOLOAD & handles
# -------------------------------------------------------------------
my $k = Bar->new(foo => "Foo");
lives_ok { $k->foo_baz } "but not for class name";
}
+
+done_testing;