1 package HTML::AutoConvert::OpenOffice;
5 HTML::AutoConvert::antiword - antiword plugin for HTML::AutoConvert
9 OpenOffice v2.3 or later
20 This module starts and leaves an OpenOffice instance running.
22 The OpenOffice instance binds to and listens to a port on localhost for
23 commands. Anything which can talk to this port can instruct OpenOffice to
24 read or write any file the current user has access to.
26 By default, port 8100 is used. You can choose a different port by passing an
27 option to the new() constructor:
29 my $converter = HTML::AutoConvert->new('openoffice_port'=>5555);
34 use vars qw( %info ); #$slept );
35 use IPC::Run qw( run timeout io );
36 use File::Slurp qw( slurp );
39 'types' => [qw( doc rtf odt sxw )],
41 'url' => 'http://wvware.sourceforge.net/',
46 #sub program { ( 'openoffice', '-headless' ); }
48 #half-ass using DocumentConverter.py for now
49 #need to recode with OpenOffice::UNO
52 my( $self, $file ) = ( shift, shift );
53 my $opt = ref($_[0]) ? shift : { @_ };
55 $self->start_openoffice($opt);
57 my $program = 'DocumentConverter.py';
61 use File::Temp qw/ tempfile /;
62 my($fh, $outfile) = tempfile(SUFFIX => '.html');
63 #hmm, it gets overwritten so $fh is bunk
65 my($out, $err) = ( '', '' );
66 local($SIG{CHLD}) = sub {};
67 run( [ $program, $file, $outfile ], \undef, \$out, \$err, timeout($timeout) )
68 or die "$program failed with exit status ". ( $? >> 8 ). ": $out\n";
70 my $html = slurp($outfile);
76 sub start_openoffice {
77 my( $self ) = ( shift, shift );
78 my $opt = ref($_[0]) ? shift : { @_ };
79 my $port = $opt->{'openoffice_port'} || 8100;
81 my $cmd = [ 'openoffice', '-headless',
82 "-accept=socket,port=$port;urp",
86 local($SIG{CHLD}) = sub {};
87 run $cmd, \undef, '>/dev/null', '2>/dev/null'
88 or die "can't launch openoffice: $@\n";
90 #it isn't ready to run commands right away :(
91 #it would be better if we could ping against UNO API somehow until ready...
92 #sleep 5 unless $slept++;