blob: 711f5f6e8f73e3ac3d4acc59717730eb4b657687 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
NAME
MooseX::Privacy - Provides the syntax to restrict/control visibility of
your methods
SYNOPSIS
use MooseX::Privacy;
private _foo => sub {
return 23;
};
protected _bar => sub {
return 42;
};
DESCRIPTION
MooseX::Privacy brings the concept of private and protected methods to
your class.
Private
When you declare a method as private, this method can be called only
within the class.
package Foo;
use Moose;
use MooseX::Privacy;
private _foo => sub { return 23 };
sub foo { my $self = shift; $self->_foo }
1;
my $foo = Foo->new;
$foo->_foo; # die
$foo->foo; # ok
Protected
When you declare a method as protected, this method can be called only
within the class AND any of it's subclasses.
package Foo;
use Moose;
use MooseX::Privacy;
protected _foo => sub { return 23 };
package Bar;
use Moose;
extends Foo;
sub foo { my $self = shift; $self->_foo }
1;
my $foo = Foo->new;
$foo->_foo; # die
my $bar = Bar->new;
$bar->foo; # ok
AUTHOR
franck cuny <franck@lumberjaph.net>
SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
|