diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-05-07 18:36:35 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-05-07 18:36:35 -0500 |
commit | 4352309685f8fbbb052ee628dc0cd8c299575f2d (patch) | |
tree | 4f5212dfefe9fa65871c72d21581711ce93077d7 /t | |
parent | 234e6a77e247f9e9ccb933588b0405846bbf8d7f (diff) | |
download | moosex-nonmoose-4352309685f8fbbb052ee628dc0cd8c299575f2d.tar.gz moosex-nonmoose-4352309685f8fbbb052ee628dc0cd8c299575f2d.zip |
basic test for non-hashref base class instances (with MX-InsideOut)
Diffstat (limited to 't')
-rw-r--r-- | t/032-moosex-insideout.t | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/t/032-moosex-insideout.t b/t/032-moosex-insideout.t new file mode 100644 index 0000000..6d3f60e --- /dev/null +++ b/t/032-moosex-insideout.t @@ -0,0 +1,65 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +BEGIN { + eval "use MooseX::InsideOut ()"; + plan skip_all => "MooseX::InsideOut is required for this test" if $@; + plan tests => 2; +} + +BEGIN { + require Moose; + + package Foo::Exporter; + use Moose::Exporter; + Moose::Exporter->setup_import_methods(also => ['Moose']); + + sub init_meta { + shift; + my %options = @_; + Moose->init_meta(%options); + Moose::Util::MetaRole::apply_metaclass_roles( + for_class => $options{for_class}, + metaclass_roles => ['MooseX::NonMoose::Meta::Role::Class'], + constructor_class_roles => + ['MooseX::NonMoose::Meta::Role::Constructor'], + instance_metaclass_roles => + ['MooseX::InsideOut::Role::Meta::Instance'], + ); + return Class::MOP::class_of($options{for_class}); + } +} + +package Foo; + +sub new { + my $class = shift; + bless [$_[0]], $class; +} + +sub foo { + my $self = shift; + $self->[0] = shift if @_; + $self->[0]; +} + +package Foo::Moose; +BEGIN { Foo::Exporter->import } +extends 'Foo'; + +has bar => ( + is => 'rw', + isa => 'Str', +); + +sub BUILDARGS { + my $self = shift; + shift; + return $self->SUPER::BUILDARGS(@_); +} + +package main; +my $foo = Foo::Moose->new('FOO', bar => 'BAR'); +is($foo->foo, 'FOO', 'base class accessor works'); +is($foo->bar, 'BAR', 'subclass accessor works'); |