File Coverage

blib/lib/WWW/Asana/Task.pm
Criterion Covered Total %
statement 7 33 21.2
branch 0 20 0.0
condition n/a
subroutine 3 20 15.0
pod 0 13 0.0
total 10 86 11.6


line stmt bran cond sub pod time code
1             package WWW::Asana::Task;
2             BEGIN {
3 1     1   2302 $WWW::Asana::Task::AUTHORITY = 'cpan:GETTY';
4             }
5             {
6             $WWW::Asana::Task::VERSION = '0.003';
7             }
8             # ABSTRACT: Asana Task Class
9              
10 1     1   12 use MooX;
  1         2  
  1         10  
11              
12             with 'WWW::Asana::Role::HasClient';
13             with 'WWW::Asana::Role::HasResponse';
14             with 'WWW::Asana::Role::NewFromResponse';
15              
16             with 'WWW::Asana::Role::HasFollowers';
17             with 'WWW::Asana::Role::HasStories';
18              
19             with 'WWW::Asana::Role::CanReload';
20             with 'WWW::Asana::Role::CanUpdate';
21             with 'WWW::Asana::Role::CanCreate';
22              
23 1     1   868 use DateTime::Format::ISO8601;
  1         2  
  1         1169  
24              
25 0     0 0   sub own_base_args { 'tasks', shift->id }
26 0     0 0   sub reload_base_args { 'Task', 'GET' }
27             sub update_args {
28 0     0 0   my ( $self ) = @_;
29 0     0     'Task', 'PUT', $self->own_base_args, $self->value_args, sub { workspace => $self->workspace };
  0            
30             }
31             sub create_args {
32 0     0 0   my ( $self ) = @_;
33 0     0     'Task', 'POST', 'tasks', $self->value_args, sub { workspace => $self->workspace };
  0            
34             }
35              
36             sub value_args {
37 0     0 0   my ( $self ) = @_;
38             return {
39 0 0         workspace => $self->workspace->id,
    0          
    0          
    0          
    0          
40             assignee => $self->has_assignee ? $self->assignee->id : undef,
41             $self->has_name ? ( name => $self->name ) : (),
42             $self->has_notes ? ( notes => $self->notes ) : (),
43             $self->has_completed ? ( completed => $self->completed_value ) : (),
44             $self->has_due_on ? ( due_on => $self->due_on_value ) : (),
45             };
46             }
47              
48             has id => (
49             is => 'ro',
50             predicate => 1,
51             );
52              
53             has assignee => (
54             is => 'rw',
55             isa => sub {
56             die "assignee must be a WWW::Asana::User" unless ref $_[0] eq 'WWW::Asana::User';
57             },
58             predicate => 1,
59             clearer => 'clear_assignee',
60             );
61              
62             has assignee_status => (
63             is => 'ro',
64             isa => sub {
65             die "assignee_status must be inbox, later, today or upcoming"
66             unless grep { $_[0] eq $_ } qw( inbox later today upcoming );
67             },
68             );
69              
70             has created_at => (
71             is => 'ro',
72             isa => sub {
73             die "created_at must be a DateTime" unless ref $_[0] eq 'DateTime';
74             },
75             predicate => 1,
76             );
77              
78             has completed => (
79             is => 'rw',
80             predicate => 1,
81             );
82 0 0   0 0   sub completed_value { shift->completed ? 'true' : 'false' }
83              
84             has completed_at => (
85             is => 'ro',
86             isa => sub {
87             die "completed_at must be a DateTime" unless ref $_[0] eq 'DateTime';
88             },
89             predicate => 1,
90             );
91              
92             has due_on => (
93             is => 'rw',
94             isa => sub {
95             die "due_on must be a DateTime" unless ref $_[0] eq 'DateTime';
96             },
97             predicate => 1,
98             clearer => 'clear_due_on',
99             );
100 0     0 0   sub due_on_value { shift->due_on->ymd('-') }
101              
102             has name => (
103             is => 'rw',
104             predicate => 1,
105             );
106              
107             has notes => (
108             is => 'rw',
109             predicate => 1,
110             );
111              
112             has workspace => (
113             is => 'rw',
114             isa => sub {
115             die "workspace must be a WWW::Asana::Workspace" unless ref $_[0] eq 'WWW::Asana::Workspace';
116             },
117             required => 1,
118             );
119              
120             sub projects {
121 0     0 0   my ( $self ) = @_;
122 0     0     $self->do('[Project]', 'GET', $self->own_base_args, 'projects', sub { workspace => $self->workspace });
  0            
123             }
124              
125             sub add_project {
126 0     0 0   my ( $self, $project ) = @_;
127 0 0         return $self->do('', 'POST', $self->own_base_args, 'addProject', { project => $project->id } ) eq 1 ? 1 : 0;
128             }
129              
130             sub remove_project {
131 0     0 0   my ( $self, $project ) = @_;
132 0 0         return $self->do('', 'POST', $self->own_base_args, 'removeProject', { project => $project->id } ) eq 1 ? 1 : 0;
133             }
134              
135             sub tags {
136 0     0 0   my ( $self ) = @_;
137 0     0     $self->do('[Tag]', 'GET', $self->own_base_args, 'tags', sub { workspace => $self->workspace });
  0            
138             }
139              
140             sub add_tag {
141 0     0 0   my ( $self, $tag ) = @_;
142 0 0         return $self->do('', 'POST', $self->own_base_args, 'addTag', { tag => $tag->id } ) eq 1 ? 1 : 0;
143             }
144              
145             sub remove_tag {
146 0     0 0   my ( $self, $tag ) = @_;
147 0 0         return $self->do('', 'POST', $self->own_base_args, 'removeTag', { tag => $tag->id } ) eq 1 ? 1 : 0;
148             }
149              
150             1;
151              
152             __END__