summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-06-30 11:24:57 +0200
committerfranck cuny <franck@lumberjaph.net>2009-06-30 11:24:57 +0200
commit2cbd7056206d1c0f5b8f9f0ded4cda65ed784cb8 (patch)
tree9dc03b8a57a6dee24629866de30c7cd572087072 /lib
parentinitial commit (diff)
downloadmoosex-methodprivate-2cbd7056206d1c0f5b8f9f0ded4cda65ed784cb8.tar.gz
private and protectd methods and basic tests
Diffstat (limited to 'lib')
-rw-r--r--lib/MooseX/MethodPrivate.pm43
1 files changed, 40 insertions, 3 deletions
diff --git a/lib/MooseX/MethodPrivate.pm b/lib/MooseX/MethodPrivate.pm
index f7801c0..37cce7a 100644
--- a/lib/MooseX/MethodPrivate.pm
+++ b/lib/MooseX/MethodPrivate.pm
@@ -1,9 +1,48 @@
package MooseX::MethodPrivate;
use Moose;
-our $VERSION = '0.01';
+use Moose::Exporter;
+our $VERSION = '0.1.0';
+use Carp qw/croak/;
+
+Moose::Exporter->setup_import_methods(
+ with_caller => [qw( private protected )], );
+
+sub private {
+ my $caller = shift;
+ my $name = shift;
+ my $real_body = shift;
+
+ my $body = sub {
+ croak "The $caller\::$name method is private"
+ unless ( scalar caller() ) eq $caller;
+
+ goto &{$real_body};
+ };
+
+ $caller->meta->add_method( $name, $body );
+}
+
+sub protected {
+ my $caller = shift;
+ my $name = shift;
+ my $real_body = shift;
+
+ my $body = sub {
+ my $new_caller = caller();
+ my @isa = $new_caller->meta->superclasses;
+ my @check = grep {/$caller/} @isa;
+ croak "The $caller\::$name method is protected"
+ unless ( ( scalar caller() ) eq $caller || @check );
+
+ goto &{$real_body};
+ };
+
+ $caller->meta->add_method( $name, $body );
+}
1;
+
__END__
=head1 NAME
@@ -28,5 +67,3 @@ franck cuny E<lt>franck.cuny {at} rtgi.frE<gt>
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
-
-=cut