summaryrefslogtreecommitdiff
path: root/lib/MooseX/Privacy
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-06-19 15:08:47 +0200
committerfranck cuny <franck@lumberjaph.net>2010-06-19 15:08:47 +0200
commiteb479abeb1020be663c471e0df622c9f70f16f20 (patch)
treef55825f7984826d61530bf1d366033a547433c5d /lib/MooseX/Privacy
parentnew role to generate attribute methods (diff)
downloadmoosex-privacy-eb479abeb1020be663c471e0df622c9f70f16f20.tar.gz
use new role to generate method
Diffstat (limited to '')
-rw-r--r--lib/MooseX/Privacy/Meta/Attribute/Private.pm24
-rw-r--r--lib/MooseX/Privacy/Meta/Attribute/Protected.pm26
2 files changed, 13 insertions, 37 deletions
diff --git a/lib/MooseX/Privacy/Meta/Attribute/Private.pm b/lib/MooseX/Privacy/Meta/Attribute/Private.pm
index 241c6fb..b3c7a35 100644
--- a/lib/MooseX/Privacy/Meta/Attribute/Private.pm
+++ b/lib/MooseX/Privacy/Meta/Attribute/Private.pm
@@ -3,24 +3,12 @@ package MooseX::Privacy::Meta::Attribute::Private;
use Moose::Role;
use Carp qw/confess/;
-sub _generate_accessor_method {
- my $self = shift;
- my $attr = $self->associated_attribute;
-
- my $package_name = $attr->associated_class->name;
- my $class = $attr->associated_class->name->meta;
- if ( $class->meta->has_attribute('local_private_attributes') ) {
- $class->_push_private_attribute( $attr->name );
- }
-
- return sub {
- my $self = shift;
- my $caller = ( scalar caller() );
- confess "Attribute " . $attr->name . " is private"
- unless $caller eq $package_name;
- $attr->set_value( $self, $_[0] ) if scalar @_;;
- $attr->get_value($self);
- };
+with 'MooseX::Privacy::Meta::Attribute::Privacy' => {level => 'private'};
+
+sub _check_private {
+ my ($meta, $caller, $attr_name, $package_name) = @_;
+ confess "Attribute " . $attr_name . " is private"
+ unless $caller eq $package_name;
}
1;
diff --git a/lib/MooseX/Privacy/Meta/Attribute/Protected.pm b/lib/MooseX/Privacy/Meta/Attribute/Protected.pm
index 05af63b..b0d57c5 100644
--- a/lib/MooseX/Privacy/Meta/Attribute/Protected.pm
+++ b/lib/MooseX/Privacy/Meta/Attribute/Protected.pm
@@ -3,25 +3,13 @@ package MooseX::Privacy::Meta::Attribute::Protected;
use Moose::Role;
use Carp qw/confess/;
-sub _generate_accessor_method {
- my $self = shift;
- my $attr = $self->associated_attribute;
-
- my $package_name = $attr->associated_class->name;
- my $class = $attr->associated_class->name->meta;
- if ( $class->meta->has_attribute('local_protected_attributes') ) {
- $class->_push_protected_attribute( $attr->name );
- }
-
- return sub {
- my $self = shift;
- my $caller = ( scalar caller() );
- confess "Attribute " . $attr->name . " is protected"
- unless $caller eq $self->meta->name
- or $caller->isa( $package_name );
- $attr->set_value( $self, $_[0] ) if scalar @_;
- $attr->get_value($self);
- };
+with 'MooseX::Privacy::Meta::Attribute::Privacy' => {level => 'protected'};
+
+sub _check_protected {
+ my ($meta, $caller, $attr_name, $package_name, $object_name) = @_;
+ confess "Attribute " . $attr_name . " is protected"
+ unless $caller eq $object_name
+ or $caller->isa($package_name);
}
1;