Skip Alien-Ditaa
[gitmo/Moose.git] / t / bugs / handles_foreign_class_bug.t
CommitLineData
d022f632 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
b10dde3a 7use Test::Fatal;
d022f632 8
9{
10 package Foo;
11
d03bd989 12 sub new {
13 bless({}, 'Foo')
d022f632 14 }
d03bd989 15
d022f632 16 sub a { 'Foo::a' }
17}
18
19{
20 package Bar;
21 use Moose;
22
b10dde3a 23 ::is( ::exception {
d022f632 24 has 'baz' => (
25 is => 'ro',
26 isa => 'Foo',
27 lazy => 1,
28 default => sub { Foo->new() },
29 handles => qr/^a$/,
30 );
b10dde3a 31 }, undef, '... can create the attribute with delegations' );
d03bd989 32
d022f632 33}
34
35my $bar;
b10dde3a 36is( exception {
d022f632 37 $bar = Bar->new;
b10dde3a 38}, undef, '... created the object ok' );
d022f632 39isa_ok($bar, 'Bar');
40
41is($bar->a, 'Foo::a', '... got the right delgated value');
42
4fe78472 43my @w;
44$SIG{__WARN__} = sub { push @w, "@_" };
d022f632 45{
46 package Baz;
47 use Moose;
48
b10dde3a 49 ::is( ::exception {
d022f632 50 has 'bar' => (
51 is => 'ro',
52 isa => 'Foo',
53 lazy => 1,
54 default => sub { Foo->new() },
55 handles => qr/.*/,
56 );
b10dde3a 57 }, undef, '... can create the attribute with delegations' );
d03bd989 58
d022f632 59}
60
4fe78472 61is(@w, 0, "no warnings");
62
63
d022f632 64my $baz;
b10dde3a 65is( exception {
d022f632 66 $baz = Baz->new;
b10dde3a 67}, undef, '... created the object ok' );
d022f632 68isa_ok($baz, 'Baz');
69
70is($baz->a, 'Foo::a', '... got the right delgated value');
71
72
73
74
75
4fe78472 76@w = ();
77
78{
79 package Blart;
80 use Moose;
81
b10dde3a 82 ::is( ::exception {
4fe78472 83 has 'bar' => (
84 is => 'ro',
85 isa => 'Foo',
86 lazy => 1,
87 default => sub { Foo->new() },
88 handles => [qw(a new)],
89 );
b10dde3a 90 }, undef, '... can create the attribute with delegations' );
d03bd989 91
4fe78472 92}
93
94{
95 local $TODO = "warning not yet implemented";
96
97 is(@w, 1, "one warning");
98 like($w[0], qr/not delegating.*new/i, "warned");
99}
100
101
102
103my $blart;
b10dde3a 104is( exception {
4fe78472 105 $blart = Blart->new;
b10dde3a 106}, undef, '... created the object ok' );
4fe78472 107isa_ok($blart, 'Blart');
d022f632 108
4fe78472 109is($blart->a, 'Foo::a', '... got the right delgated value');
d022f632 110
a28e50e4 111done_testing;