summaryrefslogtreecommitdiff
path: root/lib/MooseX/Privacy/Meta/Class/Protected.pm
blob: 3b80010f7fbfd874ed7f3d907ee927561311fade (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
package MooseX::Privacy::Meta::Class::Protected;

use Moose::Role;
use MooseX::Types::Moose qw(Str ArrayRef );
use MooseX::Privacy::Meta::Method::Protected;

has local_protected_methods => (
    traits     => ['Array'],
    is         => 'ro',
    isa        => ArrayRef [Str],
    required   => 1,
    default    => sub { [] },
    auto_deref => 1,
    handles    => { '_push_protected_method' => 'push' },
);

sub add_protected_method {
    my $self = shift;
    my ( $method_name, $body );
    if ( scalar @_ == 1 ) {
        $method_name = $_[0]->name;
        $body        = $_[0]->body;
    }
    else {
        ($method_name, $body) = @_;
    }
    $self->add_method(
        $method_name,
        MooseX::Privacy::Meta::Method::Protected->wrap(
            name         => $method_name,
            body         => $body,
            package_name => $self->name
        )
    );
    $self->_push_protected_method($method_name);
}

1;