package atom; use strict; use warnings; use XML::Parser; # --- Output variables ----- our $type; our $mode; our $body; # --- Plug-in package variables ----- my $parser; my %escape; my $escape_re; # -------------------------------- sub start { $parser = new XML::Parser; %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); $escape_re = join '|' => keys %escape; 1; } sub story { my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) =@_; if (eval {$parser->parse("
$$body_ref
")}) { $type = 'application/xhtml+xml'; $mode = 'xml'; $body = "
$$body_ref
"; } else { $type = 'text/html'; $mode = 'escaped'; if (index($$body_ref,']]>')<0) { $body = ""; } else { ($body = $$body_ref) =~ s/($escape_re)/$escape{$1}/g; } } return 1; } 1;