summaryrefslogtreecommitdiffstats
path: root/t/10-immutable.t
blob: 275b3872725d10200bcc28f8ac2170ab0614d6a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

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 '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');

done_testing;