File Coverage

blib/lib/MooseX/ExpiredAttribute.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package MooseX::ExpiredAttribute;
2              
3 1     1   22825 use Moose 2.1204 ();
  0            
  0            
4              
5             use MooseX::ExpiredAttribute::Role::Meta::Attribute;
6             use MooseX::ExpiredAttribute::Role::Object;
7              
8             $MooseX::ExpiredAttribute::VERSION = 0.023;
9              
10             1;
11              
12             __END__
13              
14             =pod
15              
16             =head1 NAME
17              
18             MooseX::ExpiredAttribute - Expired and auto rebuilded attributes in Moose objects
19              
20             =head1 SYNOPSIS
21              
22             package MyClass;
23              
24             use Moose;
25             use MooseX::ExpiredAttribute;
26              
27             has 'config' => (
28             traits => [ qw( Expired ) ],
29             is => 'rw',
30             isa => 'HashRef',
31             expires => 5.5,
32             lazy => 1,
33             builder => '_build_config',
34             );
35              
36             sub _build_config {
37             ... # open config file, read and hash forming
38             }
39              
40             package main;
41              
42             my $prog = MyClass->new;
43              
44             $prog->config; # The first calling - here read file and make hash of configs
45             sleep 2; # only 2 seconds elapsed...
46             $prog->config; # ... there is no calling of builder again - only attribute value returning
47             sleep 4; # elapsed ~ 6 seconds from first calling of builder - more than 5.5 seconds elapsed (the 'expires' option)
48             $prog->config; # ... there is new calling of builder - rereading config file again
49             sleep 3; # only 3 seconds elapsed from rebuilding...
50             $prog->config; # ... only old value is returned
51             ...
52              
53             and even by this way:
54              
55             package MyRole;
56              
57             use Moose::Role;
58             use MooseX::ExpiredAttribute;
59              
60             has 'config' => (
61             traits => [ qw( Expired ) ],
62             is => 'rw',
63             isa => 'HashRef',
64             expires => 5.5,
65             lazy => 1,
66             builder => '_build_config',
67             );
68              
69             sub _build_config {
70             ... # open config file, read and hash forming
71             }
72              
73             package MyClass;
74              
75             with 'MyRole';
76              
77             has 'foo' => ( is => 'rw' );
78              
79             package main;
80              
81             my $prog = MyClass->new;
82              
83             $prog->config; # First calling - here read file and hash of configs
84             ...
85              
86             =head1 DESCRIPTION
87              
88             This module allows to create expired attributes with auto-rebuilding feature
89             after elapsed time. The goal of module is attrubutes which can be able to have
90             the time-varying value. For example some configs can be changed by user during
91             program runtime and wished to be reread by program every one minute for example.
92             All that is required from you to add the trait to an attribute and to add the
93             'expires' option (may be fractal seconds). An attribute should have a builder
94             too!
95              
96             =head1 SEE ALSO
97              
98             =over
99              
100             =item L<MooseX::ExpiredAttribute::Role::Object>
101              
102             =item L<MooseX::ExpiredAttribute::Role::Meta::Attribute>
103              
104             =back
105              
106             =head1 AUTHOR
107              
108             This module has been written by Perlover <perlover@perlover.com>
109              
110             =head1 LICENSE
111              
112             This module is free software and is published under the same terms as Perl
113             itself.
114              
115             =cut