diff options
author | franck cuny <franck@lumberjaph.net> | 2010-03-04 06:16:58 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-03-04 06:16:58 +0100 |
commit | 5ea3d7d61698e071b8bebfb39ba8eafa9a5e8262 (patch) | |
tree | 4f63475fc53b3411bdc15f0663b34b6e3b93f674 | |
parent | add POD about private and protected traits (diff) | |
download | moosex-privacy-5ea3d7d61698e071b8bebfb39ba8eafa9a5e8262.tar.gz |
rewrite
-rw-r--r-- | lib/MooseX/Privacy/Meta/Attribute/Private.pm | 29 | ||||
-rw-r--r-- | lib/MooseX/Privacy/Meta/Attribute/Protected.pm | 33 |
2 files changed, 59 insertions, 3 deletions
diff --git a/lib/MooseX/Privacy/Meta/Attribute/Private.pm b/lib/MooseX/Privacy/Meta/Attribute/Private.pm index 84f9d4f..e230b40 100644 --- a/lib/MooseX/Privacy/Meta/Attribute/Private.pm +++ b/lib/MooseX/Privacy/Meta/Attribute/Private.pm @@ -2,10 +2,17 @@ package MooseX::Privacy::Meta::Attribute::Private; use Moose::Role; use Carp qw/confess/; +use MooseX::Types::Moose qw/Str ArrayRef/; sub _generate_accessor_method { - my $attr = (shift)->associated_attribute; + 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; @@ -19,3 +26,23 @@ sub _generate_accessor_method { } 1; +__END__ + +=head1 NAME + +MooseX::Privacy::Meta::Attribute::Private + +=head1 SYNOPSIS + +=head1 AUTHOR + +franck cuny E<lt>franck@lumberjaph.netE<gt> + +=head1 SEE ALSO + +=head1 LICENSE + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/lib/MooseX/Privacy/Meta/Attribute/Protected.pm b/lib/MooseX/Privacy/Meta/Attribute/Protected.pm index 408ab50..784f5e4 100644 --- a/lib/MooseX/Privacy/Meta/Attribute/Protected.pm +++ b/lib/MooseX/Privacy/Meta/Attribute/Protected.pm @@ -2,16 +2,24 @@ package MooseX::Privacy::Meta::Attribute::Protected; use Moose::Role; use Carp qw/confess/; +use MooseX::Types::Moose qw/Str ArrayRef/; sub _generate_accessor_method { - my $attr = (shift)->associated_attribute; + 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 $package_name || $caller->isa($package_name); + unless $caller eq $self->meta->name + or $caller->isa( $package_name ); $attr->set_value( $self, $_[0] ) if scalar(@_) == 1; $attr->set_value( $self, [@_] ) if scalar(@_) > 1; $attr->get_value($self); @@ -19,3 +27,24 @@ sub _generate_accessor_method { } 1; + +__END__ + +=head1 NAME + +MooseX::Privacy::Meta::Attribute::Protected + +=head1 SYNOPSIS + +=head1 AUTHOR + +franck cuny E<lt>franck@lumberjaph.netE<gt> + +=head1 SEE ALSO + +=head1 LICENSE + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut |