1 package HTML::AutoConvert;
8 HTML::AutoConvert - Best-effort HTML conversion of arbitrary files to HTML.
16 our $VERSION = '0.01';
20 use HTML::AutoConvert;
22 my $converter = HTML::AutoConvert->new();
23 #or to turn on debugging
24 my $converter = HTML::AutoConvert->new('debug'=>1);
26 my( $html, @images ) = $converter->html_convert( $file );
28 #turn on or off debugging later
33 Convert arbitrary file types to HTML.
37 #doc on also using html_convert functional interface
47 my $class = ref($proto) || $proto;
49 my $opts = ref($_[0]) ? shift : { @_ };
50 my $self = $opts; #{};
51 bless ($self, $class);
59 =head2 html_convert FILENAME
61 Convert the given filename to HTML. The HTML output is returned as a scalar.
66 my( $self, $file ) = ( shift, shift );
67 my $opt = ref($_[0]) ? shift : { @_ };
69 $self->{'file'} = $file;
71 my @handlers = $self->handlers
72 or die "no registered handlers for filetype ". $self->filetype( $file );
74 my( $converted, $html, $errors ) = ( 0, '', '' );
75 foreach my $handler ( @handlers ) {
77 my $module = 'HTML::AutoConvert::'. $handler->{'module'};
78 my $tmp_html = eval { $module->html_convert( $self->{'file'} ) };
80 my $tmp_err = "conversion with $module failed: $@\n";
81 warn $tmp_err if $self->{'debug'};
91 die "couldn't convert $file:\n$errors" unless $converted;
99 Get or set the debugging level
105 $self->{'debug'} = shift if @_;
109 =head1 INTERNAL FUNCTIONS
113 Search for installed HTML::AutoConvert::* plugins.
121 foreach my $INC ( @INC ) {
122 warn "globbing $INC/HTML/AutoConvert/*.pm\n" if $self->{'debug'};
123 foreach my $file ( glob("$INC/HTML/AutoConvert/*.pm") ) {
124 warn "attempting to load handler info from $file\n" if $self->{'debug'};
125 $file =~ /\/(\w+)\.pm$/ or do {
126 warn "unrecognized file in $INC/HTML/AutoConvert/: $file\n";
130 my $info = eval "use HTML::AutoConvert::$mod; ".
131 "\\%HTML::AutoConvert::$mod\::info;";
133 die "error using HTML::AutoConvert::$mod (skipping): $@\n" if $@;
136 unless ( keys %$info ) {
137 warn "no %info hash in HTML::AutoConvert::$mod, skipping\n" if $self->{'debug'};
140 warn "got handler info from HTML::AutoConvert::$mod: $info\n" if $self->{'debug'};
141 if ( exists($info->{'disabled'}) && $info->{'disabled'} ) {
142 warn "skipping disabled handler HTML::AutoConvert::$mod" if $self->{'debug'};
146 my $types = $info->{'types'};
147 $types = [ $types ] unless ref($types);
149 foreach my $type ( @$types ) {
150 $types{lc($type)}->{$mod} = { 'module' => $mod, %$info };
156 $self->{'handlers'} = \%types;
162 Return the available handlers for the current file.
169 my $types = $self->{'handlers'};
171 my $type = $self->filetype;
173 sort { $a->{'weight'} <=> $b->{'weight'} }
174 values %{ $types->{lc($type)} };
182 Determine the type of the current file.
186 #just use the file extension... could also use File::MMagic or something
190 my $file = $self->{'file'};
191 $file =~ /\.(\w{3,4})$/ or die "can't parse $file for extension";
197 Ivan Kohler, C<< <ivan-html-autoconvert at 420.am> >>
201 Please report any bugs or feature requests to C<bug-html-autoconvert at rt.cpan.org>, or through
202 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTML-AutoConvert>. I will be notified, and then you'll
203 automatically be notified of progress on your bug as I make changes.
207 You can find documentation for this module with the perldoc command.
209 perldoc HTML::AutoConvert
211 You can also look for information at:
215 =item * RT: CPAN's request tracker
217 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTML-AutoConvert>
219 =item * AnnoCPAN: Annotated CPAN documentation
221 L<http://annocpan.org/dist/HTML-AutoConvert>
225 L<http://cpanratings.perl.org/d/HTML-AutoConvert>
229 L<http://search.cpan.org/dist/HTML-AutoConvert>
234 =head1 ACKNOWLEDGEMENTS
238 =head1 COPYRIGHT & LICENSE
240 Copyright 2008 Freeside Internet Services, Inc.
243 This program is free software; you can redistribute it and/or modify it
244 under the same terms as Perl itself.
248 1; # End of HTML::AutoConvert