diff options
author | franck cuny <franck@lumberjaph.net> | 2010-04-29 09:34:54 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-04-29 09:34:54 +0200 |
commit | a6ca96e9e0b26761deef4aaee86e928f0e5c393f (patch) | |
tree | 8e4192e274c1a80628cb082c3f0f87f73c6c3ca8 | |
parent | update tests, use with_immutable (diff) | |
download | moosex-privacy-a6ca96e9e0b26761deef4aaee86e928f0e5c393f.tar.gz |
regen README
-rw-r--r-- | README | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/README b/README index 711f5f6..8fa8c9a 100644 --- a/README +++ b/README @@ -3,54 +3,85 @@ NAME your methods SYNOPSIS - use MooseX::Privacy; + use MooseX::Privacy; + + has config => ( + is => 'rw', + isa => 'Some::Config', + traits => [qw/Private/], + ); - private _foo => sub { - return 23; - }; + has username => ( + is => 'rw', + isa => 'Str', + traits => [qw/Protected/], + ); - protected _bar => sub { - return 42; - }; + private_method foo => sub { + return 23; + }; + + protected_method bar => sub { + return 42; + }; DESCRIPTION MooseX::Privacy brings the concept of private and protected methods to your class. +METHODS Private When you declare a method as private, this method can be called only within the class. package Foo; + use Moose; use MooseX::Privacy; - private _foo => sub { return 23 }; - sub foo { my $self = shift; $self->_foo } + + private_method foo => sub { return 23 }; + + sub mul_by_foo { my $self = shift; $self->foo * $_[0] } + 1; my $foo = Foo->new; - $foo->_foo; # die - $foo->foo; # ok + $foo->foo; # die + $foo->mul_by_foo; # ok Protected When you declare a method as protected, this method can be called only within the class AND any of it's subclasses. package Foo; + use Moose; use MooseX::Privacy; - protected _foo => sub { return 23 }; + + protected_method foo => sub { return 23 }; package Bar; + use Moose; extends Foo; - sub foo { my $self = shift; $self->_foo } + + sub bar { my $self = shift; $self->foo } + 1; my $foo = Foo->new; - $foo->_foo; # die + $foo->foo; # die my $bar = Bar->new; - $bar->foo; # ok + $bar->bar; # ok + + Attributes + Private + When the Private traits is applied to an attribute, this attribute can + only be read or set within the class. + + Protected + When the Protected traits is applied to an attribute, this attribute can + only be read or set within the class AND any of his subclasses. AUTHOR franck cuny <franck@lumberjaph.net> |