WWW::SourceForge - Retrieve infromation from SourceForge site.


WWW-SourceForge documentation Contained in the WWW-SourceForge distribution.

Index


Code Index:

NAME

Top

WWW::SourceForge - Retrieve infromation from SourceForge site.

SYNOPSIS

Top

use WWW::SourceForge::Project; use Data::Dumper;

my $proj = WWW::SourceForge::Project->new('gaim');

my @top10 = $proj->most_active; my @top100 = $proj->active_list(100);

DESCRIPTION

Top

This module help you to retrive Project information from sourceforge site.

So far the module itself is useless, all function is in WWW::SourceForge::Project.

new()

Return an WWW::SourceForge project.

most_active($self)

This method retrive top 10 project in the active list.

active_list($self,$n)

This method retrive top-n projects in the most active list.

COPYRIGHT

Top


WWW-SourceForge documentation Contained in the WWW-SourceForge distribution.
package WWW::SourceForge;

use vars qw/$VERSION/;
use WWW::Mechanize;
$VERSION = '0.06';

use constant {
    HOMEPAGE => 'http://sourceforge.net/' ,
};

sub new {
    my $class = shift;
    my $self = { wa => undef };
    return bless $self, $class;
}


sub most_active {
    my $wa = $self->{wa} || WWW::Mechanize->new(autocheck => 1);
    my $r = $wa->get(HOMEPAGE);
    my @top10;
    my $content = $wa->content;
    while ($content=~ m{<b>(\d+)</b> <A HREF="/projects/(\w+?)/">(.+?)</A><BR>\n}igs) {
        push @top10 , { unixname => $2 , name => $3 };
    }
    return wantarray? @top10 : \@top10;
}

sub active_list {
    my ($self,$topn) = @_;
    $topn ||= 50;
    my @top;

    my $wa = $self->{wa} || WWW::Mechanize->new(autocheck => 1);
    $wa->get(HOMEPAGE);
    $wa->follow_link( text_regex => qr/More Activity/i);
    push @top, $self->parse_list_table($wa->content);

    my $n = 50;
    while (my $link = $wa->find_link(text_regex => qr/-->/i)) {
        last if $n >= $topn;
        sleep(1);
        $wa->follow_link( url => $link->url);
	push @top,$self->parse_list_table($wa->content);
        $n += 50;
    }

    @top = sort { $b->{percentile} <=> $a->{percentile} }@top;
    return wantarray? @top : \@top;
}


sub parse_list_table {
    my ($self,$c) = @_;
    my @top;
    while ($c =~ m{(<TR.*?>(.*?)</TR>)}g) {
	my $line = $2;
	if($line =~ m{href="/projects/(.+?)/">(.+?)</a>.*?</TD><TD.*?>(.+?)</TD>}) {
	    push @top, { unixname => $1 , name => $2 , percentile => $3 };
	    print STDERR "[[$1 , $2 , $3]]\n";
	}
    }
    return @top;
}

1;

__END__