From ce2292a695d6a84bce5692196b79e1ed9c399ad1 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Sun, 14 Feb 2010 18:00:16 +0100 Subject: add_{private,protected}_method accept a MX::Private::Meta::Method::* instance, POD --- lib/MooseX/Privacy/Meta/Class/Private.pm | 65 +++++++++++++++++++++--------- lib/MooseX/Privacy/Meta/Class/Protected.pm | 63 ++++++++++++++++++++--------- 2 files changed, 90 insertions(+), 38 deletions(-) (limited to 'lib/MooseX') 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 Efranck@lumberjaph.netE + +=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 + diff --git a/lib/MooseX/Privacy/Meta/Class/Protected.pm b/lib/MooseX/Privacy/Meta/Class/Protected.pm index 3b80010..f7b72ee 100644 --- a/lib/MooseX/Privacy/Meta/Class/Protected.pm +++ b/lib/MooseX/Privacy/Meta/Class/Protected.pm @@ -1,7 +1,9 @@ package MooseX::Privacy::Meta::Class::Protected; +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::Protected; has local_protected_methods => ( @@ -15,26 +17,49 @@ has local_protected_methods => ( ); 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); + my ( $self, $method_name, $method ) = @_; + + my $protected_method + = blessed $method + ? $method + : MooseX::Privacy::Meta::Method::Protected->wrap( + name => $method_name, + package_name => $self->name, + body => $method + ); + + confess $method_name . " is not a protected method" + unless $protected_method->isa( + 'MooseX::Privacy::Meta::Method::Protected'); + + $self->add_method( $protected_method->name, $protected_method ); + $self->_push_protected_method( $protected_method->name ); } 1; +__END__ + +=head1 NAME + +MooseX::Privacy::Meta::Class::Protected + +=head1 SYNOPSIS + +=head1 METHODS + +=head2 local_protected_methods + +=head2 add_protected_method + +=head1 AUTHOR + +franck cuny Efranck@lumberjaph.netE + +=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 -- cgit 1.4.1