Kusarigama/App/Review.pm

filter: Statementstmt 33.6% 41 / 122 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 38.7% 12 / 31 Podpod 0.0% 0 / 8 totaltotal 26.5% 53 / 200 CC 20 SCAR 39.2
CC
20
Cov
26%
run
182.0
decimate_group
12.0
pick_decimate
12.0
CRAP 50.2
« Kusarigama/Plugin/Command/Open.pm ↑ Summary Kusarigama/Plugin.pm »
1 package Taskwarrior::Kusarigama::App::Review;
2 1 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: interactive review of unprioritized tasks
4 1 $Taskwarrior::Kusarigama::App::Review::VERSION = '0.11.0';
5  
6 1 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Taskwarrior::Kusarigama::Wrapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use List::UtilsBy qw/ partition_by /;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use List::AllUtils qw/ pairmap sum shuffle/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Term::ANSIScreen qw/:screen :cursor :color/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use IO::Prompt::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Prompt::ReadKey ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use MooseX::App::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use MooseX::MungeHas;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use experimental 'postderef', 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 has tw => sub {
25 0 ▶ Taskwarrior::Kusarigama::Wrapper->new
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 1 };
27  
28 has tasks => sub {
29 0 ▶ return +{ partition_by { $_->{priority} || 'U' } $_[0]->tw->export( '+READY' ) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Subroutine _build_tasks: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_->{"priority"} or "U" 0 0 0
30 1 };
31  
32 # for things that we don't want to wait to
33 # see the result. We just fire out and
34 # stop thinking about it
35 ▶sub async_do ($self,$code) {
Subroutine async_do: not called CC=2 SCAR=17.9
Pod undocumented
36 0 ▶ return if fork;
Branch: 1 branch
BranchTrueFalseTotal
if fork 0 0 0
37  
38 0 $code->();
39 0 exit;
40 }
41  
42 has _prompt => (
43 is => 'ro',
44 lazy => 1,
45 0 ▶ default => sub { Prompt::ReadKey->new; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 1 handles => { 'menu_prompt' => 'prompt' },
47 );
48  
49 ▶sub nbr_prioritized_tasks($self) {
Subroutine nbr_prioritized_tasks: not called CC=1 SCAR=6.9
Pod undocumented
50 0 return sum map { scalar $self->tasks->{$_}->@* } qw/ H M L /;
51 }
52  
53 ▶sub decimate($self) {
Subroutine decimate: not called CC=1 SCAR=6.9
Pod undocumented
54 0 $self->decimate_group( 0.10, 'H', 'M' );
55 0 $self->clear_tasks;
56 0 $self->decimate_group( 0.60, 'M', 'L' );
57 }
58  
59 ▶sub decimate_group($self,$target,$prio1,$prio2) {
Subroutine decimate_group: not called CC=3 SCAR=24.8
Pod undocumented
60 0 my $nbr = int $target * $self->nbr_prioritized_tasks;
61  
62 0 my $main = $self->tasks->{$prio1};
63  
64 0 say "Decimating $prio1 priority...";
65 0 say "We have @{[ scalar @$main ]}, we want $nbr";
66  
67 # do we have enough?
68 0 ▶ while( $nbr > @$main ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nbr > @$main) 0 0 0
69 0 say "need ", $nbr - @$main, ' more ', $prio1, ' tasks';
70 0 say "Promote one!\n\n";
71 0 my $task = $self->pick_decimate( $self->tasks->{$prio2} );
72  
73 0 push @$main, $task;
74 $self->async_do(sub{
75 0 ▶ $task->mod( 'priority:' . $prio1 );
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 0 });
77 }
78  
79 # do we have too much?
80 0 ▶ while( $nbr < @$main ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nbr < @$main) 0 0 0
81 0 say "need ", @$main - $nbr, ' less ', $prio1, ' tasks';
82 0 say "Demote one!\n\n";
83 0 my $task = $self->pick_decimate( $self->tasks->{$prio1} );
84  
85 0 shift @$main;
86 $self->async_do(sub{
87 0 ▶ $task->mod( 'priority:' . $prio2);
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 });
89 }
90 }
91  
92 ▶sub pick_decimate($self, $tasks ) {
Subroutine pick_decimate: not called CC=3 SCAR=24.8
Pod undocumented
93 0 my @contenders = (shuffle @$tasks)[0..9];
94  
95 0 for ( 0..9 ) {
96 0 my $c = $contenders[$_];
97  
98 printf "%2d %4d %s%s%s\n",
99 $_, $contenders[$_]{id},
100 colored( ['blue'], $c->{project} ? '['.$c->{project}.'] ' : '' ),
101 $contenders[$_]{description},
102 0 ▶ ( join ' ', map { colored [ 'cyan' ], " +$_" } @{ $c->{tags} } );
Branch: 1 branch
BranchTrueFalseTotal
$c->{'project'} ? : 0 0 0
103 }
104  
105 0 print "\n\n";
106  
107 my $action = $self->menu_prompt( prompt => "which one?",
108 options => [
109 0 map { +{ keys => [ $_ ], name => $_ } } 0..9
110 ],
111 help_keys => [ '?' ],
112 );
113  
114 0 @$tasks = grep { $_->{uuid} ne $contenders[$action]->{uuid} } @$tasks;
115  
116 0 return $contenders[$action];
117 }
118  
119 sub run {
120 0 ▶ my $self = shift;
Subroutine run: not called CC=13 SCAR=52.0
Pod undocumented
121  
122 0 ▶ while ( my $next = shift $self->tasks->{U}->@* ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next = shift @{$self->tasks->{"U"}}) 0 0 0
123 0 cls;
124 0 $self->print_summary_line;
125  
126 0 while() {
127 0 say join "\n", $self->tw->info( $next->{uuid} );
128  
129 0 my $action = $self->menu_prompt( prompt => "whatcha gonna do?",
130 case_insensitive => 0,
131 options => [
132 { name => 'h', doc => 'high priority', keys => [ 'h' ] },
133 { name => 'H', doc => 'high priority and next', keys => [ 'H' ] },
134 { name => 'm', doc => 'med priority', keys => [ 'm' ] },
135 { name => 'M', doc => 'med priority and next', keys => [ 'M' ] },
136 { name => 'l', doc => 'low priority', keys => [ 'l' ] },
137 { name => 'L', doc => 'low priority and next', keys => [ 'L' ] },
138 { name => 'mod', doc => 'generic modification', keys => [ '.' ] },
139 { name => 'append', doc => 'append', keys => [ ',' ] },
140 { name => 'done', keys => [ 'd' ] },
141 { name => 'delete', keys => [ 'D' ] },
142 { name => 'wait', keys => [ 'w' ] },
143 { name => 'quit', keys => [ 'q' ] },
144 { name => 'annotate', keys => [ 'a' ] },
145 { name => 'show again', keys => [ ' ' ] },
146 { name => 'next', doc => 'next', keys => [ 'n' ] },
147 ],
148 help_keys => [ '?' ],
149 );
150  
151 0 ▶ if ( $action eq 'quit' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "quit") 0 0 0
152 0 say "no, come back!";
153 0 return;
154 }
155  
156 0 ▶ if ( $action eq 'annotate' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($action eq 'annotate') { } 0 0 0
elsif ($action eq 'wait') { } 0 0 0
157 0 $next->annotate( prompt 'note' );
158 }
159 elsif ( $action eq 'wait' ) {
160 0 $self->wait_menu($next);
161 0 last;
162 }
163 0 ▶ if( $action =~ /^[hml]$/i ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($action =~ /^[hml]$/iu) { } 0 0 0
elsif ($action eq 'mod') { } 0 0 0
elsif ($action eq 'append') { } 0 0 0
elsif ($action eq 'done') { } 0 0 0
elsif ($action eq 'delete') { } 0 0 0
164 0 ▶ if ( $action eq uc $action ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq uc $action) { } 0 0 0
165 $self->async_do(sub{
166 0 ▶ $next->mod( 'priority:' . uc $action );
Subroutine __ANON__: not called CC=1 SCAR=6.9
167 0 });
168 }
169 else {
170 0 $next->mod( 'priority:' . uc $action );
171 }
172 }
173 elsif ( $action eq 'mod' ) {
174 0 $next->mod( prompt "mod" );
175 }
176 elsif ( $action eq 'append' ) {
177 0 $next->append( prompt "append" );
178 }
179 elsif ( $action eq 'done' ) {
180 0 ▶ $self->async_do(sub{ $next->done; });
Subroutine __ANON__: not called CC=1 SCAR=6.9
181 0 last;
182 }
183 elsif ( $action eq 'delete' ) {
184 # TODO I think it fails because underneath it tries to ask
185 # interactively if deleting is okay
186 0 $next->delete( { 'rc.confirmation' => 'no' } );
187 0 last;
188 }
189  
190  
191 0 ▶ last if $action eq 'next' or $action eq uc $action;
Branch: 1 branch
BranchTrueFalseTotal
if $action eq "next" or $action eq uc $action 0 0 0
Condition0%0/3
$action eq "next" or $action eq uc $action
l!l&&r!l&&!r
000
MC/DC0%0/2
$action eq "next" or $action eq uc $action
$action eq "next" $action eq uc $action
Truth table0%0/3
A or B
A= $action eq "next"B= $action eq uc $action
ABresult
1X1
011
000
192 }
193  
194  
195 }
196  
197 0 say "congrats! no task left unprioritized!";
198  
199 }
200  
201 ▶sub wait_menu($self,$task) {
Subroutine wait_menu: not called CC=2 SCAR=17.9
Pod undocumented
202  
203 0 my $action = $self->menu_prompt( prompt => "how long?",
204 case_insensitive => 0,
205 options => [
206 { name => 'eow', doc => 'end of week priority', keys => [ 'e' ] },
207 { name => '1w', doc => 'one week', keys => [ 'w' ] },
208 { name => '1m', doc => 'one month', keys => [ 'm' ] },
209 { name => '3m', doc => 'three months', keys => [ 'M' ] },
210 { name => 'edit', doc => 'custom', keys => [ '.' ] },
211 ],
212 help_keys => [ '?' ],
213 );
214  
215 0 ▶ if( $action eq 'edit' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "edit") 0 0 0
216 0 $action = prompt 'wait';
217 }
218  
219 $self->async_do(sub{
220 0 ▶ $task->mod( 'wait:'.$action );
Subroutine __ANON__: not called CC=1 SCAR=6.9
221 0 });
222 }
223  
224 ▶sub print_summary_line($self) {
Subroutine print_summary_line: not called CC=1 SCAR=6.9
Pod undocumented
225  
226 0 ▶ my %prio = pairmap { $a => scalar @$b } $self->tasks->%*;
Subroutine __ANON__: not called CC=1 SCAR=6.9
227  
228 0 my @colors = ( H => 'red', M => 'blue', L => 'cyan', 'U' => 'green' );
229  
230 0 ▶ say join ' ', pairmap { colored [ $b ], $prio{$a}, $a } @colors;
Subroutine __ANON__: not called CC=1 SCAR=6.9
231 }
232  
233 1 1;
234  
235 __END__
236  
237 =pod
238  
239 =encoding UTF-8
240  
241 =head1 NAME
242  
243 Taskwarrior::Kusarigama::App::Review - interactive review of unprioritized tasks
244  
245 =head1 VERSION
246  
247 version 0.11.0
248  
249 =head1 SYNOPSIS
250  
251 $ task-kusarigama review
252  
253 =head1 DESCRIPTION
254  
255 Interactive review of tasks.
256  
257 The command gathers all the tasks that are not proritized and
258 display them one by one, providing a menu of actions to do.
259  
260 Key Name Description
261 h h high priority
262 H H high priority and next
263 m m med priority
264 M M med priority and next
265 l l low priority
266 L L low priority and next
267 . mod generic modification
268 , append append
269 d done
270 D delete
271 w wait
272 q quit
273 a annotate
274 n next next
275 ? help List available commands
276  
277 =head1 AUTHOR
278  
279 Yanick Champoux <yanick@cpan.org>
280  
281 =head1 COPYRIGHT AND LICENSE
282  
283 This software is copyright (c) 2018, 2017 by Yanick Champoux.
284  
285 This is free software; you can redistribute it and/or modify it under
286 the same terms as the Perl 5 programming language system itself.
287  
288 =cut
« Kusarigama/Plugin/Command/Open.pm ↑ Summary Kusarigama/Plugin.pm »