| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Toodledo::Util; |
|
2
|
10
|
|
|
10
|
|
85
|
use strict; |
|
|
10
|
|
|
|
|
20
|
|
|
|
10
|
|
|
|
|
336
|
|
|
3
|
10
|
|
|
10
|
|
56
|
use warnings; |
|
|
10
|
|
|
|
|
21
|
|
|
|
10
|
|
|
|
|
483
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
52
|
use base qw(Exporter); |
|
|
10
|
|
|
|
|
20
|
|
|
|
10
|
|
|
|
|
795
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
3024
|
use File::HomeDir qw(); |
|
|
10
|
|
|
|
|
38249
|
|
|
|
10
|
|
|
|
|
232
|
|
|
10
|
10
|
|
|
10
|
|
737
|
use JSON; |
|
|
10
|
|
|
|
|
13802
|
|
|
|
10
|
|
|
|
|
82
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(debug toodledo_encode toodledo_decode toodledo_time |
|
13
|
|
|
|
|
|
|
arg_encode home preferred_date_format); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub home |
|
17
|
|
|
|
|
|
|
{ |
|
18
|
2
|
|
|
2
|
1
|
14
|
my ($home) = ( File::HomeDir->my_home =~ /(.*)/ ); |
|
19
|
2
|
|
|
|
|
141
|
$home; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub debug |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
0
|
0
|
|
0
|
1
|
0
|
print STDERR "TOODLEDO: ", @_ if $ENV{APP_TOODLEDO_DEBUG}; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub arg_encode |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
0
|
|
|
0
|
1
|
0
|
local $_ = shift; |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
s/\n/\\n/g; |
|
34
|
0
|
0
|
|
|
|
0
|
ref $_ |
|
35
|
|
|
|
|
|
|
? encode_json( $_ ) |
|
36
|
|
|
|
|
|
|
: $_; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub toodledo_encode |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
0
|
|
|
0
|
1
|
0
|
local $_ = shift; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
s/&/%26/g; |
|
45
|
0
|
|
|
|
|
0
|
s/;/%3B/g; |
|
46
|
0
|
|
|
|
|
0
|
$_; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub toodledo_decode |
|
51
|
|
|
|
|
|
|
{ |
|
52
|
16
|
|
|
16
|
1
|
29
|
local $_ = shift; |
|
53
|
|
|
|
|
|
|
|
|
54
|
16
|
|
|
|
|
30
|
s/%26/&/g; |
|
55
|
16
|
|
|
|
|
25
|
s/%3B/;/g; |
|
56
|
16
|
|
|
|
|
267
|
$_; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub preferred_date_format # (0=M D, Y, 1=M/D/Y, 2=D/M/Y, 3=Y-M-D) |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
0
|
|
|
0
|
1
|
|
my ($f_index, $time) = @_; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my @format = ( "%m %d", "%m/%d/%Y", "%d/%m/%Y", "%Y-%m-%d" ); |
|
65
|
0
|
|
|
|
|
|
require POSIX; |
|
66
|
0
|
|
|
|
|
|
POSIX::strftime( $format[$f_index], localtime $time ); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 METHODS |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 arg_encode |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
JSON encoding for parameters submitted to the API. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 home |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
User's home directory. Broken out so you can override it if you want. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 debug |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Outputs debugging print if the environment variable APP_TOODLEDO_DEBUG |
|
93
|
|
|
|
|
|
|
is set. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 toodledo_encode |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Munge strings according to L<http://api.toodledo.com/2/tasks/index.php>: |
|
98
|
|
|
|
|
|
|
"please encode the & character as %26 and the ; character as %3B." |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 toodledo_decode |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Reverse of C<toodledo_encode>. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 preferred_date_format( $index, $time ) |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Outputs a date in the Toodledo user's preferred format: |
|
107
|
|
|
|
|
|
|
0=M D, Y, 1=M/D/Y, 2=D/M/Y, 3=Y-M-D. This is the |
|
108
|
|
|
|
|
|
|
C<$time> is an epoch time and C<$index> is between 0 and 3. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AUTHOR |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Peter Scott C<cpan at psdt.com> |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
|
115
|
|
|
|
|
|
|
|