| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package UnRTF; |
|
2
|
1
|
|
|
1
|
|
64150
|
use Modern::Perl; |
|
|
1
|
|
|
|
|
9859
|
|
|
|
1
|
|
|
|
|
6
|
|
|
3
|
1
|
|
|
1
|
|
832
|
use Moo; |
|
|
1
|
|
|
|
|
11014
|
|
|
|
1
|
|
|
|
|
5
|
|
|
4
|
1
|
|
|
1
|
|
3117
|
use Types::Standard qw(Str); |
|
|
1
|
|
|
|
|
85093
|
|
|
|
1
|
|
|
|
|
11
|
|
|
5
|
1
|
|
|
1
|
|
1612
|
use IPC::Cmd qw(run can_run); |
|
|
1
|
|
|
|
|
45798
|
|
|
|
1
|
|
|
|
|
73
|
|
|
6
|
1
|
|
|
1
|
|
483
|
use Alien::UnRTF; |
|
|
1
|
|
|
|
|
35450
|
|
|
|
1
|
|
|
|
|
12
|
|
|
7
|
1
|
|
|
1
|
|
8959
|
use Env qw( @PATH ); |
|
|
1
|
|
|
|
|
2769
|
|
|
|
1
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
|
|
unshift @PATH, Alien::UnRTF->bin_dir; # unrtf is now in $PATH |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
UnRTF - A Perl wrapper around unrtf tool |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
UnRTF is a simple wrapper around unrtf command line tool, unrtf converts RTF |
|
17
|
|
|
|
|
|
|
files to text and write it to the STDOUT. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
See: L. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use UnRTF; |
|
24
|
|
|
|
|
|
|
my $unrtf = UnRTF->new(file => "/tmp/file.rtf"); |
|
25
|
|
|
|
|
|
|
my $text = $unrtf->convert(format => 'text'); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Copyright (C) 2013-2021 Joenio Marques da Costa |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has file => (is => 'rw', isa => Str, required => 1); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub BUILD { |
|
36
|
3
|
50
|
|
3
|
0
|
12098
|
die "Could not find unrtf command" unless can_run('unrtf'); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub unrtf { |
|
40
|
1
|
|
|
1
|
0
|
19
|
my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = |
|
41
|
|
|
|
|
|
|
run( command => [ 'unrtf', @_ ], verbose => 0 ); |
|
42
|
1
|
50
|
|
|
|
25840
|
die "unrtf failure: @{[ join '', @$stderr_buf ]}" if ! $success; |
|
|
0
|
|
|
|
|
0
|
|
|
43
|
1
|
|
|
|
|
76
|
return join '', @$stdout_buf; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub convert { |
|
47
|
2
|
|
|
2
|
0
|
109972
|
my ($self, %args) = @_; |
|
48
|
2
|
100
|
|
|
|
34
|
return '' unless $args{format}; |
|
49
|
1
|
|
|
|
|
35
|
unrtf("--$args{format}", $self->file); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |