| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package ACME::2026; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
246162
|
use 5.008003; |
|
|
2
|
|
|
|
|
8
|
|
|
4
|
2
|
|
|
2
|
|
16
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
86
|
|
|
5
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
148
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use Carp qw(croak); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
141
|
|
|
8
|
2
|
|
|
2
|
|
10
|
use Exporter 'import'; |
|
|
2
|
|
|
|
|
22
|
|
|
|
2
|
|
|
|
|
72
|
|
|
9
|
2
|
|
|
2
|
|
997
|
use File::Temp qw(tempfile); |
|
|
2
|
|
|
|
|
21580
|
|
|
|
2
|
|
|
|
|
163
|
|
|
10
|
2
|
|
|
2
|
|
1839
|
use JSON::PP (); |
|
|
2
|
|
|
|
|
43683
|
|
|
|
2
|
|
|
|
|
78
|
|
|
11
|
2
|
|
|
2
|
|
1463
|
use POSIX qw(strftime); |
|
|
2
|
|
|
|
|
15024
|
|
|
|
2
|
|
|
|
|
17
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
ACME::2026 - Checklists for glorious 2026 goals |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.01 |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
|
26
|
|
|
|
|
|
|
plan_new plan_load plan_save |
|
27
|
|
|
|
|
|
|
add_item update_item delete_item get_item |
|
28
|
|
|
|
|
|
|
add_note complete_item skip_item reopen_item |
|
29
|
|
|
|
|
|
|
items stats |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use ACME::2026 qw(:all); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $plan = plan_new( |
|
39
|
|
|
|
|
|
|
title => '2026', |
|
40
|
|
|
|
|
|
|
storage => '2026.json', |
|
41
|
|
|
|
|
|
|
autosave => 1, |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $id = add_item($plan, 'Run a marathon', |
|
45
|
|
|
|
|
|
|
list => 'Health', |
|
46
|
|
|
|
|
|
|
due => '2026-10-01', |
|
47
|
|
|
|
|
|
|
tags => [qw/fitness endurance/], |
|
48
|
|
|
|
|
|
|
priority => 2, |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
complete_item($plan, $id, note => 'Signed up for NYC'); |
|
52
|
|
|
|
|
|
|
my @open = items($plan, status => 'todo', list => 'Health', sort => 'due'); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
plan_save($plan); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
ACME::2026 is a tiny functional API for keeping 2026 checklists. It stores |
|
59
|
|
|
|
|
|
|
plans as plain Perl hashrefs and can persist them to JSON. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 DATA MODEL |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Plan hashref: |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
{ |
|
66
|
|
|
|
|
|
|
title => '2026', |
|
67
|
|
|
|
|
|
|
items => [ ... ], |
|
68
|
|
|
|
|
|
|
next_id => 1, |
|
69
|
|
|
|
|
|
|
created_at => '2026-01-01T12:00:00Z', |
|
70
|
|
|
|
|
|
|
updated_at => '2026-01-01T12:00:00Z', |
|
71
|
|
|
|
|
|
|
storage => '2026.json', |
|
72
|
|
|
|
|
|
|
autosave => 1, |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Item hashref: |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
{ |
|
78
|
|
|
|
|
|
|
id => 1, |
|
79
|
|
|
|
|
|
|
title => 'Run a marathon', |
|
80
|
|
|
|
|
|
|
status => 'todo', |
|
81
|
|
|
|
|
|
|
list => 'Health', |
|
82
|
|
|
|
|
|
|
tags => ['fitness'], |
|
83
|
|
|
|
|
|
|
priority => 2, |
|
84
|
|
|
|
|
|
|
due => '2026-10-01', |
|
85
|
|
|
|
|
|
|
notes => [ { note => 'Signed up', at => '2026-02-10T09:00:00Z' } ], |
|
86
|
|
|
|
|
|
|
created_at => '2026-01-01T12:00:00Z', |
|
87
|
|
|
|
|
|
|
updated_at => '2026-02-10T09:00:00Z', |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Status values are C, C, or C. Dates are ISO 8601 strings |
|
91
|
|
|
|
|
|
|
(C or C). |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 plan_new |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $plan = plan_new(%opts); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Creates a new plan hashref. Supported options: |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
title - plan title (default: 2026) |
|
102
|
|
|
|
|
|
|
storage - JSON path used by plan_save and autosave |
|
103
|
|
|
|
|
|
|
autosave - boolean, save after mutating operations |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 plan_load |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $plan = plan_load($path, %opts); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Loads a JSON file from C<$path>. The plan is normalized to ensure required |
|
110
|
|
|
|
|
|
|
fields exist. You can override C or C with C<%opts>. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 plan_save |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
plan_save($plan); |
|
115
|
|
|
|
|
|
|
plan_save($plan, $path); |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Writes the plan as JSON. Uses C<$plan-E{storage}> if no path is provided. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 add_item |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $id = add_item($plan, $title, %opts); |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Adds an item and returns its id. Supported options: |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
list, tags (arrayref or string), priority, due, note |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 update_item |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $item = update_item($plan, $id, %attrs); |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Updates a few fields in place: C, C, C, C, C. |
|
132
|
|
|
|
|
|
|
Use C or the status helpers for notes and status changes. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 delete_item |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
my $item = delete_item($plan, $id); |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Removes an item and returns it. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 get_item |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $item = get_item($plan, $id); |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Returns the item or C if it does not exist. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 add_note |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
add_note($plan, $id, $note); |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Appends a note with a timestamp. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 complete_item |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
complete_item($plan, $id, %opts); |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Sets the status to C. If C is supplied, it is added. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 skip_item |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
skip_item($plan, $id, %opts); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Sets the status to C. If C is supplied, it is added. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 reopen_item |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
reopen_item($plan, $id, %opts); |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Sets the status back to C. If C is supplied, it is added. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 items |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
my @items = items($plan, %filters); |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Filters items with any of: |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
status, list, tag, tags, priority, min_priority, max_priority, |
|
177
|
|
|
|
|
|
|
due_before, due_after, sort |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
For C or C, any matching tag is enough. C supports: |
|
180
|
|
|
|
|
|
|
C, C, C, C, or C. Prefix with C<-> |
|
181
|
|
|
|
|
|
|
for descending order. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 stats |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
my $stats = stats($plan, %filters); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Returns a hashref with C, C, C, C, and |
|
188
|
|
|
|
|
|
|
C. |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub plan_new { |
|
193
|
1
|
|
|
1
|
1
|
210421
|
my %opts = _normalize_opts(@_); |
|
194
|
|
|
|
|
|
|
|
|
195
|
1
|
|
|
|
|
7
|
my $now = _now(); |
|
196
|
|
|
|
|
|
|
my $plan = { |
|
197
|
|
|
|
|
|
|
title => defined $opts{title} ? $opts{title} : '2026', |
|
198
|
|
|
|
|
|
|
items => [], |
|
199
|
|
|
|
|
|
|
next_id => 1, |
|
200
|
|
|
|
|
|
|
created_at => $now, |
|
201
|
|
|
|
|
|
|
updated_at => $now, |
|
202
|
|
|
|
|
|
|
storage => $opts{storage}, |
|
203
|
1
|
50
|
|
|
|
45
|
autosave => $opts{autosave} ? 1 : 0, |
|
|
|
50
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
}; |
|
205
|
|
|
|
|
|
|
|
|
206
|
1
|
|
|
|
|
6
|
return $plan; |
|
207
|
|
|
|
|
|
|
} |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub plan_load { |
|
210
|
1
|
|
|
1
|
1
|
9
|
my ($path, %opts) = @_; |
|
211
|
1
|
50
|
33
|
|
|
6
|
croak 'plan_load requires a path' unless defined $path && length $path; |
|
212
|
|
|
|
|
|
|
|
|
213
|
1
|
|
|
|
|
5
|
my $json = _read_file($path); |
|
214
|
1
|
|
|
|
|
4
|
my $data = eval { JSON::PP->new->decode($json) }; |
|
|
1
|
|
|
|
|
36
|
|
|
215
|
1
|
50
|
|
|
|
10386
|
croak "Failed to decode JSON from $path: $@" if $@; |
|
216
|
|
|
|
|
|
|
|
|
217
|
1
|
|
|
|
|
8
|
_normalize_plan($data); |
|
218
|
|
|
|
|
|
|
|
|
219
|
1
|
|
|
|
|
3
|
$data->{storage} = $path; |
|
220
|
1
|
50
|
|
|
|
6
|
$data->{title} = $opts{title} if exists $opts{title}; |
|
221
|
1
|
0
|
|
|
|
4
|
$data->{autosave} = $opts{autosave} ? 1 : 0 if exists $opts{autosave}; |
|
|
|
50
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
|
223
|
1
|
|
|
|
|
6
|
return $data; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub plan_save { |
|
227
|
1
|
|
|
1
|
1
|
7789
|
my ($plan, $path) = @_; |
|
228
|
1
|
|
|
|
|
6
|
_ensure_plan($plan); |
|
229
|
|
|
|
|
|
|
|
|
230
|
1
|
|
33
|
|
|
3
|
$path ||= $plan->{storage}; |
|
231
|
1
|
50
|
33
|
|
|
9
|
croak 'plan_save requires a path or plan storage' unless defined $path && length $path; |
|
232
|
|
|
|
|
|
|
|
|
233
|
1
|
|
|
|
|
5
|
_normalize_plan($plan); |
|
234
|
|
|
|
|
|
|
|
|
235
|
1
|
|
|
|
|
14
|
my $encoder = JSON::PP->new->canonical(1)->pretty(1); |
|
236
|
1
|
|
|
|
|
168
|
my $json = $encoder->encode($plan); |
|
237
|
1
|
|
|
|
|
1697
|
_write_file_atomic($path, $json); |
|
238
|
|
|
|
|
|
|
|
|
239
|
1
|
|
|
|
|
20
|
return 1; |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub add_item { |
|
243
|
2
|
|
|
2
|
1
|
2144
|
my ($plan, @args) = @_; |
|
244
|
2
|
|
|
|
|
9
|
_ensure_plan($plan); |
|
245
|
|
|
|
|
|
|
|
|
246
|
2
|
|
|
|
|
4
|
my ($title, %opts); |
|
247
|
2
|
50
|
|
|
|
8
|
if (@args % 2 == 1) { |
|
248
|
2
|
|
|
|
|
4
|
$title = shift @args; |
|
249
|
2
|
|
|
|
|
16
|
%opts = @args; |
|
250
|
|
|
|
|
|
|
} else { |
|
251
|
0
|
|
|
|
|
0
|
%opts = @args; |
|
252
|
0
|
|
|
|
|
0
|
$title = $opts{title}; |
|
253
|
|
|
|
|
|
|
} |
|
254
|
|
|
|
|
|
|
|
|
255
|
2
|
50
|
33
|
|
|
13
|
croak 'add_item requires a title' unless defined $title && length $title; |
|
256
|
2
|
|
|
|
|
9
|
_reject_unknown('add_item', \%opts, qw(title list tags tag priority due note)); |
|
257
|
|
|
|
|
|
|
|
|
258
|
2
|
|
|
|
|
6
|
my $now = _now(); |
|
259
|
|
|
|
|
|
|
my $item = { |
|
260
|
|
|
|
|
|
|
id => $plan->{next_id}++, |
|
261
|
|
|
|
|
|
|
title => $title, |
|
262
|
|
|
|
|
|
|
status => 'todo', |
|
263
|
|
|
|
|
|
|
list => defined $opts{list} ? $opts{list} : 'General', |
|
264
|
|
|
|
|
|
|
tags => _normalize_tags($opts{tags}, $opts{tag}), |
|
265
|
|
|
|
|
|
|
priority => defined $opts{priority} ? $opts{priority} : 3, |
|
266
|
|
|
|
|
|
|
due => $opts{due}, |
|
267
|
2
|
50
|
|
|
|
19
|
notes => [], |
|
|
|
100
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
created_at => $now, |
|
269
|
|
|
|
|
|
|
updated_at => $now, |
|
270
|
|
|
|
|
|
|
}; |
|
271
|
|
|
|
|
|
|
|
|
272
|
2
|
|
|
|
|
6
|
push @{ $plan->{items} }, $item; |
|
|
2
|
|
|
|
|
5
|
|
|
273
|
2
|
50
|
|
|
|
30
|
if (defined $opts{note}) { |
|
274
|
0
|
|
|
|
|
0
|
_add_note($plan, $item, $opts{note}); |
|
275
|
|
|
|
|
|
|
} else { |
|
276
|
2
|
|
|
|
|
8
|
_touch($plan); |
|
277
|
|
|
|
|
|
|
} |
|
278
|
2
|
|
|
|
|
7
|
_maybe_autosave($plan); |
|
279
|
|
|
|
|
|
|
|
|
280
|
2
|
|
|
|
|
13
|
return $item->{id}; |
|
281
|
|
|
|
|
|
|
} |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
sub update_item { |
|
284
|
0
|
|
|
0
|
1
|
0
|
my ($plan, $id, %attrs) = @_; |
|
285
|
0
|
|
|
|
|
0
|
_ensure_plan($plan); |
|
286
|
|
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
0
|
my $item = _find_item($plan, $id); |
|
288
|
0
|
0
|
|
|
|
0
|
croak "No item with id $id" unless $item; |
|
289
|
|
|
|
|
|
|
|
|
290
|
0
|
|
|
|
|
0
|
_reject_unknown('update_item', \%attrs, qw(title list tags tag priority due)); |
|
291
|
|
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
0
|
my $changed = 0; |
|
293
|
0
|
|
|
|
|
0
|
for my $key (qw(title list priority due)) { |
|
294
|
0
|
0
|
|
|
|
0
|
next unless exists $attrs{$key}; |
|
295
|
0
|
|
|
|
|
0
|
$item->{$key} = $attrs{$key}; |
|
296
|
0
|
|
|
|
|
0
|
$changed = 1; |
|
297
|
|
|
|
|
|
|
} |
|
298
|
|
|
|
|
|
|
|
|
299
|
0
|
0
|
0
|
|
|
0
|
if (exists $attrs{tags} || exists $attrs{tag}) { |
|
300
|
0
|
|
|
|
|
0
|
$item->{tags} = _normalize_tags($attrs{tags}, $attrs{tag}); |
|
301
|
0
|
|
|
|
|
0
|
$changed = 1; |
|
302
|
|
|
|
|
|
|
} |
|
303
|
|
|
|
|
|
|
|
|
304
|
0
|
0
|
|
|
|
0
|
return $item unless $changed; |
|
305
|
|
|
|
|
|
|
|
|
306
|
0
|
|
|
|
|
0
|
$item->{updated_at} = _now(); |
|
307
|
0
|
|
|
|
|
0
|
_touch($plan); |
|
308
|
0
|
|
|
|
|
0
|
_maybe_autosave($plan); |
|
309
|
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
0
|
return $item; |
|
311
|
|
|
|
|
|
|
} |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
sub delete_item { |
|
314
|
0
|
|
|
0
|
1
|
0
|
my ($plan, $id) = @_; |
|
315
|
0
|
|
|
|
|
0
|
_ensure_plan($plan); |
|
316
|
|
|
|
|
|
|
|
|
317
|
0
|
|
|
|
|
0
|
my $items = $plan->{items}; |
|
318
|
0
|
|
|
|
|
0
|
for my $idx (0 .. $#$items) { |
|
319
|
0
|
0
|
0
|
|
|
0
|
next unless defined $items->[$idx]{id} && $items->[$idx]{id} == $id; |
|
320
|
0
|
|
|
|
|
0
|
my $item = splice(@$items, $idx, 1); |
|
321
|
0
|
|
|
|
|
0
|
_touch($plan); |
|
322
|
0
|
|
|
|
|
0
|
_maybe_autosave($plan); |
|
323
|
0
|
|
|
|
|
0
|
return $item; |
|
324
|
|
|
|
|
|
|
} |
|
325
|
|
|
|
|
|
|
|
|
326
|
0
|
|
|
|
|
0
|
return; |
|
327
|
|
|
|
|
|
|
} |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
sub get_item { |
|
330
|
2
|
|
|
2
|
1
|
1859
|
my ($plan, $id) = @_; |
|
331
|
2
|
|
|
|
|
8
|
_ensure_plan($plan); |
|
332
|
2
|
|
|
|
|
6
|
return _find_item($plan, $id); |
|
333
|
|
|
|
|
|
|
} |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
sub add_note { |
|
336
|
0
|
|
|
0
|
1
|
0
|
my ($plan, $id, $note) = @_; |
|
337
|
0
|
|
|
|
|
0
|
_ensure_plan($plan); |
|
338
|
0
|
0
|
0
|
|
|
0
|
croak 'add_note requires a note' unless defined $note && length $note; |
|
339
|
|
|
|
|
|
|
|
|
340
|
0
|
|
|
|
|
0
|
my $item = _find_item($plan, $id); |
|
341
|
0
|
0
|
|
|
|
0
|
croak "No item with id $id" unless $item; |
|
342
|
|
|
|
|
|
|
|
|
343
|
0
|
|
|
|
|
0
|
_add_note($plan, $item, $note); |
|
344
|
0
|
|
|
|
|
0
|
_maybe_autosave($plan); |
|
345
|
|
|
|
|
|
|
|
|
346
|
0
|
|
|
|
|
0
|
return $item; |
|
347
|
|
|
|
|
|
|
} |
|
348
|
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub complete_item { |
|
350
|
1
|
|
|
1
|
1
|
1841
|
my ($plan, $id, %opts) = @_; |
|
351
|
1
|
|
|
|
|
5
|
return _set_status($plan, $id, 'done', %opts); |
|
352
|
|
|
|
|
|
|
} |
|
353
|
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
sub skip_item { |
|
355
|
0
|
|
|
0
|
1
|
0
|
my ($plan, $id, %opts) = @_; |
|
356
|
0
|
|
|
|
|
0
|
return _set_status($plan, $id, 'skipped', %opts); |
|
357
|
|
|
|
|
|
|
} |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
sub reopen_item { |
|
360
|
0
|
|
|
0
|
1
|
0
|
my ($plan, $id, %opts) = @_; |
|
361
|
0
|
|
|
|
|
0
|
return _set_status($plan, $id, 'todo', %opts); |
|
362
|
|
|
|
|
|
|
} |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
sub items { |
|
365
|
3
|
|
|
3
|
1
|
4215
|
my ($plan, %filters) = @_; |
|
366
|
3
|
|
|
|
|
11
|
_ensure_plan($plan); |
|
367
|
|
|
|
|
|
|
|
|
368
|
3
|
50
|
|
|
|
6
|
my @items = @{ $plan->{items} || [] }; |
|
|
3
|
|
|
|
|
17
|
|
|
369
|
|
|
|
|
|
|
|
|
370
|
3
|
100
|
|
|
|
9
|
if (defined $filters{status}) { |
|
371
|
2
|
|
|
|
|
9
|
my $status = _normalize_status($filters{status}); |
|
372
|
2
|
|
|
|
|
7
|
@items = grep { $_->{status} eq $status } @items; |
|
|
4
|
|
|
|
|
14
|
|
|
373
|
|
|
|
|
|
|
} |
|
374
|
|
|
|
|
|
|
|
|
375
|
3
|
50
|
|
|
|
9
|
if (defined $filters{list}) { |
|
376
|
0
|
0
|
|
|
|
0
|
@items = grep { defined $_->{list} && $_->{list} eq $filters{list} } @items; |
|
|
0
|
|
|
|
|
0
|
|
|
377
|
|
|
|
|
|
|
} |
|
378
|
|
|
|
|
|
|
|
|
379
|
3
|
|
|
|
|
7
|
my @tags; |
|
380
|
3
|
50
|
|
|
|
11
|
push @tags, $filters{tag} if defined $filters{tag}; |
|
381
|
3
|
50
|
|
|
|
9
|
if (defined $filters{tags}) { |
|
382
|
0
|
0
|
|
|
|
0
|
if (ref $filters{tags} eq 'ARRAY') { |
|
383
|
0
|
|
|
|
|
0
|
push @tags, @{ $filters{tags} }; |
|
|
0
|
|
|
|
|
0
|
|
|
384
|
|
|
|
|
|
|
} else { |
|
385
|
0
|
|
|
|
|
0
|
push @tags, $filters{tags}; |
|
386
|
|
|
|
|
|
|
} |
|
387
|
|
|
|
|
|
|
} |
|
388
|
|
|
|
|
|
|
|
|
389
|
3
|
50
|
|
|
|
8
|
if (@tags) { |
|
390
|
|
|
|
|
|
|
@items = grep { |
|
391
|
0
|
0
|
|
|
|
0
|
my %item_tags = map { $_ => 1 } @{ $_->{tags} || [] }; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
392
|
0
|
|
|
|
|
0
|
my $match = 0; |
|
393
|
0
|
|
|
|
|
0
|
for my $tag (@tags) { |
|
394
|
0
|
0
|
0
|
|
|
0
|
next unless defined $tag && length $tag; |
|
395
|
0
|
0
|
|
|
|
0
|
if ($item_tags{$tag}) { |
|
396
|
0
|
|
|
|
|
0
|
$match = 1; |
|
397
|
0
|
|
|
|
|
0
|
last; |
|
398
|
|
|
|
|
|
|
} |
|
399
|
|
|
|
|
|
|
} |
|
400
|
0
|
|
|
|
|
0
|
$match; |
|
401
|
|
|
|
|
|
|
} @items; |
|
402
|
|
|
|
|
|
|
} |
|
403
|
|
|
|
|
|
|
|
|
404
|
3
|
50
|
|
|
|
9
|
if (defined $filters{priority}) { |
|
405
|
0
|
0
|
|
|
|
0
|
@items = grep { defined $_->{priority} && $_->{priority} == $filters{priority} } @items; |
|
|
0
|
|
|
|
|
0
|
|
|
406
|
|
|
|
|
|
|
} |
|
407
|
|
|
|
|
|
|
|
|
408
|
3
|
50
|
|
|
|
8
|
if (defined $filters{min_priority}) { |
|
409
|
0
|
0
|
|
|
|
0
|
@items = grep { defined $_->{priority} && $_->{priority} >= $filters{min_priority} } @items; |
|
|
0
|
|
|
|
|
0
|
|
|
410
|
|
|
|
|
|
|
} |
|
411
|
|
|
|
|
|
|
|
|
412
|
3
|
50
|
|
|
|
8
|
if (defined $filters{max_priority}) { |
|
413
|
0
|
0
|
|
|
|
0
|
@items = grep { defined $_->{priority} && $_->{priority} <= $filters{max_priority} } @items; |
|
|
0
|
|
|
|
|
0
|
|
|
414
|
|
|
|
|
|
|
} |
|
415
|
|
|
|
|
|
|
|
|
416
|
3
|
50
|
|
|
|
9
|
if (defined $filters{due_before}) { |
|
417
|
0
|
0
|
|
|
|
0
|
@items = grep { defined $_->{due} && $_->{due} le $filters{due_before} } @items; |
|
|
0
|
|
|
|
|
0
|
|
|
418
|
|
|
|
|
|
|
} |
|
419
|
|
|
|
|
|
|
|
|
420
|
3
|
50
|
|
|
|
9
|
if (defined $filters{due_after}) { |
|
421
|
0
|
0
|
|
|
|
0
|
@items = grep { defined $_->{due} && $_->{due} ge $filters{due_after} } @items; |
|
|
0
|
|
|
|
|
0
|
|
|
422
|
|
|
|
|
|
|
} |
|
423
|
|
|
|
|
|
|
|
|
424
|
3
|
50
|
|
|
|
10
|
if (defined $filters{sort}) { |
|
425
|
0
|
|
|
|
|
0
|
@items = _sort_items(\@items, $filters{sort}); |
|
426
|
|
|
|
|
|
|
} |
|
427
|
|
|
|
|
|
|
|
|
428
|
3
|
|
|
|
|
15
|
return @items; |
|
429
|
|
|
|
|
|
|
} |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
sub stats { |
|
432
|
1
|
|
|
1
|
1
|
951
|
my ($plan, %filters) = @_; |
|
433
|
1
|
|
|
|
|
5
|
_ensure_plan($plan); |
|
434
|
|
|
|
|
|
|
|
|
435
|
1
|
|
|
|
|
5
|
my @items = items($plan, %filters); |
|
436
|
1
|
|
|
|
|
8
|
my %stats = ( |
|
437
|
|
|
|
|
|
|
total => scalar @items, |
|
438
|
|
|
|
|
|
|
todo => 0, |
|
439
|
|
|
|
|
|
|
done => 0, |
|
440
|
|
|
|
|
|
|
skipped => 0, |
|
441
|
|
|
|
|
|
|
); |
|
442
|
|
|
|
|
|
|
|
|
443
|
1
|
|
|
|
|
3
|
for my $item (@items) { |
|
444
|
2
|
50
|
|
|
|
8
|
$stats{ $item->{status} }++ if exists $stats{ $item->{status} }; |
|
445
|
|
|
|
|
|
|
} |
|
446
|
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
$stats{complete_pct} = $stats{total} |
|
448
|
1
|
50
|
|
|
|
9
|
? int(($stats{done} / $stats{total}) * 100 + 0.5) |
|
449
|
|
|
|
|
|
|
: 0; |
|
450
|
|
|
|
|
|
|
|
|
451
|
1
|
|
|
|
|
5
|
return \%stats; |
|
452
|
|
|
|
|
|
|
} |
|
453
|
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
sub _set_status { |
|
455
|
1
|
|
|
1
|
|
5
|
my ($plan, $id, $status, %opts) = @_; |
|
456
|
1
|
|
|
|
|
5
|
_ensure_plan($plan); |
|
457
|
|
|
|
|
|
|
|
|
458
|
1
|
|
|
|
|
3
|
_reject_unknown('_set_status', \%opts, qw(note)); |
|
459
|
1
|
|
|
|
|
12
|
my $item = _find_item($plan, $id); |
|
460
|
1
|
50
|
|
|
|
4
|
croak "No item with id $id" unless $item; |
|
461
|
|
|
|
|
|
|
|
|
462
|
1
|
|
|
|
|
4
|
$item->{status} = _normalize_status($status); |
|
463
|
1
|
|
|
|
|
5
|
$item->{updated_at} = _now(); |
|
464
|
1
|
50
|
|
|
|
6
|
if (defined $opts{note}) { |
|
465
|
1
|
|
|
|
|
4
|
_add_note($plan, $item, $opts{note}); |
|
466
|
|
|
|
|
|
|
} else { |
|
467
|
0
|
|
|
|
|
0
|
_touch($plan); |
|
468
|
|
|
|
|
|
|
} |
|
469
|
1
|
|
|
|
|
3
|
_maybe_autosave($plan); |
|
470
|
|
|
|
|
|
|
|
|
471
|
1
|
|
|
|
|
6
|
return $item; |
|
472
|
|
|
|
|
|
|
} |
|
473
|
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
sub _normalize_opts { |
|
475
|
1
|
50
|
33
|
1
|
|
8
|
return %{ $_[0] } if @_ == 1 && ref $_[0] eq 'HASH'; |
|
|
0
|
|
|
|
|
0
|
|
|
476
|
1
|
|
|
|
|
5
|
return @_; |
|
477
|
|
|
|
|
|
|
} |
|
478
|
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
sub _normalize_plan { |
|
480
|
2
|
|
|
2
|
|
8
|
my ($plan) = @_; |
|
481
|
2
|
|
|
|
|
8
|
_ensure_plan($plan); |
|
482
|
|
|
|
|
|
|
|
|
483
|
2
|
50
|
33
|
|
|
19
|
$plan->{title} = '2026' unless defined $plan->{title} && length $plan->{title}; |
|
484
|
2
|
50
|
|
|
|
10
|
$plan->{items} = [] unless ref $plan->{items} eq 'ARRAY'; |
|
485
|
2
|
50
|
|
|
|
7
|
$plan->{autosave} = $plan->{autosave} ? 1 : 0; |
|
486
|
|
|
|
|
|
|
|
|
487
|
2
|
|
|
|
|
4
|
my $max_id = 0; |
|
488
|
2
|
|
|
|
|
4
|
for my $item (@{ $plan->{items} }) { |
|
|
2
|
|
|
|
|
8
|
|
|
489
|
4
|
50
|
|
|
|
9
|
next unless ref $item eq 'HASH'; |
|
490
|
4
|
50
|
33
|
|
|
24
|
$max_id = $item->{id} if defined $item->{id} && $item->{id} > $max_id; |
|
491
|
|
|
|
|
|
|
} |
|
492
|
|
|
|
|
|
|
|
|
493
|
2
|
|
33
|
|
|
7
|
$plan->{next_id} = $plan->{next_id} || ($max_id + 1); |
|
494
|
2
|
|
|
|
|
4
|
my $next_id = $plan->{next_id}; |
|
495
|
|
|
|
|
|
|
|
|
496
|
2
|
|
|
|
|
4
|
for my $item (@{ $plan->{items} }) { |
|
|
2
|
|
|
|
|
5
|
|
|
497
|
4
|
50
|
|
|
|
89
|
next unless ref $item eq 'HASH'; |
|
498
|
4
|
50
|
|
|
|
15
|
if (!defined $item->{id}) { |
|
499
|
0
|
|
|
|
|
0
|
$item->{id} = $next_id++; |
|
500
|
|
|
|
|
|
|
} |
|
501
|
4
|
|
|
|
|
13
|
$item->{status} = _normalize_status($item->{status}); |
|
502
|
4
|
|
|
|
|
13
|
$item->{tags} = _normalize_tags($item->{tags}); |
|
503
|
4
|
|
|
|
|
10
|
$item->{notes} = _normalize_notes($item->{notes}); |
|
504
|
4
|
50
|
|
|
|
14
|
$item->{priority} = defined $item->{priority} ? $item->{priority} : 3; |
|
505
|
4
|
50
|
|
|
|
11
|
$item->{list} = defined $item->{list} ? $item->{list} : 'General'; |
|
506
|
4
|
50
|
|
|
|
10
|
$item->{created_at} = _now() unless defined $item->{created_at}; |
|
507
|
4
|
50
|
|
|
|
9
|
$item->{updated_at} = $item->{created_at} unless defined $item->{updated_at}; |
|
508
|
|
|
|
|
|
|
} |
|
509
|
|
|
|
|
|
|
|
|
510
|
2
|
50
|
|
|
|
6
|
$plan->{next_id} = $next_id if $next_id > $plan->{next_id}; |
|
511
|
2
|
50
|
|
|
|
6
|
$plan->{created_at} = _now() unless defined $plan->{created_at}; |
|
512
|
2
|
50
|
|
|
|
5
|
$plan->{updated_at} = $plan->{created_at} unless defined $plan->{updated_at}; |
|
513
|
|
|
|
|
|
|
|
|
514
|
2
|
|
|
|
|
28
|
return $plan; |
|
515
|
|
|
|
|
|
|
} |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
sub _normalize_status { |
|
518
|
7
|
|
|
7
|
|
17
|
my ($status) = @_; |
|
519
|
7
|
50
|
33
|
|
|
35
|
$status = 'todo' if !defined $status || $status eq ''; |
|
520
|
7
|
50
|
66
|
|
|
37
|
return $status if $status eq 'todo' || $status eq 'done' || $status eq 'skipped'; |
|
|
|
|
33
|
|
|
|
|
|
521
|
0
|
|
|
|
|
0
|
croak "Unknown status '$status'"; |
|
522
|
|
|
|
|
|
|
} |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
sub _normalize_tags { |
|
525
|
6
|
|
|
6
|
|
15
|
my ($tags, $tag) = @_; |
|
526
|
6
|
|
|
|
|
12
|
my @tags; |
|
527
|
|
|
|
|
|
|
|
|
528
|
6
|
50
|
|
|
|
16
|
if (defined $tags) { |
|
529
|
6
|
50
|
|
|
|
16
|
if (ref $tags eq 'ARRAY') { |
|
530
|
6
|
|
|
|
|
18
|
@tags = @$tags; |
|
531
|
|
|
|
|
|
|
} else { |
|
532
|
0
|
|
|
|
|
0
|
@tags = ($tags); |
|
533
|
|
|
|
|
|
|
} |
|
534
|
|
|
|
|
|
|
} |
|
535
|
|
|
|
|
|
|
|
|
536
|
6
|
50
|
|
|
|
16
|
push @tags, $tag if defined $tag; |
|
537
|
|
|
|
|
|
|
|
|
538
|
6
|
50
|
|
|
|
10
|
@tags = grep { defined $_ && length $_ } @tags; |
|
|
6
|
|
|
|
|
49
|
|
|
539
|
6
|
|
|
|
|
36
|
return \@tags; |
|
540
|
|
|
|
|
|
|
} |
|
541
|
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
sub _normalize_notes { |
|
543
|
4
|
|
|
4
|
|
10
|
my ($notes) = @_; |
|
544
|
4
|
50
|
|
|
|
7
|
return [] unless defined $notes; |
|
545
|
4
|
50
|
|
|
|
11
|
if (ref $notes eq 'ARRAY') { |
|
546
|
4
|
|
|
|
|
7
|
my @out; |
|
547
|
4
|
|
|
|
|
7
|
for my $note (@$notes) { |
|
548
|
2
|
50
|
|
|
|
6
|
if (ref $note eq 'HASH') { |
|
549
|
2
|
|
|
|
|
6
|
push @out, $note; |
|
550
|
|
|
|
|
|
|
} else { |
|
551
|
0
|
|
|
|
|
0
|
push @out, { note => $note }; |
|
552
|
|
|
|
|
|
|
} |
|
553
|
|
|
|
|
|
|
} |
|
554
|
4
|
|
|
|
|
10
|
return \@out; |
|
555
|
|
|
|
|
|
|
} |
|
556
|
0
|
|
|
|
|
0
|
return [ { note => $notes } ]; |
|
557
|
|
|
|
|
|
|
} |
|
558
|
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
sub _ensure_plan { |
|
560
|
12
|
|
|
12
|
|
24
|
my ($plan) = @_; |
|
561
|
12
|
50
|
|
|
|
46
|
croak 'Plan must be a hashref' unless ref $plan eq 'HASH'; |
|
562
|
|
|
|
|
|
|
} |
|
563
|
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
sub _find_item { |
|
565
|
3
|
|
|
3
|
|
7
|
my ($plan, $id) = @_; |
|
566
|
3
|
50
|
|
|
|
9
|
return unless defined $id; |
|
567
|
3
|
50
|
|
|
|
5
|
for my $item (@{ $plan->{items} || [] }) { |
|
|
3
|
|
|
|
|
12
|
|
|
568
|
3
|
50
|
|
|
|
10
|
next unless defined $item->{id}; |
|
569
|
3
|
50
|
|
|
|
13
|
return $item if $item->{id} == $id; |
|
570
|
|
|
|
|
|
|
} |
|
571
|
0
|
|
|
|
|
0
|
return; |
|
572
|
|
|
|
|
|
|
} |
|
573
|
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
sub _add_note { |
|
575
|
1
|
|
|
1
|
|
3
|
my ($plan, $item, $note) = @_; |
|
576
|
1
|
50
|
33
|
|
|
8
|
return unless defined $note && length $note; |
|
577
|
|
|
|
|
|
|
|
|
578
|
1
|
|
|
|
|
2
|
push @{ $item->{notes} }, { note => $note, at => _now() }; |
|
|
1
|
|
|
|
|
4
|
|
|
579
|
1
|
|
|
|
|
4
|
$item->{updated_at} = _now(); |
|
580
|
1
|
|
|
|
|
3
|
_touch($plan); |
|
581
|
|
|
|
|
|
|
} |
|
582
|
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
sub _touch { |
|
584
|
3
|
|
|
3
|
|
5
|
my ($plan) = @_; |
|
585
|
3
|
|
|
|
|
7
|
$plan->{updated_at} = _now(); |
|
586
|
|
|
|
|
|
|
} |
|
587
|
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
sub _maybe_autosave { |
|
589
|
3
|
|
|
3
|
|
5
|
my ($plan) = @_; |
|
590
|
3
|
50
|
|
|
|
10
|
return unless $plan->{autosave}; |
|
591
|
0
|
|
|
|
|
0
|
plan_save($plan); |
|
592
|
|
|
|
|
|
|
} |
|
593
|
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
sub _sort_items { |
|
595
|
0
|
|
|
0
|
|
0
|
my ($items, $sort) = @_; |
|
596
|
0
|
0
|
0
|
|
|
0
|
return @$items unless defined $sort && length $sort; |
|
597
|
|
|
|
|
|
|
|
|
598
|
0
|
|
|
|
|
0
|
my $desc = ($sort =~ s/^-//); |
|
599
|
|
|
|
|
|
|
|
|
600
|
0
|
0
|
|
|
|
0
|
if ($sort eq 'due') { |
|
601
|
|
|
|
|
|
|
return sort { |
|
602
|
0
|
0
|
|
|
|
0
|
my $ad = defined $a->{due} ? $a->{due} : ($desc ? '0000-00-00' : '9999-12-31'); |
|
|
0
|
0
|
|
|
|
0
|
|
|
603
|
0
|
0
|
|
|
|
0
|
my $bd = defined $b->{due} ? $b->{due} : ($desc ? '0000-00-00' : '9999-12-31'); |
|
|
|
0
|
|
|
|
|
|
|
604
|
0
|
|
|
|
|
0
|
my $cmp = $ad cmp $bd; |
|
605
|
0
|
0
|
|
|
|
0
|
$desc ? -$cmp : $cmp; |
|
606
|
|
|
|
|
|
|
} @$items; |
|
607
|
|
|
|
|
|
|
} |
|
608
|
|
|
|
|
|
|
|
|
609
|
0
|
0
|
|
|
|
0
|
if ($sort eq 'priority') { |
|
610
|
|
|
|
|
|
|
return sort { |
|
611
|
0
|
0
|
|
|
|
0
|
my $ad = defined $a->{priority} ? $a->{priority} : 0; |
|
|
0
|
|
|
|
|
0
|
|
|
612
|
0
|
0
|
|
|
|
0
|
my $bd = defined $b->{priority} ? $b->{priority} : 0; |
|
613
|
0
|
|
|
|
|
0
|
my $cmp = $ad <=> $bd; |
|
614
|
0
|
0
|
|
|
|
0
|
$desc ? -$cmp : $cmp; |
|
615
|
|
|
|
|
|
|
} @$items; |
|
616
|
|
|
|
|
|
|
} |
|
617
|
|
|
|
|
|
|
|
|
618
|
0
|
0
|
|
|
|
0
|
if ($sort eq 'created') { |
|
619
|
|
|
|
|
|
|
return sort { |
|
620
|
0
|
|
0
|
|
|
0
|
my $cmp = ($a->{created_at} || '') cmp ($b->{created_at} || ''); |
|
|
0
|
|
0
|
|
|
0
|
|
|
621
|
0
|
0
|
|
|
|
0
|
$desc ? -$cmp : $cmp; |
|
622
|
|
|
|
|
|
|
} @$items; |
|
623
|
|
|
|
|
|
|
} |
|
624
|
|
|
|
|
|
|
|
|
625
|
0
|
0
|
|
|
|
0
|
if ($sort eq 'updated') { |
|
626
|
|
|
|
|
|
|
return sort { |
|
627
|
0
|
|
0
|
|
|
0
|
my $cmp = ($a->{updated_at} || '') cmp ($b->{updated_at} || ''); |
|
|
0
|
|
0
|
|
|
0
|
|
|
628
|
0
|
0
|
|
|
|
0
|
$desc ? -$cmp : $cmp; |
|
629
|
|
|
|
|
|
|
} @$items; |
|
630
|
|
|
|
|
|
|
} |
|
631
|
|
|
|
|
|
|
|
|
632
|
0
|
0
|
|
|
|
0
|
if ($sort eq 'title') { |
|
633
|
|
|
|
|
|
|
return sort { |
|
634
|
0
|
|
0
|
|
|
0
|
my $cmp = lc($a->{title} || '') cmp lc($b->{title} || ''); |
|
|
0
|
|
0
|
|
|
0
|
|
|
635
|
0
|
0
|
|
|
|
0
|
$desc ? -$cmp : $cmp; |
|
636
|
|
|
|
|
|
|
} @$items; |
|
637
|
|
|
|
|
|
|
} |
|
638
|
|
|
|
|
|
|
|
|
639
|
0
|
|
|
|
|
0
|
return @$items; |
|
640
|
|
|
|
|
|
|
} |
|
641
|
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
sub _reject_unknown { |
|
643
|
3
|
|
|
3
|
|
12
|
my ($context, $attrs, @known) = @_; |
|
644
|
3
|
|
|
|
|
7
|
my %known = map { $_ => 1 } @known; |
|
|
15
|
|
|
|
|
33
|
|
|
645
|
3
|
|
|
|
|
11
|
my @unknown = grep { !$known{$_} } keys %$attrs; |
|
|
7
|
|
|
|
|
16
|
|
|
646
|
3
|
50
|
|
|
|
22
|
return unless @unknown; |
|
647
|
0
|
|
|
|
|
0
|
croak "$context does not accept: " . join(', ', sort @unknown); |
|
648
|
|
|
|
|
|
|
} |
|
649
|
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
sub _now { |
|
651
|
9
|
|
|
9
|
|
261
|
return strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()); |
|
652
|
|
|
|
|
|
|
} |
|
653
|
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
sub _read_file { |
|
655
|
1
|
|
|
1
|
|
2
|
my ($path) = @_; |
|
656
|
1
|
50
|
|
|
|
51
|
open my $fh, '<', $path or croak "Unable to read $path: $!"; |
|
657
|
1
|
|
|
|
|
6
|
local $/; |
|
658
|
1
|
|
|
|
|
51
|
return <$fh>; |
|
659
|
|
|
|
|
|
|
} |
|
660
|
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
sub _write_file_atomic { |
|
662
|
1
|
|
|
1
|
|
4
|
my ($path, $content) = @_; |
|
663
|
1
|
|
|
|
|
4
|
my ($fh, $tmp) = tempfile('acme2026-XXXXXX', DIR => _temp_dir($path)); |
|
664
|
1
|
50
|
|
|
|
600
|
print {$fh} $content or croak "Unable to write $tmp: $!"; |
|
|
1
|
|
|
|
|
22
|
|
|
665
|
1
|
50
|
|
|
|
56
|
close $fh or croak "Unable to close $tmp: $!"; |
|
666
|
1
|
50
|
|
|
|
275
|
rename $tmp, $path or croak "Unable to move $tmp to $path: $!"; |
|
667
|
|
|
|
|
|
|
} |
|
668
|
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
sub _temp_dir { |
|
670
|
1
|
|
|
1
|
|
3
|
my ($path) = @_; |
|
671
|
1
|
50
|
33
|
|
|
8
|
return '.' unless defined $path && length $path; |
|
672
|
1
|
50
|
|
|
|
6
|
if ($path =~ /[\/\\]/) { |
|
673
|
1
|
|
|
|
|
9
|
$path =~ s/[\/\\][^\/\\]+$//; |
|
674
|
1
|
50
|
|
|
|
26
|
return length $path ? $path : '.'; |
|
675
|
|
|
|
|
|
|
} |
|
676
|
0
|
|
|
|
|
|
return '.'; |
|
677
|
|
|
|
|
|
|
} |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
=head1 AUTHOR |
|
680
|
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
Will Willis |
|
682
|
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
=head1 BUGS |
|
684
|
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
686
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
687
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
688
|
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
=head1 SUPPORT |
|
690
|
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
692
|
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
perldoc ACME::2026 |
|
694
|
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
You can also look for information at: |
|
696
|
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
=over 4 |
|
698
|
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
|
700
|
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
L |
|
702
|
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
=item * Search CPAN |
|
704
|
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
L |
|
706
|
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
=back |
|
708
|
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
710
|
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
712
|
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
This software is Copyright (c) 2026 by Will Willis . |
|
714
|
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
This is free software, licensed under: |
|
716
|
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
=cut |
|
720
|
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
1; # End of ACME::2026 |