| 1 | package Taskwarrior::Kusarigama::Task; | ||||||||||||||||||||
| 2 | 7 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||
| 3 | # ABSTRACT: per-task Taskwarrior::Kusarigama::Wrapper | ||||||||||||||||||||
| 4 | 7 | $Taskwarrior::Kusarigama::Task::VERSION = '0.10.0'; | |||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 7 | ▶ | use experimental 'postderef'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 7 | ▶ | use Clone; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | sub new { | ||||||||||||||||||||
| 13 | 4 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 14 | 4 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 4 | my $data = pop; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 4 | ▶ | $data->{_wrapper} = shift if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 4 | bless $data, $class; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | sub add_note { | ||||||||||||||||||||
| 24 | 1 | ▶ | my ( $self, $note ) = @_; | ||||||||||||||||||
|
Subroutine
add_note: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 1 | ▶ | $self->{annotations} ||= []; | ||||||||||||||||||
|
Condition50%1/2
$self->{"annotations"} ||= []
MC/DC0%0/1
$self->{"annotations"} ||= []
$self->{"annotations"}
Truth table50%1/2
A
A= $self->{"annotations"}
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | require DateTime::Functions; | |||||||||||||||||||
| 29 | 1 | my $now = DateTime::Functions::now(); | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 1 | my $timestamp = $now->ymd("") . 'T' . $now->hms("") . "Z"; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | push $self->{annotations}->@*, { | ||||||||||||||||||||
| 34 | 1 | entry => $timestamp, | |||||||||||||||||||
| 35 | description => $note, | ||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub clone { | ||||||||||||||||||||
| 41 | 1 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
clone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 1 | my $cloned = Clone::clone($self); | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 1 | delete $cloned->{$_} for qw/ id uuid entry modified end urgency status /; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 1 | return $self->new( $self->{_wrapper}, $cloned ); | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | sub data { | ||||||||||||||||||||
| 51 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 52 | 2 | require List::Util; | |||||||||||||||||||
| 53 | 2 | ▶ | return { List::Util::pairgrep( sub { $a !~ /^_/ }, %$self ) } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | sub save { | ||||||||||||||||||||
| 57 | 2 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
save: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 2 | my $new = $self->{_wrapper}->save($self->data); | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 2 | %$self = %$new; | |||||||||||||||||||
| 62 | # delete $self->{$_} for keys %$self; | ||||||||||||||||||||
| 63 | # $self->{$_} = $new->{$_} for keys %$new; | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 2 | return $self; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | sub AUTOLOAD { | ||||||||||||||||||||
| 70 | 5 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=5 SCAR=16.4
| |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 5 | (my $meth = our $AUTOLOAD) =~ s/.+:://; | |||||||||||||||||||
| 73 | 5 | ▶ | return if $meth eq 'DESTROY'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 1 | $meth =~ tr/_/-/; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 1 | ▶ | $self->{_wrapper} ||= Taskwarrior::Kusarigama::Wrapper->new; | ||||||||||||||||||
|
Condition33%1/3
$self->{"_wrapper"} ||= "Taskwarrior::Kusarigama::Wrapper"->new
MC/DC0%0/2
$self->{"_wrapper"} ||= "Taskwarrior::Kusarigama::Wrapper"->new
$self->{"_wrapper"}
"Taskwarrior::Kusarigama::Wrapper"->new
Truth table33%1/3
A ||= B
A= $self->{"_wrapper"}B= "Taskwarrior::Kusarigama::Wrapper"->new
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 1 | ▶ | unshift @_, [] unless 'ARRAY' eq ref $_[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 7 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 82 | my $uuid = $self->{uuid} | ||||||||||||||||||||
| 83 | 1 | ▶ | or croak "task doesn't have an uuid\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 1 | push $_[0]->@*, { uuid => $uuid }; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 1 | return $self->{_wrapper}->RUN($meth, @_); | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 7 | 1; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | =pod | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =encoding UTF-8 | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =head1 NAME | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | Taskwarrior::Kusarigama::Task - per-task Taskwarrior::Kusarigama::Wrapper | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =head1 VERSION | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | version 0.10.0 | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =head1 SYNOPSIS | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | use Taskwarrior::Kusarigama::Wrapper; | ||||||||||||||||||||
| 110 | use Taskwarrior::Kusarigama::Task; | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | my $tw = Taskwarrior::Kusarigama::Wrapper->new; | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | my ( $task ) = $tw->export; | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | say $task->info; | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =head1 DESCRIPTION | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | Thin wrapper around the task hashrefs that calls L<Taskwarrior::Kusarigama::Wrapper>. | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | Unless specified otherwise, the task must have | ||||||||||||||||||||
| 123 | an C<uuid> to be acted upon. | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head1 METHODS | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | =head2 new | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | my $task = Taskwarrior::Kusarigama::Task->new( \%data ); | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | my $task = Taskwarrior::Kusarigama::Task->new( $wrapper, \%data ); | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | Constructor. Takes in a raw hashref of the task's | ||||||||||||||||||||
| 134 | attributes as would be give by C<task export>, and | ||||||||||||||||||||
| 135 | an optional C<$wrapper>, which is the | ||||||||||||||||||||
| 136 | L<Taskwarrior::Kusarigama::Wrapper> | ||||||||||||||||||||
| 137 | object to use. The wrapper object can also | ||||||||||||||||||||
| 138 | be passed via a C<_wrapper> attribute. | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | # equivalent to the two-argument 'new' | ||||||||||||||||||||
| 141 | my $task = Taskwarrior::Kusarigama::Task->new( | ||||||||||||||||||||
| 142 | { _wrapper => $wrapper, %data } | ||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =head2 clone | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | Clone the current task. All attributes are copied, except for | ||||||||||||||||||||
| 148 | C<id>, C<uuid>, C<urgency>, C<status>, C<entry> and C<modified>. | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =head1 AUTHOR | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | Yanick Champoux <yanick@cpan.org> | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | This software is copyright (c) 2018, 2017 by Yanick Champoux. | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 159 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||