WWW::Freshmeat - automates usage of Freshmeat.net


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

Index


Code Index:

NAME

Top

WWW::Freshmeat - automates usage of Freshmeat.net

VERSION

Top

Version 0.20

SYNOPSIS

Top

    use WWW::Freshmeat;

    my $fm = WWW::Freshmeat->new(token=>'freshmeat_token');

    my $project = $fm->retrieve_project('project_id');

    foreach my $p ( @projects, $project ) {
        print $p->name(), "\n";
        print $p->version(), "\n";
        print $p->description(), "\n";
    }

DESCRIPTION

Top

WWW::Freshmeat derives from LWP::UserAgent, so it accepts all the methods that LWP::UserAgent does, notably timeout, useragent, env_proxy...

Methods

retrieve_project STRING

Query the freshmeat.net site for the project STRING (should be the Freshmeat ID of the requested project) and returns a WWW::Freshmeat::Project object or undef if the project entry cannot be found.

project_from_xml STRING

Receives Freshmeat project XML record and returns a WWW::Freshmeat::Project object or undef if the project entry cannot be found.

redir_url STRING

Receives URL and returns URL which it redirects to.

SEE ALSO

Top

LWP::UserAgent.

AUTHOR

Top

Cedric Bouvier, <cbouvi at cpan.org>. Alexandr Ciornii.

BUGS

Top

Please report any bugs or feature requests to bug-www-freshmeat at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Freshmeat. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc WWW::Freshmeat

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/WWW-Freshmeat

* CPAN Ratings

http://cpanratings.perl.org/d/WWW-Freshmeat

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Freshmeat

* Search CPAN

http://search.cpan.org/dist/WWW-Freshmeat

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


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

use 5.008;
use strict;
use warnings;

our $VERSION = '0.21';

use XML::Simple qw();
use WWW::Freshmeat::Project;
use Carp;


package WWW::Freshmeat;

use base qw( LWP::UserAgent );

sub new {
  my $class=shift;
  my $self=LWP::UserAgent->new();
  bless $self,$class;
  my %data=@_;
  $self->{fm_token}=$data{token};
  return $self;
}

sub _token {
  my $self = shift;
  croak "No token" unless $self->{fm_token};
  return $self->{fm_token};
}

sub retrieve_project {
    my $self = shift;
    my $id   = shift;

    my $url = "http://freshmeat.net/projects/$id.xml?auth_code=".$self->_token;

    my $response = $self->get($url);
    if ($response->is_success) {
      my $xml = $response->content();
      return $self->project_from_xml($xml);
    } else {
      if ($response->code eq '404') {
        return undef;
      } else {
        die "Could not GET freshmeat project (".$response->status_line.")";
      }
    }
}

sub project_from_xml {
    my $self = shift;
    my $xml  = shift;

    if ($xml eq 'Error: project not found.') {
      return undef;
    }
    die "XML is empty" unless $xml;

    my $data = XML::Simple::XMLin($xml,ForceArray => ['approved-url','recent-release']);
    #die unless exists $data->{'project'};
    die unless $data->{'name'};

    return WWW::Freshmeat::Project->new($data, $self); #->{'project'}
}

sub retrieve_user {
    croak "'User' is temporarily removed";
    my $self = shift;
    my $id   = shift;
    require WWW::Freshmeat::User;
    return WWW::Freshmeat::User->new($self,$id);
}

sub redir_url {
    my $self = shift;
    my $url=shift;
    $self->requests_redirectable([]);
    my $response = $self->get($url) or return $url;
    if ($response->is_redirect) {
      #http://www.perlmonks.org/?node_id=147608
      my $referral_uri = $response->header('Location');
      {
          # Some servers erroneously return a relative URL for redirects,
          # so make it absolute if it not already is.
          local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
          my $base = $response->base;
          $referral_uri = $HTTP::URI_CLASS->new($referral_uri, $base)
                      ->abs($base)->as_string;
      }
      return $referral_uri;
    } else {
      return $url;
    }
}

1; # End of WWW::Freshmeat