| 1 | package FeedMaker::C::Default; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use base qw( FeedMaker ); |
|---|
| 6 | |
|---|
| 7 | use Data::CodeRepos::CommitPing; |
|---|
| 8 | use DateTime; |
|---|
| 9 | use Encode (); |
|---|
| 10 | use YAML (); |
|---|
| 11 | |
|---|
| 12 | use XML::Feed; |
|---|
| 13 | use XML::Feed::Entry; |
|---|
| 14 | |
|---|
| 15 | sub 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 | |
|---|
| 62 | 1; |
|---|
| 63 | |
|---|
| 64 | =head1 NAME |
|---|
| 65 | |
|---|
| 66 | FeedMaker::C::Default - Soozy Component |
|---|
| 67 | |
|---|
| 68 | =head1 SYNOPSIS |
|---|
| 69 | |
|---|
| 70 | See L<FeedMaker> |
|---|
| 71 | |
|---|
| 72 | =head1 DESCRIPTION |
|---|
| 73 | |
|---|
| 74 | Soozy Component |
|---|
| 75 | |
|---|
| 76 | =head1 AUTHOR |
|---|
| 77 | |
|---|
| 78 | Default Author |
|---|
| 79 | |
|---|
| 80 | =head1 LICENSE |
|---|
| 81 | |
|---|
| 82 | This library is free software, you can redistribute it and/or modify |
|---|
| 83 | it under the same terms as Perl itself. |
|---|
| 84 | |
|---|
| 85 | =cut |
|---|