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

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

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

sub add_private_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::Private->wrap(
            name         => $method_name,
            body         => $body,
            package_name => $self->name
        )
    );
    $self->_push_private_method($method_name);
}

1;