| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Toodledo::TaskCache; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1769
|
use Moose; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
8
|
|
|
4
|
1
|
|
|
1
|
|
6136
|
use MooseX::Method::Signatures; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
9
|
|
|
5
|
1
|
|
|
1
|
|
156
|
use MooseX::ClassAttribute; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
6
|
1
|
|
|
1
|
|
4336
|
use App::Toodledo::Util qw(home); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
69
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use YAML qw(LoadFile DumpFile); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
140
|
|
|
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
|
1
|
|
|
1
|
|
23529
|
method exists () { |
|
25
|
|
|
|
|
|
|
-s _cache_filename() or return; |
|
26
|
|
|
|
|
|
|
$self->log->debug( "Task cache exists\n" ); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
25506
|
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
|
|
|
|
|
|
|
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 |