line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::todoist; |
2
|
|
|
|
|
|
|
$App::todoist::VERSION = '0.04'; |
3
|
1
|
|
|
1
|
|
509
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
498
|
use Net::Todoist; |
|
1
|
|
|
|
|
36675
|
|
|
1
|
|
|
|
|
27
|
|
7
|
1
|
|
|
1
|
|
7
|
use Carp qw/ croak /; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
53
|
|
8
|
1
|
|
|
1
|
|
431
|
use AppConfig::Std; |
|
1
|
|
|
|
|
885767
|
|
|
1
|
|
|
|
|
45
|
|
9
|
1
|
|
|
1
|
|
510
|
use File::Slurper qw/ read_lines /; |
|
1
|
|
|
|
|
9748
|
|
|
1
|
|
|
|
|
633
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
12
|
|
|
|
|
|
|
{ |
13
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
14
|
0
|
|
0
|
|
|
|
my $obj = bless({}, $class) |
15
|
|
|
|
|
|
|
|| croak "Can't instantiate App::todoist\n"; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
return $obj; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub process_options |
21
|
|
|
|
|
|
|
{ |
22
|
0
|
|
|
0
|
0
|
|
my ($self, $opts) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
0
|
|
|
|
my $config = AppConfig::Std->new() |
25
|
|
|
|
|
|
|
|| croak "Can't instantiate AppConfig::Std\n"; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$config->define('token', { ARGCOUNT => 1 }); |
28
|
0
|
|
|
|
|
|
$config->define('project', { ARGCOUNT => 1 }); |
29
|
0
|
|
|
|
|
|
$config->define('importfile', { ARGCOUNT => 1, ALIAS => 'i' }); |
30
|
0
|
|
|
|
|
|
$config->define('priority', { ARGCOUNT => 1, ALIAS => 'p', DEFAULT => 4 }); |
31
|
0
|
|
|
|
|
|
$config->define('add-project', { ARGCOUNT => 1, ALIAS => 'ap' }); |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
0
|
|
|
|
if (defined($ENV{HOME}) && -f "$ENV{HOME}/.todoist") { |
34
|
0
|
|
|
|
|
|
my $filename = "$ENV{HOME}/.todoist"; |
35
|
0
|
0
|
|
|
|
|
if (((stat($filename))[2] & 36) != 0) { |
36
|
0
|
|
|
|
|
|
croak "your config file ($filename) is readable by others!\n"; |
37
|
|
|
|
|
|
|
} |
38
|
0
|
0
|
|
|
|
|
$config->file($filename) || exit 1; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if ($opts->{argv}) { |
42
|
|
|
|
|
|
|
$config->args($opts->{argv}) |
43
|
0
|
0
|
|
|
|
|
|| die "run \"$0 -help\" to see valid options\n"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
croak "you must provide a token\n" unless $config->token; |
47
|
0
|
0
|
0
|
|
|
|
if (!$config->project && !$config->get('add-project')) { |
48
|
0
|
|
|
|
|
|
croak "you must either project a project, or add a project\n"; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$self->{config} = $config; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
0
|
|
|
|
my $todoist = Net::Todoist->new(token => $config->token) |
54
|
|
|
|
|
|
|
|| croak "failed to connect to todoist\n"; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->{todoist} = $todoist; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ($config->project) { |
59
|
0
|
|
|
|
|
|
my @projects = $todoist->getProjects; |
60
|
0
|
|
|
|
|
|
my ($project) = grep { $_->{name} eq $config->project } @projects; |
|
0
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if (not defined $project) { |
62
|
0
|
|
|
|
|
|
croak "couldn't find project '", $config->project, "' in todoist\n" |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
$self->{project_id} = $project->{id}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub config |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
return $self->{config}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub todoist |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
77
|
0
|
|
|
|
|
|
return $self->{todoist}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub run |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
0
|
0
|
|
my ($self, $opts) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->process_options($opts); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if ($self->config->importfile) { |
87
|
0
|
|
|
|
|
|
my @tasks = read_lines($self->config->importfile); |
88
|
0
|
|
|
|
|
|
foreach my $task (@tasks) { |
89
|
|
|
|
|
|
|
$self->todoist->addItem( |
90
|
|
|
|
|
|
|
project_id => $self->{project_id}, |
91
|
0
|
|
|
|
|
|
content => $task, |
92
|
|
|
|
|
|
|
priority => $self->config->priority, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
printf STDERR "%d tasks added from %s\n", int(@tasks), |
96
|
|
|
|
|
|
|
$self->config->importfile; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if ($self->config->get('add-project')) { |
100
|
0
|
|
|
|
|
|
$self->todoist->addProject(name => $self->config->get('add-project')); |
101
|
0
|
|
|
|
|
|
my @projects = $self->todoist->getProjects; |
102
|
0
|
|
|
|
|
|
my ($project) = grep { $_->{name} eq $self->config->get('add-project') } @projects; |
|
0
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
if (defined($project)) { |
104
|
0
|
|
|
|
|
|
print STDERR "Project added - id = ", $project->{id}, "\n"; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
0
|
|
|
|
|
|
die "Failed to add project\n"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 NAME |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
App::todoist - command-line for manipulating your todoist.com todo list |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SYNOPSIS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Add something here |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 DESCRIPTION |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This module implements the functionality behind the C script. |
125
|
|
|
|
|
|
|
You should look at the documentation for that. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 REPOSITORY |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
L |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 AUTHOR |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Neil Bowers Eneilb@cpan.orgE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Neil Bowers . |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
140
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|