File: 003_immutable_n_around.t

package info (click to toggle)
libmoose-perl 1.09-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,004 kB
  • ctags: 1,472
  • sloc: perl: 25,387; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,211 bytes parent folder | download
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
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

# if make_immutable is removed from the following code the tests pass

{
    package Foo;
    use Moose;

    has foo => ( is => "ro" );

    package Bar;
    use Moose;

    extends qw(Foo);

    around new => sub {
        my $next = shift;
        my ( $self, @args ) = @_;
        $self->$next( foo => 42 );
    };

    package Gorch;
    use Moose;

    extends qw(Bar);

    package Zoink;
    use Moose;

    extends qw(Gorch);

}

my @classes = qw(Foo Bar Gorch Zoink);

tests: {
 TODO: {
    is( Foo->new->foo, undef, "base class (" . (Foo->meta->is_immutable ? "immutable" : "mutable") . ")" );
    is( Bar->new->foo, 42, "around new called on Bar->new (" . (Bar->meta->is_immutable ? "immutable" : "mutable") . ")"  );
    is( Gorch->new->foo, 42, "around new called on Gorch->new (" . (Gorch->meta->is_immutable ? "immutable" : "mutable") . ")"  );
    is( Zoink->new->foo, 42, "around new called Zoink->new (" . (Zoink->meta->is_immutable ? "immutable" : "mutable") . ")"  );
    }

    if ( @classes ) {
        local $SIG{__WARN__} = sub {};
        ( shift @classes )->meta->make_immutable;
        redo tests;
    }
}

done_testing;