aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Youri/Check/Input/Updates/Source/RAA.pm
blob: 2e7356ebc46dc834a06bdac18daad242619f437e (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
112
113
114
115
116
117
118
119
120
121
# $Id: RAA.pm 1179 2006-08-05 08:30:57Z warly $
package Youri::Check::Input::Updates::Source::RAA;

=head1 NAME

Youri::Check::Input::Updates::Source::RAA - RAA updates source

=head1 DESCRIPTION

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

=cut

use warnings;
use strict;
use Carp;
use SOAP::Lite;
use List::MoreUtils 'any';
use Youri::Package;
use base 'Youri::Check::Input::Updates::Source';

=head2 new(%args)

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

Specific parameters:

=over

=item url $url

URL to RAA SOAP interface (default:
http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.4)

=back

=cut

sub _init {
    my $self    = shift;
    my %options = (
        url => 'http://www.ruby-lang.org/xmlns/soap/interface/RAA/0.0.4/',
        @_
    );

    my $raa = SOAP::Lite->service($options{url})
        or croak "Can't connect to $options{url}";
    
    $self->{_raa}   = $raa;
    $self->{_names} = $raa->names();
}

sub get_version {
    my ($self, $package) = @_;
    croak "Not a class method" unless ref $self;

    my $name;
    if (ref $package && $package->isa('Youri::Package')) {
        # don't bother checking for non-ruby packages
        if (
            any { $_->[Youri::Package::DEPENDENCY_NAME] =~ /ruby/ }
            $package->get_requires()
        ) {
            $name = $package->get_canonical_name();
        } else {
            return;
        }
    } else {
        $name = $package;
    }

    # translate in grabber namespace
    $name = $self->get_name($name);

    # return if aliased to null 
    return unless $name;

    # susceptible to throw exception for timeout
    eval {
        my $gem = $self->{_raa}->gem($name);
        return $gem->{project}->{version} if $gem;
    };

    return;
}

sub _url {
    my ($self, $name) = @_;
    return "http://raa.ruby-lang.org/project/$name/";
}

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

    if (ref $self) {
        my $match = $name;
        $match =~ s/^ruby[-_]//;
        $match =~ s/[-_]ruby$//;
        my @results =
            grep { /^(ruby[-_])?\Q$match\E([-_]ruby)$/ }
            @{$self->{_names}};
        if (@results) {
            return $results[0];
        } else {
            return $name;
        }
    } else {
        return $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;