aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Youri/Check/Output/File/Format/RSS.pm
blob: 66ffc61f249ec1200ddc23af522dadf4166b2663 (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
# $Id$
package Youri::Check::Output::File::Format::RSS;

=head1 NAME

Youri::Check::Output::File::Format::RSS - File RSS format support

=head1 DESCRIPTION

This format plugin for L<Youri::Check::Output::File> provides RSS format
support.

=cut

use warnings;
use strict;
use Carp;
use XML::RSS;
use base 'Youri::Check::Output::File::Format';

sub extension {
    return 'rss';
}

sub get_report {
    my ($self, $time, $title, $iterator, $type, $columns, $links, $maintainer) = @_;

    return unless $maintainer;

    my $rss = new XML::RSS (version => '2.0');
    $rss->channel(
        title       => $title,
        description => $title,
        language    => 'en',
        ttl         => 1440
    );

    while (my $result = $iterator->get_result()) {
        if ($type eq 'updates') {
            $rss->add_item(
                title       => "$result->{package} $result->{available} is available",
                description => "Current version is $result->{current}",
                link        => $result->{url} ?
                    $result->{url} : $result->{source},
                guid => "$result->{package}-$result->{available}"
            );
        } else {
            $rss->add_item(
                title       => "[$type] $result->{package}",
                description => join("\n", (map { $result->{$_} || '' } @$columns)),
		link        => $result->{url},
                guid        => "$type-$result->{package}"
            );
        }
    }

    return \$rss->as_string();
}

=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;