initial import
[HTML-AutoConvert.git] / lib / HTML / AutoConvert / Run.pm
1 package HTML::AutoConvert::Run;
2
3 =head1 NAME
4
5 HTML::AutoConvert::Run - Base class for HTML::AutoConvert plugs that run an external program
6
7 =cut
8
9 use strict;
10 use IPC::Run qw( run timeout );
11
12 sub html_convert {
13   my( $self, $file ) = ( shift, shift );
14   my $opt = ref($_[0]) ? shift : { @_ };
15
16   my @program = $self->program;
17   my $program = $program[0];
18
19   my $timeout = 60; #?
20
21   my( $html, $err ) = ( '', '');
22   local($SIG{CHLD}) = sub {};
23   run( [ @program, $file ], \undef, \$html, \$err, timeout($timeout) )
24     or die "$program failed with exit status ". ( $? >> 8 ). ": $err\n";
25
26   $html;
27
28 }
29
30 1;