diff options
Diffstat (limited to '')
-rw-r--r-- | lib/MooseX/Privacy/Meta/Class/Private.pm | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/lib/MooseX/Privacy/Meta/Class/Private.pm b/lib/MooseX/Privacy/Meta/Class/Private.pm index 0482d08..d63757c 100644 --- a/lib/MooseX/Privacy/Meta/Class/Private.pm +++ b/lib/MooseX/Privacy/Meta/Class/Private.pm @@ -1,7 +1,9 @@ package MooseX::Privacy::Meta::Class::Private; +use Scalar::Util; +use Carp qw/confess/; use Moose::Role; -use MooseX::Types::Moose qw(Str ArrayRef ); +use MooseX::Types::Moose qw/Str ArrayRef/; use MooseX::Privacy::Meta::Method::Private; has local_private_methods => ( @@ -15,24 +17,49 @@ has local_private_methods => ( ); 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); + my ( $self, $method_name, $method ) = @_; + + my $private_method + = blessed $method + ? $method + : MooseX::Privacy::Meta::Method::Private->wrap( + name => $method_name, + package_name => $self->name, + body => $method + ); + + confess 'not a private method' + unless $private_method->isa('MooseX::Privacy::Meta::Method::Private'); + + $self->add_method( $private_method->name, $private_method ); + $self->_push_private_method( $private_method->name ); } 1; +__END__ + +=head1 NAME + +MooseX::Privacy::Meta::Class::Private + +=head1 SYNOPSIS + +=head1 METHODS + +=head2 local_private_methods + +=head2 add_private_method + +=head1 AUTHOR + +franck cuny E<lt>franck@lumberjaph.netE<gt> + +=head1 SEE ALSO + +=head1 LICENSE + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + |