diff options
Diffstat (limited to 't/infer-subclasses.t')
-rw-r--r-- | t/infer-subclasses.t | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/t/infer-subclasses.t b/t/infer-subclasses.t new file mode 100644 index 0000000..b50b909 --- /dev/null +++ b/t/infer-subclasses.t @@ -0,0 +1,100 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +{ + package NonMoose; + sub new { bless { data => $_[0] }, shift } +} + +{ + package Foo; + use Moose; + + has non_moose => ( + is => 'ro', + isa => 'NonMoose', + required => 1, + ); +} + +{ + package Bar; + use Moose; + + has foo => ( + is => 'ro', + isa => 'Foo', + required => 1, + ); +} + +{ + package Container; + use Moose; + use Bread::Board::Declare; + + has non_moose => ( + is => 'ro', + isa => 'NonMoose', + block => sub { NonMoose->new("blah") }, + ); + + has foo => ( + is => 'ro', + isa => 'Foo', + dependencies => ['non_moose'], + ); + + has bar => ( + is => 'ro', + isa => 'Bar', + infer => 1, + ); +} + +{ + my $c = Container->new; + my $bar = $c->bar; + isa_ok($bar->foo->non_moose, 'NonMoose'); +} + +{ + package Foo::Sub; + use Moose; + + extends 'Foo'; +} + +{ + package Container2; + use Moose; + use Bread::Board::Declare; + + has non_moose => ( + is => 'ro', + isa => 'NonMoose', + block => sub { NonMoose->new("blah") }, + ); + + has foo => ( + is => 'ro', + isa => 'Foo::Sub', + dependencies => ['non_moose'], + ); + + has bar => ( + is => 'ro', + isa => 'Bar', + infer => 1, + ); +} + +{ + my $c = Container2->new; + my $bar = $c->bar; + isa_ok($bar->foo->non_moose, 'NonMoose'); +} + +done_testing; |