Skip to content

Commit

Permalink
show recent changes with modern CPAN::Mini
Browse files Browse the repository at this point in the history
  • Loading branch information
acme committed Apr 8, 2009
1 parent 3ddfbef commit b0b94e3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
29 changes: 27 additions & 2 deletions lib/CPAN/Mini/Webserver.pm
Expand Up @@ -187,10 +187,10 @@ sub _handle_request {
$self->distvname($distvname);
$self->filename($filename);

#warn "$raw / $download / $pauseid / $distvname / $filename";
# warn "$path / $raw / $download / $pauseid / $distvname / $filename";

if ( $path eq '/' ) {
$self->direct_to_template("index");
$self->index_page();
} elsif ( $path eq '/search/' ) {
$self->search_page();
} elsif ( $raw && $pauseid && $distvname && $filename ) {
Expand Down Expand Up @@ -236,6 +236,31 @@ sub _handle_request {

}

sub index_page {
my $self = shift;

my $recent_filename = file( $self->directory, 'RECENT' );
my @recent;
if ( -f $recent_filename ) {
my $fh = IO::File->new($recent_filename) || die $!;
while ( my $line = <$fh> ) {
chomp $line;
next unless $line =~ m{authors/id/};

my $d = CPAN::DistnameInfo->new($line);

push @recent, $d;
}
}
$self->send_http_header( 200, -charset => 'utf-8' );
print Template::Declare->show(
'index',
{ recents => \@recent,
parse_cpan_authors => $self->parse_cpan_authors,
}
);
}

sub not_found_page {
my $self = shift;
my $q = shift;
Expand Down
33 changes: 31 additions & 2 deletions lib/CPAN/Mini/Webserver/Templates.pm
Expand Up @@ -198,7 +198,9 @@ private template 'search_results' => sub {
};

template 'index' => sub {
my $self = shift;
my ( $self, $arguments ) = @_;
my $parse_cpan_authors = $arguments->{parse_cpan_authors};
my $recents = $arguments->{recents};

html {
attr { xmlns => 'http://www.w3.org/1999/xhtml' };
Expand All @@ -212,6 +214,31 @@ template 'index' => sub {
show('searchbar');
h1 {'Index'};
p {'Welcome to CPAN::Mini::Webserver. Start searching!'};
if ($recents) {
h2 {'Recent distributions'};
ul {
foreach my $recent (@$recents) {
my $cpanid = $recent->cpanid;
my $distvname = $recent->distvname;
next unless $distvname;
li {
a {
attr { href => '/~'
. lc($cpanid) . '/'
. $distvname };
$distvname;
};
outs ' by ';
show(
'author_link',
$parse_cpan_authors->author(
$cpanid
)
);
}
}
};
}
};
show('footer');
};
Expand Down Expand Up @@ -414,7 +441,9 @@ private template 'metadata' => sub {
div {
attr { class => 'metadata' };
dl {
foreach my $key ( qw(abstract license repository), 'release date' ) {
foreach
my $key ( qw(abstract license repository), 'release date' )
{
if ( defined $meta->{$key} ) {
dt { ucfirst $key; };
if ( defined $meta->{resources}->{$key} ) {
Expand Down

0 comments on commit b0b94e3

Please sign in to comment.