line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::SimplenoteSync::Note; |
2
|
|
|
|
|
|
|
$App::SimplenoteSync::Note::VERSION = '0.2.1'; |
3
|
|
|
|
|
|
|
# ABSTRACT: stores notes in plain files, |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
88288
|
use v5.10; |
|
2
|
|
|
|
|
10
|
|
6
|
2
|
|
|
2
|
|
969
|
use Moose; |
|
2
|
|
|
|
|
770606
|
|
|
2
|
|
|
|
|
12
|
|
7
|
2
|
|
|
2
|
|
13317
|
use MooseX::Types::Path::Class; |
|
2
|
|
|
|
|
244732
|
|
|
2
|
|
|
|
|
11
|
|
8
|
2
|
|
|
2
|
|
1580
|
use Try::Tiny; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
111
|
|
9
|
2
|
|
|
2
|
|
11
|
use namespace::autoclean; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'WebService::Simplenote::Note'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
1453
|
use Method::Signatures; |
|
2
|
|
|
|
|
102362
|
|
|
2
|
|
|
|
|
13
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has '+title' => (trigger => \&_title_to_filename,); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has file => ( |
18
|
|
|
|
|
|
|
is => 'rw', |
19
|
|
|
|
|
|
|
isa => 'Path::Class::File', |
20
|
|
|
|
|
|
|
coerce => 1, |
21
|
|
|
|
|
|
|
traits => ['NotSerialised'], |
22
|
|
|
|
|
|
|
trigger => \&_has_markdown_ext, |
23
|
|
|
|
|
|
|
predicate => 'has_file', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has file_extension => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
isa => 'HashRef', |
29
|
|
|
|
|
|
|
traits => ['NotSerialised'], |
30
|
|
|
|
|
|
|
default => sub { |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
default => 'txt', |
33
|
|
|
|
|
|
|
markdown => 'mkdn', |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
}, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has notes_dir => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
isa => 'Path::Class::Dir', |
41
|
|
|
|
|
|
|
traits => ['NotSerialised'], |
42
|
|
|
|
|
|
|
required => 1, |
43
|
|
|
|
|
|
|
default => sub { |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
if ($self->has_file) { |
46
|
|
|
|
|
|
|
return $self->file->dir; |
47
|
|
|
|
|
|
|
} else { |
48
|
|
|
|
|
|
|
return Path::Class::Dir->new($ENV{HOME}, 'Notes'); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has ignored => ( |
54
|
|
|
|
|
|
|
is => 'rw', |
55
|
|
|
|
|
|
|
isa => 'Bool', |
56
|
|
|
|
|
|
|
traits => ['NotSerialised'], |
57
|
|
|
|
|
|
|
default => 0, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# set the markdown systemtag if the file has a markdown extension |
61
|
2
|
|
|
2
|
|
191203
|
method _has_markdown_ext(@_) { |
|
3
|
|
|
3
|
|
6
|
|
62
|
3
|
|
|
|
|
84
|
my $ext = $self->file_extension->{markdown}; |
63
|
|
|
|
|
|
|
|
64
|
3
|
50
|
33
|
|
|
97
|
if ($self->file =~ m/\.$ext$/ && !$self->is_markdown) { |
65
|
0
|
|
|
|
|
0
|
$self->set_markdown; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
3
|
|
|
|
|
187
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Convert note's title into file |
72
|
2
|
50
|
66
|
2
|
|
7742
|
method _title_to_filename(Str $title, Str $old_title?) { |
|
4
|
50
|
33
|
4
|
|
22
|
|
|
4
|
50
|
66
|
|
|
21
|
|
|
4
|
50
|
|
|
|
7
|
|
|
4
|
|
|
|
|
32
|
|
|
4
|
|
|
|
|
8636
|
|
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
65
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# don't change if already set |
75
|
4
|
100
|
|
|
|
91
|
if (defined $self->file) { |
76
|
2
|
|
|
|
|
43
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# TODO trim |
80
|
2
|
|
|
|
|
3
|
my $file = $title; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# non-word to underscore |
83
|
2
|
|
|
|
|
7
|
$file =~ s/\W/_/g; |
84
|
2
|
|
|
|
|
4
|
$file .= '.'; |
85
|
|
|
|
|
|
|
|
86
|
2
|
50
|
|
|
|
3
|
if (grep '/markdown/', @{$self->systemtags}) { |
|
2
|
|
|
|
|
46
|
|
87
|
0
|
|
|
|
|
0
|
$file .= $self->file_extension->{markdown}; |
88
|
0
|
|
|
|
|
0
|
$self->logger->debug('Note is markdown'); |
89
|
|
|
|
|
|
|
} else { |
90
|
2
|
|
|
|
|
61
|
$file .= $self->file_extension->{default}; |
91
|
2
|
|
|
|
|
42
|
$self->logger->debug('Note is plain text'); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
|
|
|
2065
|
$self->file($self->notes_dir->file($file)); |
95
|
|
|
|
|
|
|
|
96
|
2
|
|
|
|
|
42
|
return 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
2
|
50
|
|
2
|
|
1782
|
method load_content { |
|
1
|
|
|
1
|
|
684
|
|
|
1
|
|
|
|
|
4
|
|
100
|
1
|
|
|
|
|
2
|
my $content; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
try { |
103
|
1
|
|
|
1
|
|
73
|
$content = $self->file->slurp(iomode => '<:utf8'); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
catch { |
106
|
0
|
|
|
0
|
|
0
|
$self->logger->error("Failed to read file: $_"); |
107
|
0
|
|
|
|
|
0
|
return; |
108
|
1
|
|
|
|
|
10
|
}; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
270
|
$self->content($content); |
111
|
1
|
|
|
|
|
26
|
return 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
2
|
0
|
|
2
|
|
1413
|
method save_content { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
try { |
116
|
0
|
|
|
0
|
|
|
my $fh = $self->file->open('w'); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# data from simplenote should always be utf8 |
119
|
0
|
|
|
|
|
|
$fh->binmode(':utf8'); |
120
|
0
|
|
|
|
|
|
$fh->print($self->content); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
catch { |
123
|
0
|
|
|
0
|
|
|
$self->logger->error("Failed to write content to file: $_"); |
124
|
0
|
|
|
|
|
|
return; |
125
|
0
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
return 1; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=pod |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=encoding UTF-8 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=for :stopwords Ioan Rogers Fletcher T. Penney github |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 NAME |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
App::SimplenoteSync::Note - stores notes in plain files, |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 VERSION |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
version 0.2.1 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 AUTHORS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=over 4 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Ioan Rogers <ioanr@cpan.org> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Fletcher T. Penney <owner@fletcherpenney.net> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
This software is Copyright (c) 2021 by Ioan Rogers. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This is free software, licensed under: |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
You can make new bug reports, and view existing ones, through the |
175
|
|
|
|
|
|
|
web interface at L<https://github.com/ioanrogers/App-SimplenoteSync/issues>. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SOURCE |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
The development version is on github at L<https://github.com/ioanrogers/App-SimplenoteSync> |
180
|
|
|
|
|
|
|
and may be cloned from L<git://github.com/ioanrogers/App-SimplenoteSync.git> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |