<%PERL>
my $dirname = File::Basename::dirname($INC{'RT.pm'});
my $localdirname = File::Basename::dirname($INC{'RT.pm'})."/../local/lib/";
$n =~ s/::/\//g;
my $show;
my $suffix;
foreach my $ending (qw(pm pod)) {
    if ( -r "$dirname/$n.$ending" ) {
        $show = "$dirname/$n";
        $suffix = $ending;
    } elsif ( -r "$localdirname/$n.$ending" ) {
        $show = "$localdirname/$n";
        $suffix = $ending;
    }
    last if $show;
}
unless ($show) {
        $show = "$dirname/RT";
        $suffix = 'pm';
}
if (-r "$show.$suffix") {
    local $/;
    my $got_name = 0;
    my $total_body = '';
    foreach my $postfix ('', '_Overlay', '_Vendor', '_Local') {
    	my $fh;
        next unless -r "$show$postfix.$suffix";
        open $fh, "$show$postfix.$suffix" or next;
        my $body = <$fh>;
        if ($body =~ s/.*Create takes a hash of values and creates a row in the
database:([^=]+)//s) {
            # okay, reduce it...
            $body = "=head1 SCHEMA\n\n$1\n=head1 ACCESSORS\n\n\n=cut\n$body";
            $body =~ s/=item/=head2/g;
        }
        elsif ($body =~ /^=item NewItem$/m and $n =~ /s$/) {
            my $pkg = $n;
            $pkg =~ s{/}{::}g;
            chop $pkg;
            $body = "=head1 NAME\n\n${pkg}s - Collection of $pkg
objects\n\n=cut\n";
            $got_name++;
        }
        else {
            $body =~ s/^=head1 NAME[^=]+//m if $got_name;
        }
        $body =~ s/^=head1\b(?! ACCESSORS).*\s*(?==(head1|cut))//mg;
        $body =~ s/^=head1 (?:AUTHOR|SEE ALSO|SYNOPSIS)\s*[^=]+//mg;
        $body =~ s/^=/\n=/mg;
        $body =~ s/^=begin testing\n/=begin testing\n\n/mg;
        close $fh;
	$total_body .= $body;
    }
	my $body;
    my $converter = Pod::Simple::HTML->new();
    $converter->output_string(\$body);
    $converter->parse_string_document($total_body);
    $body =~ s{.*?]+>}{}s;
    $body =~ s{\s*