blob: 05af63b99fa2b455792751d4e9088af469a29523 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
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);
};
}
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
|