line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Toodledo::TaskCache; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
57
|
use Moose; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
60
|
|
4
|
8
|
|
|
8
|
|
49446
|
use MooseX::Method::Signatures; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
72
|
|
5
|
8
|
|
|
8
|
|
1660
|
use MooseX::ClassAttribute; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
64
|
|
6
|
8
|
|
|
8
|
|
29268
|
use App::Toodledo::Util qw(home); |
|
8
|
|
|
|
|
157
|
|
|
8
|
|
|
|
|
699
|
|
7
|
8
|
|
|
8
|
|
52
|
use YAML qw(LoadFile DumpFile); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
1139
|
|
8
|
|
|
|
|
|
|
with 'MooseX::Log::Log4perl'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has tasks => ( is => 'rw', isa => 'ArrayRef[App::Toodledo::Task]', |
13
|
|
|
|
|
|
|
auto_deref => 1 ); |
14
|
|
|
|
|
|
|
has last_updated => ( is => 'rw', isa => 'Int' ); # Timestamp |
15
|
|
|
|
|
|
|
class_has Filename => ( is => 'rw', default => '.toodledo_task_cache' ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _cache_filename |
19
|
|
|
|
|
|
|
{ |
20
|
0
|
|
|
0
|
|
|
File::Spec->catfile( home(), __PACKAGE__->Filename ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
8
|
|
|
8
|
|
166187
|
method exists () { |
25
|
|
|
|
|
|
|
-s _cache_filename() or return; |
26
|
|
|
|
|
|
|
$self->log->debug( "Task cache exists\n" ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
8
|
|
|
8
|
|
160470
|
method fetch () { |
31
|
|
|
|
|
|
|
$self->log->debug( "Loading from task cache\n" ); |
32
|
|
|
|
|
|
|
%$self = LoadFile( _cache_filename() ); |
33
|
|
|
|
|
|
|
$self->log->debug( "Fetched " . @{ $self->tasks } . " tasks from " |
34
|
|
|
|
|
|
|
. _cache_filename() . "\n" ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
8
|
|
|
8
|
|
371084
|
method store ( App::Toodledo::Task @tasks ) { |
39
|
|
|
|
|
|
|
$self->last_updated( time ); |
40
|
|
|
|
|
|
|
$self->tasks( [ @tasks ] ); |
41
|
|
|
|
|
|
|
$self->log->debug( "Storing " . @tasks ." tasks in " . _cache_filename() . "\n" ); |
42
|
|
|
|
|
|
|
DumpFile( _cache_filename(), %$self ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 NAME |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
App::Toodledo::TaskCache - Manage a local cache of Toodledo tasks |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SYNOPSIS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 DESCRIPTION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This is neither fast nor space efficient. It uses YAML to store the tasks. |
59
|
|
|
|
|
|
|
This has the advantage of producing a human-readable cache but that's about the |
60
|
|
|
|
|
|
|
only advantage. Go ahead and send a patch for SQLite if you can. That'll |
61
|
|
|
|
|
|
|
facilitate selective updating of the cache. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 METHODS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 $boolean = $cache->exists |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Return true if the cache file exists and is nonempty. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 $cache->fetch |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Load the cache from the file. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 $cache->store |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Store the cache to the file. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 tasks |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
A hashref of L<App::Toodledo::Task> objects. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 last_updated |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Unix time the cache was last written. Use for comparing with time of |
86
|
|
|
|
|
|
|
the last operation on the Toodledo server. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 NOTES |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Override the routine C<_cache_filename> in this package if you want to |
91
|
|
|
|
|
|
|
change the filename used for the cache. It returns the concatenation |
92
|
|
|
|
|
|
|
of the user's home directory with the class attribute C<Filename> |
93
|
|
|
|
|
|
|
(default: C<.toodledo_task_cache>). If you just want to change the |
94
|
|
|
|
|
|
|
name of the file and keep it in the home directory, override the |
95
|
|
|
|
|
|
|
C<Filename> attribute (declared with C<class_has> via |
96
|
|
|
|
|
|
|
L<MooseX::ClassAttribute>). |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Peter Scott C<cpan at psdt.com> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |