# $Id: Distribution.pm,v 1.11 2003/10/07 19:38:30 clajac Exp $ package CPANXR::Apache::Distribution; use CPANXR::Database; use CPANXR::Config; use CPANXR::Apache::Util; use File::Spec::Functions qw(catdir abs2rel); use File::Find::Rule; use Data::Page; use strict; sub find { my ($self, $r, $q) = @_; my %args; my $by_prefix = $q->param('c') || 'A'; my $current = $q->param('p') || 1; $args{by_name} = $by_prefix . "%"; my $result = CPANXR::Database->select_distributions(%args); for('A'..'Z') { $r->print(""); if($by_prefix eq $_) { $r->print("$_"); } else { $r->print($_); } $r->print(" \n"); } my $page = Data::Page->new(scalar @$result, 10, $current); $r->print("
\n"); if(@$result) { $r->print("Found " . $page->total_entries . " distributions, "); $r->print("showing " . $page->first . " to " . $page->last . "\n"); } sub list { my ($self, $r, $q) = @_; my $id = $q->param('id'); my $name = $q->param('name'); my $show = $q->param('hide') || 0; my %args; $args{id} = $id if($id =~ /^\d+$/); $args{by_name} = "$name\%" if($name && !exists $args{id}); # Select name from database my $result = CPANXR::Database->select_distributions(%args); if(@$result) { # Fetch files related to this dist that are cross-indexed my $db_files = CPANXR::Database->select_files(dist_id => $result->[0]->[0]); $r->print("Contents of: $result->[0]->[1]
\n"); my $table = CPANXR::Apache::Util::Table->new($r, 1); $table->begin; $table->header("Name:"); for($page->splice($result)) { my $name = $_->[1]; $name =~ s/-[0-9_\.]+$//; $table->print("[0]\">$name
\n"); } $table->end; my $base = "dists?c=$by_prefix"; CPANXR::Apache::Util->navigator($r, $page, $base); } else { $r->print("No distributions starting with $by_prefix\n"); } $r->print("
\n"); my $dist_root = CPANXR::Config->get("XrRoot"); my $path = catdir($dist_root, $result->[0]->[1]); my @files = File::Find::Rule->file()->in($path); my %files; foreach(@$db_files) { $files{$_->[2]} = [$_->[0], $_->[4]]; } my $table = CPANXR::Apache::Util::Table->new($r, 2, [qw(90% 10%)]); $table->begin; $table->header("Path:", "LOC:"); foreach my $file (@files) { $file = abs2rel($file, $dist_root); if(exists $files{$file}) { my $link = "[0] . "\">" . $file . ""; $table->print($link, $files{$file}->[1]); } elsif($show) { $table->print("" . $file . "", ""); } } $table->end; $r->print("\n"); if($show) { $r->print("Hide non-indexed files"); } else { $r->print("Show all files"); } $r->print("