diff options
author | doy <doy@tozt.net> | 2009-04-08 02:30:49 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2009-04-08 02:30:49 -0500 |
commit | 2334e70f8fd720328371feea2a024ca904dae36a (patch) | |
tree | ad55309517b94528184e4c41bde9d712dc9e88e7 /t/010-immutable.t | |
parent | 6571e62aa24c76fecc37dc06b6bbd3388792d02a (diff) | |
download | moosex-nonmoose-2334e70f8fd720328371feea2a024ca904dae36a.tar.gz moosex-nonmoose-2334e70f8fd720328371feea2a024ca904dae36a.zip |
add a test for immutability
Diffstat (limited to 't/010-immutable.t')
-rw-r--r-- | t/010-immutable.t | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/t/010-immutable.t b/t/010-immutable.t new file mode 100644 index 0000000..092d58c --- /dev/null +++ b/t/010-immutable.t @@ -0,0 +1,43 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More tests => 6; + +package Foo; + +sub new { + my $class = shift; + bless { @_ }, $class; +} + +sub foo { + my $self = shift; + return $self->{foo} unless @_; + $self->{foo} = shift; +} + +sub baz { 'Foo' } +sub quux { ref(shift) } + +package Foo::Moose; +use Moose; +use MooseX::NonMoose; +extends_nonmoose 'Foo'; + +has bar => ( + is => 'rw', +); + +__PACKAGE__->meta->make_immutable; + +package main; + +my $foo_moose = Foo::Moose->new(foo => 'FOO', bar => 'BAR'); +is $foo_moose->foo, 'FOO', 'foo set in constructor'; +is $foo_moose->bar, 'BAR', 'bar set in constructor'; +$foo_moose->foo('BAZ'); +$foo_moose->bar('QUUX'); +is $foo_moose->foo, 'BAZ', 'foo set by accessor'; +is $foo_moose->bar, 'QUUX', 'bar set by accessor'; +is $foo_moose->baz, 'Foo', 'baz method'; +is $foo_moose->quux, 'Foo::Moose', 'quux method'; |