#or to turn on debugging
my $converter = HTML::AutoConvert->new('debug'=>1);
+ my $html = $converter->html_convert( $file );
+ # OR
my( $html, @images ) = $converter->html_convert( $file );
#turn on or off debugging later
=head2 html_convert FILENAME
-Convert the given filename to HTML. The HTML output is returned as a scalar.
+Convert the given filename to HTML.
+
+In a scalar context, simply returns the HTML output as a scalar.
+
+ my $html = $converter->html_convert( $file );
+
+In a list context, returns a list consisting of the HTML output as a scalar,
+followed by references for each image extracted, if any. Each image reference
+is a list reference consisting of two elements: the first is the filename and
+the second is the image itself.
+
+ my( $html, @images ) = $converter->html_convert( $file );
+ foreach my $image ( @images ) {
+ my( $filename, $data ) = @$image;
+ #...
+ }
=cut
or die "no registered handlers for filetype ". $self->filetype( $file );
my( $converted, $html, $errors ) = ( 0, '', '' );
+ my @imgs = ();
foreach my $handler ( @handlers ) {
my $module = 'HTML::AutoConvert::'. $handler->{'module'};
- my $tmp_html = eval { $module->html_convert( $self->{'file'} ) };
+
+ my $tmp_html = '';
+ my @tmp_imgs = ();
+ if ( $handler->{'returns_images'} && wantarray ) {
+ ( $tmp_html, @tmp_imgs ) =
+ eval { $module->html_convert( $self->{'file'} ) };
+ } else {
+ $tmp_html =
+ eval { $module->html_convert( $self->{'file'} ) };
+ }
+
if ( $@ ) {
my $tmp_err = "conversion with $module failed: $@\n";
warn $tmp_err if $self->{'debug'};
$converted = 1;
$html = $tmp_html;
+ @imgs = @tmp_imgs;
last;
}
die "couldn't convert $file:\n$errors" unless $converted;
- $html;
+ if ( wantarray ) {
+ ( $html, @imgs );
+ } else {
+ $html;
+ }
}