root/websites/coderepos.org/feedmaker/lib/FeedMaker/C/Default.pm @ 9944

Revision 9944, 2.2 kB (checked in by yappo, 6 years ago)

test
t
e
s
t

Line 
1package FeedMaker::C::Default;
2
3use strict;
4use warnings;
5use base qw( FeedMaker );
6
7use Data::CodeRepos::CommitPing;
8use DateTime;
9use Encode ();
10use YAML ();
11
12use XML::Feed;
13use XML::Feed::Entry;
14
15sub do_default {
16    my $self = shift;
17    $self->res->body('ok');
18    return unless $self->req->address eq '202.228.221.240';
19
20    my $commit = eval { Data::CodeRepos::CommitPing->new($self->req) };
21    return if $@;
22
23    my $log = YAML::LoadFile($self->config->{log});
24    unshift @$log, $commit;
25    pop @$log if @$log > $self->config->{max};
26    YAML::DumpFile($self->config->{log}, $log);
27
28    my $feed = XML::Feed->new('RSS');
29    $feed->title('CodeRepos Timeline');
30    $feed->link('http://coderepos.org/share/');
31    $feed->modified(DateTime->now( time_zone => 'local' ));
32    $feed->generator("CodeRepos FeedMaker/$FeedMaker::VERSION");
33    $feed->description('');
34    $feed->author('yappo');
35
36    for my $rev (@$log) {
37        my $changes_base = $rev->changes_base;
38        my $changes_base_txt = (ref $changes_base eq 'ARRAY') ? join(', ', @$changes_base) : $changes_base;
39        my $comment = Encode::decode('utf-8', $rev->comment);
40
41        my $entry = XML::Feed::Entry->new('RSS');
42        $entry->title(sprintf 'r%s: %s: %s', $rev->rev, $changes_base_txt, @{ split /\n/, $comment }[0]);
43        $entry->link('http://coderepos.org/share/changeset/' . $rev->rev);
44        $entry->issued($rev->date);
45        $entry->modified($rev->date);
46        $entry->author($rev->author);
47
48        $changes_base_txt =~ s/, / /g;
49        $entry->category($changes_base_txt);
50        $entry->content('<div>'.$comment.'</div><div><ul>' . join('', map { '<li>'.$_->{status}.':'.$_->{path}.'</li>' } @{ $rev->files }) . '</ul></div>');
51
52        $feed->add_entry($entry);
53    }
54
55    my $xml = $feed->as_xml;
56    utf8::decode($xml) unless utf8::is_utf8($xml);
57    open my $output, ">:utf8", $self->config->{feed} or return;
58    print $output $xml;
59    close $output;
60}
61
621;
63
64=head1 NAME
65
66FeedMaker::C::Default - Soozy Component
67
68=head1 SYNOPSIS
69
70See L<FeedMaker>
71
72=head1 DESCRIPTION
73
74Soozy Component
75
76=head1 AUTHOR
77
78Default Author
79
80=head1 LICENSE
81
82This library is free software, you can redistribute it and/or modify
83it under the same terms as Perl itself.
84
85=cut
Note: See TracBrowser for help on using the browser.