| 1 | package Taskwarrior::Kusarigama::Core; | ||||||||||||||
| 2 | 21 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||
| 3 | # ABSTRACT: Set of core functions interacting with Taskwarrior | ||||||||||||||
| 4 | 21 | $Taskwarrior::Kusarigama::Core::VERSION = '0.10.0'; | |||||||||||||
| 5 | |||||||||||||||
| 6 | 21 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 21 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 21 | ▶ | use Path::Tiny; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 21 | ▶ | use Moo::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 21 | ▶ | use MooseX::MungeHas; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 21 | ▶ | use IPC::Run3; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 21 | ▶ | use JSON; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 21 | ▶ | use Module::Runtime qw/ use_module /; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | 21 | ▶ | use List::AllUtils qw/ uniq /; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | |||||||||||||||
| 20 | 21 | ▶ | use experimental 'postderef'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 21 | |||||||||||||||
| 22 | 21 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | |||||||||||||||
| 25 | has $_ => ( | ||||||||||||||
| 26 | is => 'rw', | ||||||||||||||
| 27 | 21 | ) for qw/ api version args command rc data /; | |||||||||||||
| 28 | |||||||||||||||
| 29 | |||||||||||||||
| 30 | has pre_command_args => sub { | ||||||||||||||
| 31 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_pre_command_args: not called CC=2 SCAR=17.9
| |||||||||||||||
| 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 | ▶ | return $1 if $args =~ /(.*?)\s*\b$command\b/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | |||||||||||||||
| 40 | # command can be abbreviated | ||||||||||||||
| 41 | 0 | chop $command; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 21 | }; | |||||||||||||
| 45 | |||||||||||||||
| 46 | |||||||||||||||
| 47 | has post_command_args => sub { | ||||||||||||||
| 48 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_post_command_args: not called CC=2 SCAR=17.9
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||
| 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 | ▶ | return $1 if $args =~ /\b$command\b\s*(.*)/; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 56 | |||||||||||||||
| 57 | # command can be abbreviated | ||||||||||||||
| 58 | 0 | chop $command; | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 21 | }; | |||||||||||||
| 62 | |||||||||||||||
| 63 | |||||||||||||||
| 64 | has data_dir => sub { | ||||||||||||||
| 65 | 0 | ▶ | path( $_[0]->data ); | ||||||||||||
|
Subroutine
_build_data_dir: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 66 | 21 | }; | |||||||||||||
| 67 | |||||||||||||||
| 68 | |||||||||||||||
| 69 | has run_task => sub { | ||||||||||||||
| 70 | 0 | ▶ | require Taskwarrior::Kusarigama::Wrapper; | ||||||||||||
|
Subroutine
_build_run_task: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 71 | 0 | Taskwarrior::Kusarigama::Wrapper->new; | |||||||||||||
| 72 | 21 | }; | |||||||||||||
| 73 | |||||||||||||||
| 74 | |||||||||||||||
| 75 | has plugins => sub { | ||||||||||||||
| 76 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.0
Subroutine
_build_plugins: not called CC=2 SCAR=14.0
| |||||||||||||||
| 77 | |||||||||||||||
| 78 | 21 | ▶ | no warnings 'uninitialized'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 79 | |||||||||||||||
| 80 | 0 | [ map { use_module($_)->new( tw => $self ) } | |||||||||||||
| 81 | 0 | ▶ | map { s/^\+// ? $_ : ( 'Taskwarrior::Kusarigama::Plugin::' . $_ ) } | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 82 | 0 | split ',', $self->config->{kusarigama}{plugins} ] | |||||||||||||
| 83 | 21 | }; | |||||||||||||
| 84 | |||||||||||||||
| 85 | before plugins => sub { | ||||||||||||||
| 86 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.7
| |||||||||||||||
| 87 | 21 | ▶ | no warnings 'uninitialized'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 88 | @INC = uniq @INC, | ||||||||||||||
| 89 | 0 | map { s/^\./$self->data_dir/er } | |||||||||||||
| 90 | 0 | split ':', $self->config->{kusarigama}{lib}; | |||||||||||||
| 91 | 21 | }; | |||||||||||||
| 92 | |||||||||||||||
| 93 | |||||||||||||||
| 94 | sub export_tasks { | ||||||||||||||
| 95 | 0 | ▶ | my( $self, @query ) = @_; | ||||||||||||
|
Subroutine
export_tasks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 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 } }; | |||||||||||||
| 100 | } | ||||||||||||||
| 101 | |||||||||||||||
| 102 | |||||||||||||||
| 103 | sub new_task { | ||||||||||||||
| 104 | 0 | ▶ | my ( $self, $task ) = @_; | ||||||||||||
|
Subroutine
new_task: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 105 | 0 | ▶ | $task ||= {}; | ||||||||||||
|
Condition0%0/2
$task ||= {}
MC/DC0%0/1
$task ||= {}
$task
Truth table0%0/2
A
A= $task
| |||||||||||||||
| 106 | |||||||||||||||
| 107 | 0 | return Taskwarrior::Kusarigama::Task->new( $self->run_task, $task ); | |||||||||||||
| 108 | } | ||||||||||||||
| 109 | |||||||||||||||
| 110 | |||||||||||||||
| 111 | sub import_task { | ||||||||||||||
| 112 | 0 | ▶ | my( $self, $task ) = @_; | ||||||||||||
|
Subroutine
import_task: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 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 | ▶ | my( $self, @stuff ) = @_; | ||||||||||||
|
Subroutine
calc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 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 | 21 | 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.10.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) 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 | ||||||||||||||