line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::FunkyAttributes::Role::Attribute::InsideOut; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
5092
|
use 5.008; |
|
6
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
231
|
|
4
|
6
|
|
|
6
|
|
35
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
213
|
|
5
|
6
|
|
|
6
|
|
180
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
344
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
6
|
|
|
6
|
|
23
|
$MooseX::FunkyAttributes::Role::Attribute::InsideOut::AUTHORITY = 'cpan:TOBYINK'; |
9
|
6
|
|
|
|
|
108
|
$MooseX::FunkyAttributes::Role::Attribute::InsideOut::VERSION = '0.003'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
5699
|
use Hash::FieldHash (); |
|
6
|
|
|
|
|
5081
|
|
|
6
|
|
|
|
|
152
|
|
13
|
6
|
|
|
6
|
|
41
|
use Scalar::Util (); |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
101
|
|
14
|
6
|
|
|
6
|
|
30
|
use Moose::Role; |
|
6
|
|
|
|
|
29
|
|
|
6
|
|
|
|
|
58
|
|
15
|
6
|
|
|
6
|
|
41906
|
use namespace::autoclean; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
59
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
with qw(MooseX::FunkyAttributes::Role::Attribute); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @_HASHES; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $i = 0; |
22
|
|
|
|
|
|
|
before _process_options => sub |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
my ($class, $name, $options) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $hashcount = $i++; |
27
|
|
|
|
|
|
|
Hash::FieldHash::fieldhash my %h; |
28
|
|
|
|
|
|
|
$_HASHES[$hashcount] = \%h; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$options->{custom_get} = sub { $h{ $_[1] } }; |
31
|
|
|
|
|
|
|
$options->{custom_set} = sub { $h{ $_[1] } = $_[2] }; |
32
|
|
|
|
|
|
|
$options->{custom_has} = sub { exists $h{ $_[1] } }; |
33
|
|
|
|
|
|
|
$options->{custom_clear} = sub { delete $h{ $_[1] } }; |
34
|
|
|
|
|
|
|
$options->{custom_weaken} = sub { Scalar::Util::weaken( $h{ $_[1] } ) }; |
35
|
|
|
|
|
|
|
$options->{custom_init} = sub { $h{ $_[1] } = $_[2] }; |
36
|
|
|
|
|
|
|
$options->{custom_inline_get} = sub { my ($self, $inst) = @_; qq(\$MooseX::FunkyAttributes::Role::Attribute::InsideOut::_HASHES[$hashcount]{$inst}) }; |
37
|
|
|
|
|
|
|
$options->{custom_inline_set} = sub { my ($self, $inst, $val) = @_; qq(\$MooseX::FunkyAttributes::Role::Attribute::InsideOut::_HASHES[$hashcount]{$inst} = $val) }; |
38
|
|
|
|
|
|
|
$options->{custom_inline_weaken} = sub { my ($self, $inst) = @_; qq(Scalar::Util::weaken \$MooseX::FunkyAttributes::Role::Attribute::InsideOut::_HASHES[$hashcount]{$inst}) }; |
39
|
|
|
|
|
|
|
$options->{custom_inline_has} = sub { my ($self, $inst) = @_; qq(exists \$MooseX::FunkyAttributes::Role::Attribute::InsideOut::_HASHES[$hashcount]{$inst}) }; |
40
|
|
|
|
|
|
|
$options->{custom_inline_clear} = sub { my ($self, $inst) = @_; qq(delete \$MooseX::FunkyAttributes::Role::Attribute::InsideOut::_HASHES[$hashcount]{$inst}) }; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
MooseX::FunkyAttributes::Role::Attribute::InsideOut - an inside-out attribute |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
package Person; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Moose; |
56
|
|
|
|
|
|
|
use MooseX::FunkyAttributes; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
has name => ( |
59
|
|
|
|
|
|
|
traits => [ InsideOutAttribute ], |
60
|
|
|
|
|
|
|
is => 'ro', |
61
|
|
|
|
|
|
|
isa => 'Str', |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has age => ( |
65
|
|
|
|
|
|
|
is => 'ro', |
66
|
|
|
|
|
|
|
isa => 'Num', |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
package main; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use feature 'say'; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $bob = Person->new(name => 'Bob', age => 32); |
74
|
|
|
|
|
|
|
say $bob->name; # Bob |
75
|
|
|
|
|
|
|
say $bob->dump; # $VAR1 = bless({ age => 32 }, 'Person'); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This trait implements the "inside-out" technique for Moose attributes. Unlike |
80
|
|
|
|
|
|
|
L<MooseX::InsideOut> it doesn't make all attributes in the class inside-out; |
81
|
|
|
|
|
|
|
just the attribute(s) it is applied to. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
One situation where you might want to do this is to hide certain attributes |
84
|
|
|
|
|
|
|
from dumps. For example, a "password" attribute that you don't want to appear |
85
|
|
|
|
|
|
|
in log files, or an attribute which contains a large chunk of textual data or |
86
|
|
|
|
|
|
|
a deeply nested data structure which makes the logs less readable. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This trait inherits from L<MooseX::FunkyAttributes::Role::Attribute>, but |
89
|
|
|
|
|
|
|
forget about most of what you read in the documentaton for that trait. Those |
90
|
|
|
|
|
|
|
C<custom_set>, C<custom_get>, C<custom_inline_set>, etc options are all |
91
|
|
|
|
|
|
|
automatically generated for you. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 BUGS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Please report any bugs to |
96
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=MooseX-FunkyAttributes>. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SEE ALSO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L<MooseX::FunkyAttributes>, L<MooseX::InsideOut>, L<Hash::FieldHash>. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This software is copyright (c) 2012-2014 by Toby Inkster. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
111
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
116
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
117
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
118
|
|
|
|
|
|
|
|