aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Youri/Check/Input/Updates/Source/Freshmeat.pm
blob: 9e9b7ce29e4f02b3f53b17dbabab3decbc7cf05d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# $Id: Freshmeat.pm 1179 2006-08-05 08:30:57Z warly $
package Youri::Check::Input::Updates::Source::Freshmeat;

=head1 NAME

Youri::Check::Input::Updates::Source::Freshmeat - Freshmeat source for updates

=head1 DESCRIPTION

This source plugin for L<Youri::Check::Input::Updates> collects updates
available from Freshmeat.

=cut

use warnings;
use strict;
use Carp;
use XML::Twig;
use LWP::UserAgent;
use base 'Youri::Check::Input::Updates::Source';

=head2 new(%args)

Creates and returns a new Youri::Check::Input::Updates::Source::Freshmeat
object.

Specific parameters:

=over

=item preload true/false

Allows to load full Freshmeat catalogue at once instead of checking each software independantly (default: false)

=back

=cut

sub _init {
    my $self    = shift;
    my %options = (
        preload => 0,
        @_
    );

    if ($options{preload}) {
        my $versions;
        
        my $project = sub {
            my ($twig, $project) = @_;
            my $name    = $project->first_child('projectname_short')->text();
            my $version = $project->first_child('latest_release')->first_child('latest_release_version')->text();
            $versions->{$name} = $version;
            $twig->purge();
        };

        my $twig = XML::Twig->new(
           TwigRoots => { project => $project }
        );

        my $url = 'http://download.freshmeat.net/backend/fm-projects.rdf.bz2';

        open(INPUT, "GET $url | bzcat |") or die "Can't fetch $url: $!\n";
        $twig->parse(\*INPUT);
        close(INPUT);

        $self->{_versions} = $versions;
    }
}

sub _version {
    my ($self, $name) = @_;

    if ($self->{_versions}) {
        return $self->{_versions}->{$name};
    } else {
        my $version;

        my $latest_release_version = sub {
            $version = $_[1]->text();
        };

        my $twig = XML::Twig->new(
            TwigRoots => { latest_release_version => $latest_release_version }
        );

        my $url = "http://freshmeat.net/projects-xml/$name";
        
        open(INPUT, "GET $url |") or die "Can't fetch $url: $!\n";
        # freshmeat answer with an HTML page when project doesn't exist
        $twig->safe_parse(\*INPUT);
        close(INPUT);

        return $version;
    }
}

sub _url {
    my ($self, $name) = @_;
    return "http://freshmeat.net/projects/$name";
}

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2002-2006, YOURI project

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

=cut

1;