diff options
author | franck cuny <franck@lumberjaph.net> | 2010-04-29 14:07:28 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-04-29 14:07:28 +0200 |
commit | 9877be34968be4bcd831c28d09a96887acc715b9 (patch) | |
tree | ce7017ec3c01890164eddfb3923778059bab2085 | |
parent | update makefile (diff) | |
download | moosex-privacy-9877be34968be4bcd831c28d09a96887acc715b9.tar.gz |
parameterized role for private and protected trait
-rw-r--r-- | lib/MooseX/Privacy/Trait/Private.pm | 11 | ||||
-rw-r--r-- | lib/MooseX/Privacy/Trait/Protected.pm | 11 | ||||
-rw-r--r-- | lib/MooseX/Privacy/Trait/Role.pm | 22 |
3 files changed, 24 insertions, 20 deletions
diff --git a/lib/MooseX/Privacy/Trait/Private.pm b/lib/MooseX/Privacy/Trait/Private.pm index 8fca8b9..9f5eeb9 100644 --- a/lib/MooseX/Privacy/Trait/Private.pm +++ b/lib/MooseX/Privacy/Trait/Private.pm @@ -1,16 +1,7 @@ package MooseX::Privacy::Trait::Private; use Moose::Role; - -around accessor_metaclass => sub { - my ( $orig, $self, @rest ) = @_; - - return Moose::Meta::Class->create_anon_class( - superclasses => [ $self->$orig(@_) ], - roles => ['MooseX::Privacy::Meta::Attribute::Private'], - cache => 1 - )->name; -}; +with 'MooseX::Privacy::Trait::Role' => {name => 'private'}; 1; diff --git a/lib/MooseX/Privacy/Trait/Protected.pm b/lib/MooseX/Privacy/Trait/Protected.pm index eaaf10b..0c49719 100644 --- a/lib/MooseX/Privacy/Trait/Protected.pm +++ b/lib/MooseX/Privacy/Trait/Protected.pm @@ -1,16 +1,7 @@ package MooseX::Privacy::Trait::Protected; use Moose::Role; - -around accessor_metaclass => sub { - my ( $orig, $self, @rest ) = @_; - - return Moose::Meta::Class->create_anon_class( - superclasses => [ $self->$orig(@_) ], - roles => ['MooseX::Privacy::Meta::Attribute::Protected'], - cache => 1 - )->name; -}; +with 'MooseX::Privacy::Trait::Role' => {name => 'protected'}; 1; diff --git a/lib/MooseX/Privacy/Trait/Role.pm b/lib/MooseX/Privacy/Trait/Role.pm new file mode 100644 index 0000000..9d8c274 --- /dev/null +++ b/lib/MooseX/Privacy/Trait/Role.pm @@ -0,0 +1,22 @@ +package MooseX::Privacy::Trait::Role; + +use MooseX::Role::Parameterized; + +parameter name => ( isa => 'Str', required => 1, ); + +role { + my $p = shift; + my $role_name = "MooseX::Privacy::Meta::Attribute::" . ucfirst($p->name); + + around accessor_metaclass => sub { + my ( $orig, $self, @rest ) = @_; + + return Moose::Meta::Class->create_anon_class( + superclasses => [ $self->$orig(@_) ], + roles => [$role_name], + cache => 1 + )->name; + }; +}; + +1; |