Kusarigama/Plugin/ProjectDefaults.pm

filter: Statementstmt 100% 39 / 39 Branchbran 71.4% 10 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 87.1% 61 / 70 CC 9 SCAR 12.4
CC
9
Cov
91%
on_add
6.3
project_config
4.1
BEGIN
1.0
CRAP 3.4
« Kusarigama/App/Install.pm ↑ Summary Kusarigama/Plugin/Command/Wait.pm »
1 package Taskwarrior::Kusarigama::Plugin::ProjectDefaults;
2 2 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: assign project-level defaults when creating tasks
4 2 $Taskwarrior::Kusarigama::Plugin::ProjectDefaults::VERSION = '0.11.0';
5  
6 2 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use JSON qw/ from_json /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Hash::Merge qw/ merge /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use MooseX::MungeHas;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 extends 'Taskwarrior::Kusarigama::Plugin';
17  
18 2 with 'Taskwarrior::Kusarigama::Hook::OnAdd';
19  
20 2 ▶use experimental qw/ signatures postderef /;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 ▶sub project_config ($self, $project ) {
Subroutine project_config: called CC=4 SCAR=14.0
Pod undocumented
23 1 ▶ my $config = $self->tw->config->{project} or return {};
Branch: 1 branch
BranchTrueFalseTotal
my $config = $self->tw->config->{"project"} or return {} 0 1 1
24  
25 1 my @levels = split /\./, $project;
26  
27 1 my $aggregated = '';
28  
29 1 ▶ while( my $l = shift @levels ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = shift @levels) 2 1 3
30 2 ▶ $config = $config->{$l} or last;
Branch: 1 branch
BranchTrueFalseTotal
$config = $config->{$l} or last 0 2 2
31 2 $aggregated = $config->{defaults} .' '. $aggregated;
32 }
33  
34 1 return $aggregated;
35 }
36  
37 ▶sub on_add ( $self, $task ) {
Subroutine on_add: called CC=6 SCAR=18.4
Pod undocumented
38 # no project? nothing to do
39 1 ▶ my $project = $task->{project} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $project = $task->{"project"} or return 0 1 1
40  
41 1 ▶ my $defaults = $self->project_config( $project )
Branch: 1 branch
BranchTrueFalseTotal
my $defaults = $self->project_config($project) or return 0 1 1
42 or return;
43  
44 1 ▶ $task->{$1} ||= $2 while $defaults =~ /\b(\S+):(\S+)\b/g;
Branch: 1 branch
BranchTrueFalseTotal
$defaults =~ /\b(\S+):(\S+)\b/g and do { $task->{$1} ||= $2 } 2 1 3
Condition66%2/3
$task->{$1} ||= $2
l!l&&r!l&&!r
110
MC/DC0%0/2
$task->{$1} ||= $2
$task->{$1} $2
Truth table66%2/3
A ||= B
A= $task->{$1}B= $2
ABresult
1X1
011
000
45  
46 1 ▶ push $task->{tags}->@*, $1 while $defaults =~ /\+(\S+)/g;
Branch: 1 branch
BranchTrueFalseTotal
$defaults =~ /\+(\S+)/g and do { push @{$$task{"tags"}}, $1 } 2 1 3
47 }
48  
49 2 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
« Kusarigama/App/Install.pm ↑ Summary Kusarigama/Plugin/Command/Wait.pm »