{ head("Lintian Report for $name", 1) }
  <h1>{$name}</h1>

  <p>
    At the time of the last Lintian run, the following possible problems
    were found in packages maintained by {$maintainer}, listed by source
    package.
{
    if ($errors) {
        qq(    See also the <a href="../full/$id">full report</a>, including)
           . " info, experimental and overridden tags.";
    } else {
        qq(    See also the <a href="../maintainer/$id">report showing)
           . " only errors and warnings</a>.";
    }
}
    Also see their
    <a href="http://qa.debian.org/developer.php?login={$email}">QA
    overview</a>.
  </p>

{
    # Show the summary only if the number of packages is within a certain
    # range.
    my $num_packages = keys(%packages) + keys(%uploads);
    if ($num_packages > 1 and $num_packages < 20) {
        $OUT .= qq(  <div id="summary">\n    <ul>\n);
        foreach my $source (sort(keys(%packages), keys(%uploads))) {
            # Only display a link for the package if either we're
            # displaying the full report, or the package has error
            # or warning tags
            my $interesting = 0;
            if (!$errors) {
                # Full report, so include the package
                $interesting = 1;
            } else {
                my $versions = $packages{$source} || $uploads{$source};
                VERSIONS: for my $version (sort keys %$versions) {
                    my $tags = $versions->{$version};
                    for my $tag (@$tags) {
                        if (($tag->{code} eq 'E') or ($tag->{code} eq 'W')) {
                            $interesting = 1;
                            last VERSIONS;
                        }
                    }
                }
            }

            if ($interesting) {
                $OUT .= qq(      <li><a href="#$source">$source</a></li>\n);
            }
        }
        $OUT .= "    </ul>\n  </div>\n";
    }
}
  <div class="clear"></div>

{
    # We get a hash of package names to a hash of versions to a list of tags.
    # Create a list with the package information as the title and the tags as
    # the value.
    for my $source (sort (keys (%packages), keys (%uploads))) {
        my ($data, $upload);
        if ($packages{$source}) {
            $data = $packages{$source};
        } else {
            $data = $uploads{$source};
            $upload = 1;
        }
        for my $version (sort keys %$data) {
            my $tags = $data->{$version};
            my $first = 1;
            my $binary = '';
            my $tag = '';
            my $firstarea = '';
            for my $info (@$tags) {
                if ($errors) {
                    next unless $info->{code} eq 'E' or $info->{code} eq 'W';
                }

                my $is_binary = ($info->{type} eq "binary" or $info->{type} eq "udeb");
                my $new_binary = $info->{package} ne $binary if $is_binary;

                my $area = ($info->{area} eq 'main') ? '' : "; $info->{area}";
                $firstarea = $info->{area} unless $firstarea;
                if ($first) {
                    $OUT .= qq(  <div class="source-header">\n);
                    $OUT .= qq(   <h2 id="$source">);
                    $OUT .= "$source ($version$area)";
                    $OUT .= " [Uploader]" if $upload;
                    $OUT .= "</h2>\n";
                    $OUT .= qq(   <p class="info-links">\n);
                    $OUT .= qq(    <a href="http://packages.debian.org/src:$source">Info</a>\n);
                    $OUT .= qq(    <a href="http://packages.qa.debian.org/$source">PTS</a>\n);
                    $OUT .= qq(    <a href="http://bugs.debian.org/src:$source">Bugs</a>\n);
                    $OUT .= qq(   </p>\n  </div>\n);
                    $OUT .= qq(  <ul class="report">\n) unless $is_binary;
                }

                my $bin_version = '';
                unless ($info->{version} eq $version
                        and $info->{area} eq $firstarea) {
                    $bin_version = " ($info->{version}; $info->{area})";
                }

                if ($new_binary) {
                    $OUT .= "</ul>\n    </li>\n  </ul>\n" unless $first;
                    $OUT .= qq(  <h3>$info->{package}$bin_version</h3>\n);
                    $OUT .= qq(  <ul class="report">\n);
                }

                my $class = '';
                if ($info->{severity} and $info->{certainty}) {
                    $class = qq( title="$info->{severity}, $info->{certainty}");
                }

                # Display tag name only once.
                if ($tag ne $info->{tag} or $new_binary) {
                    $OUT .= "</ul>\n    </li>\n" unless $first or $new_binary;
                    $OUT .= "    <li$class>\n";
                    $OUT .= qq(      <span class="type-$info->{code}">);
                    $OUT .= "$info->{code}</span> ";
                    $OUT .= qq(<a href="../tags/$info->{tag}.html">);
                    $OUT .= "$info->{tag}</a>\n";
                    $OUT .= qq(      <ul class="extra">);
                }

                if ($info->{extra}) {
                    $OUT .= "<li>$info->{extra}</li>";
                }

                $first = 0;
                $binary = $info->{package} if $is_binary;
                $tag = $info->{tag};
            }
            $OUT .= "</ul>\n    </li>\n  </ul>\n";
        }
    }
}
{ foot() }
