line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Taskwarrior::Kusarigama::Core; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Set of core functions interacting with Taskwarrior |
4
|
|
|
|
|
|
|
$Taskwarrior::Kusarigama::Core::VERSION = '0.12.0'; |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
99081
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
100
|
|
7
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
88
|
|
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
4
|
|
2582
|
use Path::Tiny; |
|
4
|
|
|
|
|
36512
|
|
|
4
|
|
|
|
|
211
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
32
|
use Moo::Role; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
31
|
|
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
1382
|
use MooseX::MungeHas; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
32
|
|
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
4
|
|
4977
|
use IPC::Run3; |
|
4
|
|
|
|
|
78800
|
|
|
4
|
|
|
|
|
220
|
|
16
|
4
|
|
|
4
|
|
1685
|
use JSON; |
|
4
|
|
|
|
|
24595
|
|
|
4
|
|
|
|
|
37
|
|
17
|
4
|
|
|
4
|
|
496
|
use Module::Runtime qw/ use_module /; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
43
|
|
18
|
4
|
|
|
4
|
|
1615
|
use List::AllUtils qw/ uniq /; |
|
4
|
|
|
|
|
33935
|
|
|
4
|
|
|
|
|
278
|
|
19
|
|
|
|
|
|
|
|
20
|
4
|
|
|
4
|
|
398
|
use experimental 'postderef'; |
|
4
|
|
|
|
|
2814
|
|
|
4
|
|
|
|
|
26
|
|
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
4
|
|
2135
|
use namespace::clean; |
|
4
|
|
|
|
|
25990
|
|
|
4
|
|
|
|
|
23
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has $_ => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
) for qw/ api version args command rc data /; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has pre_command_args => sub { |
31
|
0
|
|
|
0
|
|
|
my $self = shift; |
32
|
0
|
|
|
|
|
|
my $command = $self->command; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $args = $self->args; |
35
|
0
|
|
|
|
|
|
$args =~ s/^task\s+//; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
while() { |
38
|
0
|
0
|
|
|
|
|
return $1 if $args =~ /(.*?)\s*\b$command\b/; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# command can be abbreviated |
41
|
0
|
|
|
|
|
|
chop $command; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has post_command_args => sub { |
48
|
0
|
|
|
0
|
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my $command = $self->command; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $args = $self->args; |
52
|
0
|
|
|
|
|
|
$args =~ s/^task\s+//; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
while() { |
55
|
0
|
0
|
|
|
|
|
return $1 if $args =~ /\b$command\b\s*(.*)/; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# command can be abbreviated |
58
|
0
|
|
|
|
|
|
chop $command; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has data_dir => sub { |
65
|
0
|
|
|
0
|
|
|
path( $_[0]->data ); |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
has run_task => sub { |
70
|
0
|
|
|
0
|
|
|
require Taskwarrior::Kusarigama::Wrapper; |
71
|
0
|
|
|
|
|
|
Taskwarrior::Kusarigama::Wrapper->new; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has plugins => sub { |
76
|
0
|
|
|
0
|
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
|
78
|
4
|
|
|
4
|
|
2288
|
no warnings 'uninitialized'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
575
|
|
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
[ map { use_module($_)->new( tw => $self ) } |
81
|
0
|
0
|
|
|
|
|
map { s/^\+// ? $_ : ( 'Taskwarrior::Kusarigama::Plugin::' . $_ ) } |
82
|
0
|
|
|
|
|
|
split ',', $self->config->{kusarigama}{plugins} ] |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
before plugins => sub { |
86
|
|
|
|
|
|
|
my $self = shift; |
87
|
4
|
|
|
4
|
|
28
|
no warnings 'uninitialized'; |
|
4
|
|
|
|
|
18
|
|
|
4
|
|
|
|
|
1338
|
|
88
|
|
|
|
|
|
|
@INC = uniq @INC, |
89
|
|
|
|
|
|
|
map { s/^\./$self->data_dir/er } |
90
|
|
|
|
|
|
|
split ':', $self->config->{kusarigama}{lib}; |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub export_tasks { |
95
|
0
|
|
|
0
|
1
|
|
my( $self, @query ) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
run3 [qw/ task rc.recurrence=no rc.hooks=off export /, @query], undef, \my $out; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return eval { @{ from_json $out } }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub new_task { |
104
|
0
|
|
|
0
|
1
|
|
my ( $self, $task ) = @_; |
105
|
0
|
|
0
|
|
|
|
$task ||= {}; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return Taskwarrior::Kusarigama::Task->new( $self->run_task, $task ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub import_task { |
112
|
0
|
|
|
0
|
1
|
|
my( $self, $task ) = @_; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $in = to_json $task; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
run3 [qw/ task rc.recurrence=no import /], \$in; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub calc { |
121
|
0
|
|
|
0
|
1
|
|
my( $self, @stuff ) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
run3 [qw/ task rc.recurrence=no rc.hooks=off calc /, @stuff ], undef, \my $output; |
124
|
0
|
|
|
|
|
|
chomp $output; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return $output; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=pod |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=encoding UTF-8 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 NAME |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Taskwarrior::Kusarigama::Core - Set of core functions interacting with Taskwarrior |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 VERSION |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
version 0.12.0 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 DESCRIPTION |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Role consumed by L<Taskwarrior::Kusarigama::Hook>. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 METHODS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The role provides the following methods: |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 api |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 version |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 args |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 command |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 rc |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 data |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 pre_command_args |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Returns the arguments that preceding the command as a string. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# assuming `task this and that foo` was run, and the command is 'foo' |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$tw->pre_command_args; # => 'this and that' |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Note that because the way the hooks get the arguments, there is no way to |
174
|
|
|
|
|
|
|
distinguish between |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
task 'this and that' foo |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
and |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
task this and that foo |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 post_command_args |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Returns the arguments that follow the command as a string. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# assuming `task this and that foo sumfin` was run, and the command is 'foo' |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
$tw->post_command_args; # => 'sumfin' |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 data_dir |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 run_task |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Returns a L<Taskwarrior::Kusarigama::Wrapper> object. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 plugins |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Returns an arrayref of instances of the plugins defined |
199
|
|
|
|
|
|
|
under Taskwarrior's C<kusarigama.plugins> configuration key. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 export_tasks |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
my @tasks = $tw->export_tasks( @query ); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Equivalent to |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
$ task export ...query... |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Returns the list of the tasks. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 new_task |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
my $task = $tw->new_task( \%task ); |
214
|
|
|
|
|
|
|
$task->save; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Creates a new task, but doesn't commit it yet (use C<save> for that). |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 import_task |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
$tw->import_task( \%task ) |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Equivalent to |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
$ task import <json representation of %task> |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head2 calc |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
$result = $tw->calc( qw/ today + 3d / ); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Equivalent to |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
$ task calc today + 3d |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 AUTHOR |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Yanick Champoux <yanick@cpan.org> |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
This software is copyright (c) 2019, 2018, 2017 by Yanick Champoux. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
243
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |