root/lang/perl/plagger/lib/Plagger/Plugin/Filter/SortEntries.pm

Revision 268, 1.3 kB (checked in by nyarla, 13 months ago)

lang/perl/plagger: I imported making plugin files.

Line 
1package Plagger::Plugin::Filter::SortEntries;
2
3use strict;
4use warnings;
5
6use base qw( Plagger::Plugin );
7
8sub register {
9    my ( $self, $c ) = @_;
10    $c->register_hook(
11        $self,
12        'publish.feed'  => $self->can('entries'),
13    );
14}
15
16sub entries {
17    my ( $self, $c, $args ) = @_;
18
19    my @entries = $args->{'feed'}->entries;
20
21    my $property = $self->conf->{'property'} or
22        $c->log( error => "Config 'property' is not specified." ) and return;
23
24    my $sort_sub = '$a->' . $property . ' cmp ' . '$b->' . $property;
25
26    @entries = sort { eval $sort_sub } @entries;
27    @entries = reverse @entries if ( $self->conf->{'reverse'} );
28
29    $args->{'feed'}->{'entries'} = \@entries;
30
31    return 1;
32}
33
341;
35__END__
36
37=head1 NAME
38
39Plagger::Plugin::Filter::SortEntries - Sort entries of Feed.
40
41=head1 SYNOPSIS
42
43  - module: Filter::SortEntries
44    config:
45      property: date->format('Epoch')
46      reverse: 1
47
48=head1 DESCRIPTION
49
50This plug-in sorts entry of Feed.
51
52=head1 CONFIG
53
54=head2 property
55
56Property for sorting.
57
58=head2 reverse
59
60reverse of sort result
61
62=head1 AUTHOR
63
64Naoki Okamura (Nyarla,) E<lt>thotep@nyarla.netE<gt>
65
66=head1 LICENSE
67
68This Plug-in is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
69
70=head1 SEE ALSO
71
72L<Plagger>
73
74=cut
Note: See TracBrowser for help on using the browser.