line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::QuickMemoPlus::Reader; |
2
|
3
|
|
|
3
|
|
148149
|
use 5.010; |
|
3
|
|
|
|
|
31
|
|
3
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
62
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
72
|
|
5
|
3
|
|
|
3
|
|
30
|
use Carp; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
222
|
|
6
|
3
|
|
|
3
|
|
2099
|
use JSON; |
|
3
|
|
|
|
|
33762
|
|
|
3
|
|
|
|
|
15
|
|
7
|
3
|
|
|
3
|
|
2955
|
use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); |
|
3
|
|
|
|
|
261733
|
|
|
3
|
|
|
|
|
530
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
31
|
use Exporter qw(import); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1931
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( lqm_to_str ); |
14
|
|
|
|
|
|
|
our $suppress_header = 0; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub lqm_to_str { |
17
|
|
|
|
|
|
|
## pass an lqm file exported from QuickMemo+ |
18
|
8
|
|
|
8
|
0
|
7125
|
my ( $lqm_file ) = @_; |
19
|
8
|
100
|
|
|
|
231
|
if (not -f $lqm_file){ |
20
|
1
|
|
|
|
|
46
|
carp "$lqm_file is not a file"; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
581
|
return ''; |
23
|
|
|
|
|
|
|
} |
24
|
7
|
|
|
|
|
26
|
my $note_created_time = ""; |
25
|
7
|
100
|
|
|
|
37
|
if ( $lqm_file =~ /(QuickMemo\+_(\d{6}_\d{6})(\(\d+\))?)/i) { |
26
|
1
|
|
|
|
|
4
|
$note_created_time = $2; |
27
|
|
|
|
|
|
|
} |
28
|
7
|
|
|
|
|
28
|
my $json_str = extract_json_from_lqm( $lqm_file ); |
29
|
|
|
|
|
|
|
|
30
|
7
|
100
|
|
|
|
47
|
return '' if not $json_str; |
31
|
|
|
|
|
|
|
|
32
|
4
|
|
|
|
|
14
|
my ($extracted_text, $note_category) = extract_text_from_json($json_str); |
33
|
4
|
|
|
|
|
14
|
my $header = "Created date: $note_created_time\n"; |
34
|
4
|
|
|
|
|
11
|
$header .= "Category: $note_category\n"; |
35
|
4
|
|
|
|
|
10
|
$header .= "-"x79 . "\n"; |
36
|
4
|
100
|
|
|
|
11
|
$header = '' if $suppress_header; |
37
|
|
|
|
|
|
|
|
38
|
4
|
|
|
|
|
27
|
return $header . $extracted_text; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
##################################### |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
sub extract_json_from_lqm { |
44
|
8
|
|
|
8
|
0
|
629
|
my $lqm_file = shift; |
45
|
8
|
|
|
|
|
57
|
my $lqm_zip = Archive::Zip->new(); |
46
|
8
|
100
|
|
|
|
306
|
unless ( $lqm_zip->read( $lqm_file ) == AZ_OK ) { |
47
|
1
|
|
|
|
|
3071
|
carp "Error reading $lqm_file"; |
48
|
|
|
|
|
|
|
####### to do: add the zip error to the warning? |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
518
|
return ""; |
51
|
|
|
|
|
|
|
} |
52
|
7
|
|
|
|
|
27899
|
my $jlqm_filename = "memoinfo.jlqm"; |
53
|
7
|
|
|
|
|
34
|
my $member = $lqm_zip->memberNamed( $jlqm_filename ); |
54
|
7
|
100
|
|
|
|
525
|
if( not $member ){ |
55
|
1
|
|
|
|
|
36
|
carp "File not found: $jlqm_filename in archive $lqm_file"; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
667
|
return ""; |
58
|
|
|
|
|
|
|
} |
59
|
6
|
|
|
|
|
35
|
my ( $string, $status ) = $member->contents(); |
60
|
6
|
100
|
|
|
|
10706
|
if(not $status == AZ_OK){ |
61
|
1
|
|
|
|
|
14
|
carp "Error extracting $jlqm_filename from $lqm_file : Status = $status"; |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
527
|
return ""; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
5
|
|
|
|
|
100
|
return $string; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
############################################### |
70
|
|
|
|
|
|
|
# |
71
|
|
|
|
|
|
|
sub extract_text_from_json { |
72
|
4
|
|
|
4
|
0
|
6
|
my $json_string = shift; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
############# To do: eval this and trap errors. |
75
|
4
|
|
|
|
|
187
|
my $href_memo = decode_json $json_string; |
76
|
4
|
50
|
|
|
|
18
|
if (not $href_memo){ |
77
|
0
|
|
|
|
|
0
|
carp "Error decoding JSON file in lqm archive."; |
78
|
0
|
|
|
|
|
0
|
return '',''; |
79
|
|
|
|
|
|
|
} |
80
|
4
|
|
|
|
|
10
|
my $text = ""; |
81
|
4
|
|
|
|
|
7
|
foreach( @{$href_memo->{MemoObjectList}} ) { |
|
4
|
|
|
|
|
14
|
|
82
|
4
|
|
|
|
|
12
|
$text .= $_->{DescRaw}; |
83
|
4
|
|
|
|
|
11
|
$text .= "\n"; |
84
|
|
|
|
|
|
|
} |
85
|
4
|
|
|
|
|
10
|
my $category = $href_memo->{Category}->{CategoryName}; |
86
|
4
|
|
50
|
|
|
11
|
$category //= ''; |
87
|
4
|
|
|
|
|
27
|
$category =~ s/[^\w-]/_/g; |
88
|
4
|
|
|
|
|
34
|
return $text, $category; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
__END__ |