Privacy.pm

filter: Statementstmt 100% 14 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 3 totaltotal 86.3% 19 / 22 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
private_method
1.0
CRAP 1.0
« Privacy/Meta/Method/Private.pm ↑ Summary Privacy/Meta/Class.pm »
1 package MooseX::Privacy;
2 8 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 $MooseX::Privacy::VERSION = '0.05';
4 }
5  
6 # ABSTRACT: Provides the syntax to restrict/control visibility of your methods
7  
8 8 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 Moose::Exporter->setup_import_methods(
11 with_meta => [qw( private_method protected_method )], );
12  
13 2 ▶sub private_method {
Subroutine private_method: called CC=1 SCAR=0.0
Pod undocumented
14 2 my ( $meta, $name, $body ) = @_;
15 2 $meta->add_private_method($name, $body);
16 }
17  
18 1 ▶sub protected_method {
Subroutine protected_method: called CC=1 SCAR=0.0
Pod undocumented
19 1 my ( $meta, $name, $body ) = @_;
20 1 $meta->add_protected_method($name, $body);
21 }
22  
23 8 ▶sub init_meta {
Subroutine init_meta: called CC=1 SCAR=0.0
Pod undocumented
24 8 my ( $me, %options ) = @_;
25  
26 8 my $for = $options{for_class};
27 8 Moose->init_meta(%options);
28  
29 8 Moose::Util::MetaRole::apply_metaroles(
30 for => $for,
31 class_metaroles => { class => [ 'MooseX::Privacy::Meta::Class', ] },
32 );
33 }
34  
35 8 1;
36  
37  
38 =pod
39  
40 =head1 NAME
41  
42 MooseX::Privacy - Provides the syntax to restrict/control visibility of your methods
43  
44 =head1 VERSION
45  
46 version 0.05
47  
48 =head1 SYNOPSIS
49  
50 use MooseX::Privacy;
51  
52 has config => (
53 is => 'rw',
54 isa => 'Some::Config',
55 traits => [qw/Private/],
56 );
57  
58 has username => (
59 is => 'rw',
60 isa => 'Str',
61 traits => [qw/Protected/],
62 );
63  
64 private_method foo => sub {
65 return 23;
66 };
67  
68 protected_method bar => sub {
69 return 42;
70 };
71  
72 =head1 DESCRIPTION
73  
74 MooseX::Privacy brings the concept of private and protected methods to your class.
75  
76 =head1 METHODS
77  
78 =head2 Private
79  
80 When you declare a method as B<private>, this method can be called only within the class.
81  
82 package Foo;
83  
84 use Moose;
85 use MooseX::Privacy;
86  
87 private_method foo => sub { return 23 };
88  
89 sub mul_by_foo { my $self = shift; $self->foo * $_[0] }
90  
91 1;
92  
93 my $foo = Foo->new;
94 $foo->foo; # die
95 $foo->mul_by_foo; # ok
96  
97 =head2 Protected
98  
99 When you declare a method as B<protected>, this method can be called only
100 within the class AND any of it's subclasses.
101  
102 package Foo;
103  
104 use Moose;
105 use MooseX::Privacy;
106  
107 protected_method foo => sub { return 23 };
108  
109 package Bar;
110  
111 use Moose;
112 extends Foo;
113  
114 sub bar { my $self = shift; $self->foo }
115  
116 1;
117  
118 my $foo = Foo->new;
119 $foo->foo; # die
120 my $bar = Bar->new;
121 $bar->bar; # ok
122  
123 =head2 Attributes
124  
125 =head3 Private
126  
127 When the B<Private> traits is applied to an attribute, this attribute can only be read or set within the class.
128  
129 =head3 Protected
130  
131 When the B<Protected> traits is applied to an attribute, this attribute can only be read or set within the class AND any of his subclasses.
132  
133 =head1 AUTHOR
134  
135 franck cuny <franck@lumberjaph.net>
136  
137 =head1 COPYRIGHT AND LICENSE
138  
139 This software is copyright (c) 2010 by franck cuny.
140  
141 This is free software; you can redistribute it and/or modify it under
142 the same terms as the Perl 5 programming language system itself.
143  
144 =cut
145  
146  
147 __END__
« Privacy/Meta/Method/Private.pm ↑ Summary Privacy/Meta/Class.pm »