summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-04-29 14:07:28 +0200
committerfranck cuny <franck@lumberjaph.net>2010-04-29 14:07:28 +0200
commit9877be34968be4bcd831c28d09a96887acc715b9 (patch)
treece7017ec3c01890164eddfb3923778059bab2085
parentupdate makefile (diff)
downloadmoosex-privacy-9877be34968be4bcd831c28d09a96887acc715b9.tar.gz
parameterized role for private and protected trait
-rw-r--r--lib/MooseX/Privacy/Trait/Private.pm11
-rw-r--r--lib/MooseX/Privacy/Trait/Protected.pm11
-rw-r--r--lib/MooseX/Privacy/Trait/Role.pm22
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;