| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# This file is part of MooseX-AutoDestruct |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# This software is Copyright (c) 2011 by Chris Weyl. |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# This is free software, licensed under: |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# The GNU Lesser General Public License, Version 2.1, February 1999 |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
package MooseX::AutoDestruct; |
|
11
|
|
|
|
|
|
|
{ |
|
12
|
|
|
|
|
|
|
$MooseX::AutoDestruct::VERSION = '0.009'; |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ABSTRACT: Clear your attributes after a certain time |
|
16
|
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
1087784
|
use warnings; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
77
|
|
|
18
|
2
|
|
|
2
|
|
11
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
73
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
1736
|
use namespace::autoclean; |
|
|
2
|
|
|
|
|
3301
|
|
|
|
2
|
|
|
|
|
13
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
116
|
use Moose (); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
36
|
|
|
23
|
2
|
|
|
2
|
|
11
|
use Moose::Exporter; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
23
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $implementation; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
{ |
|
28
|
|
|
|
|
|
|
my $moose_version = Moose->VERSION; |
|
29
|
|
|
|
|
|
|
$implementation |
|
30
|
|
|
|
|
|
|
= $moose_version < 1.99 |
|
31
|
|
|
|
|
|
|
? 'MooseX::AutoDestruct::V1' |
|
32
|
|
|
|
|
|
|
: 'MooseX::AutoDestruct::V2' |
|
33
|
|
|
|
|
|
|
; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
($moose_version > 2.99) && warn |
|
36
|
|
|
|
|
|
|
"This is Moose $moose_version, but I only know how to deal with 2.x at most!\n", |
|
37
|
|
|
|
|
|
|
"We're going to try using the v2 AutoDestruct traits, but YMMV.\n", |
|
38
|
|
|
|
|
|
|
; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
0
|
0
|
0
|
sub implementation { $implementation } |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
|
44
|
|
|
|
|
|
|
trait_aliases => [ |
|
45
|
|
|
|
|
|
|
[ "${implementation}::Trait::Attribute" => 'AutoDestruct' ], |
|
46
|
|
|
|
|
|
|
], |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# debugging |
|
50
|
|
|
|
|
|
|
#use Smart::Comments '###', '####'; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
{ |
|
53
|
|
|
|
|
|
|
package Moose::Meta::Attribute::Custom::Trait::AutoDestruct; |
|
54
|
|
|
|
|
|
|
{ |
|
55
|
|
|
|
|
|
|
$Moose::Meta::Attribute::Custom::Trait::AutoDestruct::VERSION = '0.009'; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
2
|
|
|
2
|
|
10294
|
sub register_implementation { "${implementation}::Trait::Attribute" } |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
!!42; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=pod |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
MooseX::AutoDestruct - Clear your attributes after a certain time |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 VERSION |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
version 0.009 |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
package Foo; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
use Moose; |
|
79
|
|
|
|
|
|
|
use namespace::autoclean; |
|
80
|
|
|
|
|
|
|
use MooseX::AutoDestruct; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
has foo => ( |
|
83
|
|
|
|
|
|
|
traits => [ AutoDestruct ], |
|
84
|
|
|
|
|
|
|
is => 'ro', |
|
85
|
|
|
|
|
|
|
isa => 'Str', |
|
86
|
|
|
|
|
|
|
lazy_build => 1, |
|
87
|
|
|
|
|
|
|
ttl => 600, # time, in seconds |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _build_foo { --some expensive operation-- } |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
MooseX::AutoDestruct is an attribute metaclass trait that causes your |
|
95
|
|
|
|
|
|
|
attribute value to be cleared after a certain time from when the value has |
|
96
|
|
|
|
|
|
|
been set. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This trait will work regardless of how the value is populated or if a clearer |
|
99
|
|
|
|
|
|
|
method has been installed; or if the value is accessed via the installed |
|
100
|
|
|
|
|
|
|
accessors or by accessing the attribute metaclass itself. |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=for Pod::Coverage implementation |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 TRAITS APPLIED |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
No traits are automatically applied to any metaclasses; however, on use'ing |
|
107
|
|
|
|
|
|
|
this package an 'AutoDestruct' attribute trait becomes available. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Moose will properly deduce what trait you're talking about if you pass |
|
110
|
|
|
|
|
|
|
AutoDestruct as a string -- e.g.: |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
has foo => (traits => [ 'AutoDestruct' ], ...) |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
However, this is depreciated in favor of the exported trait alias: |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
has foo => (traits => [ AutoDestruct ], ...) |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 USAGE |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Apply the AutoDestruct trait to your attribute metaclass (e.g. "traits => |
|
121
|
|
|
|
|
|
|
[AutoDestruct]") and supply a ttl value. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Typical usage of this could be for an attribute to store a value that is |
|
124
|
|
|
|
|
|
|
expensive to calculate, and can be counted on to be valid for a certain amount |
|
125
|
|
|
|
|
|
|
of time (e.g. caching). Builders are your friends :) |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L<Moose>. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 BUGS |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
134
|
|
|
|
|
|
|
C<bug-moosex-autodestruct at rt.cpan.org>, or through |
|
135
|
|
|
|
|
|
|
the web interface at |
|
136
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-AutoDestruct>. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 AUTHOR |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Chris Weyl <cweyl@alumni.drew.edu> |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This software is Copyright (c) 2011 by Chris Weyl. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This is free software, licensed under: |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
The GNU Lesser General Public License, Version 2.1, February 1999 |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
__END__ |
|
154
|
|
|
|
|
|
|
|