summary refs log tree commit diff
path: root/t/11_protected_method.t
blob: dca817635068c874c034daa3764f5273acca88a6 (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
use strict;
use warnings;

use Test::More tests => 10;
use Test::Exception;
use Test::Moose;

{

    package Foo;
    use Moose;
    use MooseX::Privacy;

    protected_method 'bar' => sub {
        my $self = shift;
        return 'baz';
    };
}

{

    package Bar;
    use Moose;
    extends 'Foo';

    sub baz {
        my $self = shift;
        return $self->bar;
    }
}

with_immutable {
    my $foo = Foo->new();
    isa_ok( $foo, 'Foo' );
    dies_ok { $foo->bar } "... can't call bar, method is protected";

    my $bar = Bar->new();
    isa_ok( $bar, 'Bar' );
    is $bar->baz(), 'baz', "... got the good value from &bar";

    is $foo->meta->_count_protected_methods, 1, "... got one protected method";
}
(qw/Foo Bar/);