line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::optex::msdoc; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
535
|
use 5.014; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=encoding utf-8 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
msdoc - module to replace MS document by its text contents |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.04 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
optex command -Mmsdoc |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This module replaces argument which terminate with I<.docx>, I |
26
|
|
|
|
|
|
|
or I files by node representing its text information. File |
27
|
|
|
|
|
|
|
itself is not altered. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
For example, you can check the text difference between MS word files |
30
|
|
|
|
|
|
|
like this: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$ optex diff -Mmsdoc OLD.docx NEW.docx |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
If you have symbolic link named B to B, and following |
35
|
|
|
|
|
|
|
setting in your F<~/.optex.d/diff.rc>: |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
option default --msdoc |
38
|
|
|
|
|
|
|
option --msdoc -Mmsdoc $ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Next command simply produces the same result. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$ diff OLD.docx NEW.docx |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Text data is extracted by B command with B<-Mmsdoc> module, |
45
|
|
|
|
|
|
|
and above command is almost equivalent to below bash command using |
46
|
|
|
|
|
|
|
process substitution. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$ diff <(greple -Mmsdoc --dump OLD.docx) \ |
49
|
|
|
|
|
|
|
<(greple -Mmsdoc --dump NEW.docx) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 ENVIRONMENT |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This version experimentally support other converter program. If the |
54
|
|
|
|
|
|
|
environment variable B is set, it is used |
55
|
|
|
|
|
|
|
instead of B. Choose one from B, B or |
56
|
|
|
|
|
|
|
B. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SEE ALSO |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
L |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
It is possible to use other data conversion program, like L or |
63
|
|
|
|
|
|
|
L. Feel to free to modify this module. I'm reluctant to |
64
|
|
|
|
|
|
|
use them, because they work quite leisurely. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 LICENSE |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Copyright (C) Kazumasa Utashiro. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
71
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 AUTHOR |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Kazumasa Utashiro |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
package App::optex::msdoc; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
1
|
|
420
|
use utf8; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
4
|
|
82
|
1
|
|
|
1
|
|
413
|
use Encode; |
|
1
|
|
|
|
|
7215
|
|
|
1
|
|
|
|
|
50
|
|
83
|
1
|
|
|
1
|
|
412
|
use Data::Dumper; |
|
1
|
|
|
|
|
4306
|
|
|
1
|
|
|
|
|
139
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my($mod, $argv); |
86
|
|
|
|
|
|
|
sub initialize { |
87
|
0
|
|
|
0
|
0
|
|
($mod, $argv) = @_; |
88
|
0
|
|
|
|
|
|
msdoc(); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub argv (&) { |
92
|
0
|
|
|
0
|
0
|
|
my $sub = shift; |
93
|
0
|
|
|
|
|
|
@$argv = $sub->(@$argv); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my %converter = ( |
97
|
|
|
|
|
|
|
'greple' => "greple -Mmsdoc --dump \"%s\"", |
98
|
|
|
|
|
|
|
'pandoc' => "pandoc -t plain \"%s\"", |
99
|
|
|
|
|
|
|
'tika' => "tika --text \"%s\"", |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $converter_default = 'greple'; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $converter = $ENV{OPTEX_MSDOC_CONVERTER} || $converter_default; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub to_text { |
107
|
0
|
|
|
0
|
0
|
|
my $file = shift; |
108
|
0
|
|
|
|
|
|
my $format = $converter{$converter}; |
109
|
0
|
|
|
|
|
|
my $exec = sprintf $format, $file; |
110
|
0
|
|
|
|
|
|
qx($exec); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
1
|
|
341
|
use App::optex::Tmpfile; |
|
1
|
|
|
|
|
6948
|
|
|
1
|
|
|
|
|
141
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my @persist; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub msdoc { |
118
|
|
|
|
|
|
|
argv { |
119
|
0
|
|
|
0
|
|
|
for (@_) { |
120
|
0
|
0
|
|
|
|
|
my($suffix) = /\.(docx|pptx|xlsx)$/x or next; |
121
|
0
|
0
|
|
|
|
|
-f $_ or next; |
122
|
0
|
|
|
|
|
|
my $tmp = new App::optex::Tmpfile; |
123
|
0
|
|
|
|
|
|
$tmp->write(to_text($_))->rewind; |
124
|
0
|
|
|
|
|
|
push @persist, $tmp; |
125
|
0
|
|
|
|
|
|
$_ = $tmp->path; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
@_; |
128
|
0
|
|
|
0
|
0
|
|
}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__DATA__ |