summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-02-14 18:00:16 +0100
committerfranck cuny <franck@lumberjaph.net>2010-02-14 18:00:16 +0100
commitce2292a695d6a84bce5692196b79e1ed9c399ad1 (patch)
tree099e7fc614c4777e188e437cd84cebd0d9ae7bdd
parentadd POD (diff)
downloadmoosex-privacy-ce2292a695d6a84bce5692196b79e1ed9c399ad1.tar.gz
add_{private,protected}_method accept a MX::Private::Meta::Method::* instance, POD
-rw-r--r--lib/MooseX/Privacy/Meta/Class/Private.pm65
-rw-r--r--lib/MooseX/Privacy/Meta/Class/Protected.pm63
2 files changed, 90 insertions, 38 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
+
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 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