line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Taskwarrior::Kusarigama::Plugin::ProjectDefaults; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: assign project-level defaults when creating tasks |
4
|
|
|
|
|
|
|
$Taskwarrior::Kusarigama::Plugin::ProjectDefaults::VERSION = '0.11.0'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
105180
|
use 5.10.0; |
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
603
|
use JSON qw/ from_json /; |
|
1
|
|
|
|
|
12121
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
615
|
use Hash::Merge qw/ merge /; |
|
1
|
|
|
|
|
9507
|
|
|
1
|
|
|
|
|
63
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
559
|
use Moo; |
|
1
|
|
|
|
|
9179
|
|
|
1
|
|
|
|
|
7
|
|
14
|
1
|
|
|
1
|
|
2000
|
use MooseX::MungeHas; |
|
1
|
|
|
|
|
4012
|
|
|
1
|
|
|
|
|
7
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
extends 'Taskwarrior::Kusarigama::Plugin'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
with 'Taskwarrior::Kusarigama::Hook::OnAdd'; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
1338
|
use experimental qw/ signatures postderef /; |
|
1
|
|
|
|
|
3469
|
|
|
1
|
|
|
|
|
5
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
0
|
2
|
sub project_config ($self, $project ) { |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
23
|
1
|
50
|
|
|
|
15
|
my $config = $self->tw->config->{project} or return {}; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
124
|
my @levels = split /\./, $project; |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
3
|
my $aggregated = ''; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
4
|
while( my $l = shift @levels ) { |
30
|
2
|
50
|
|
|
|
7
|
$config = $config->{$l} or last; |
31
|
2
|
|
|
|
|
9
|
$aggregated = $config->{defaults} .' '. $aggregated; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
5
|
return $aggregated; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
0
|
3200
|
sub on_add ( $self, $task ) { |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
38
|
|
|
|
|
|
|
# no project? nothing to do |
39
|
1
|
50
|
|
|
|
5
|
my $project = $task->{project} or return; |
40
|
|
|
|
|
|
|
|
41
|
1
|
50
|
|
|
|
10
|
my $defaults = $self->project_config( $project ) |
42
|
|
|
|
|
|
|
or return; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
66
|
|
|
24
|
$task->{$1} ||= $2 while $defaults =~ /\b(\S+):(\S+)\b/g; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
12
|
push $task->{tags}->@*, $1 while $defaults =~ /\+(\S+)/g; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=pod |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=encoding UTF-8 |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Taskwarrior::Kusarigama::Plugin::ProjectDefaults - assign project-level defaults when creating tasks |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 VERSION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
version 0.11.0 |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SYNOPSIS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$ task config project.dailies.defaults 'recur:1d +daily due:tomorrow' |
68
|
|
|
|
|
|
|
$ task add water the plants project:dailies |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
If a task is created with a project, the plugin looks if there is a |
73
|
|
|
|
|
|
|
C<defaults> assigned to the project, and if so, defaults the values. |
74
|
|
|
|
|
|
|
In the case of array values (i.e., tags), the defaults are appended |
75
|
|
|
|
|
|
|
to the already provided values (if any). |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The defaults of hierarchical projects are cumulative. So you can do things like |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$ task config project.work.defaults 'priority:M' |
80
|
|
|
|
|
|
|
$ task config project.work.projectx.defaults 'due:eom' |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$ task add ticket ABC-123 project:work.projectx |
83
|
|
|
|
|
|
|
# will get due:eom and priority:M |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Yanick Champoux <yanick@cpan.org> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This software is copyright (c) 2018, 2017 by Yanick Champoux. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
94
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |