|
Revision 268, 1.3 kB
(checked in by nyarla, 13 months ago)
|
|
lang/perl/plagger: I imported making plugin files.
|
| Line | |
|---|
| 1 | package Plagger::Plugin::Filter::SortEntries;
|
|---|
| 2 |
|
|---|
| 3 | use strict;
|
|---|
| 4 | use warnings;
|
|---|
| 5 |
|
|---|
| 6 | use base qw( Plagger::Plugin );
|
|---|
| 7 |
|
|---|
| 8 | sub register {
|
|---|
| 9 | my ( $self, $c ) = @_;
|
|---|
| 10 | $c->register_hook(
|
|---|
| 11 | $self,
|
|---|
| 12 | 'publish.feed' => $self->can('entries'),
|
|---|
| 13 | );
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | sub 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 |
|
|---|
| 34 | 1;
|
|---|
| 35 | __END__
|
|---|
| 36 |
|
|---|
| 37 | =head1 NAME
|
|---|
| 38 |
|
|---|
| 39 | Plagger::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 |
|
|---|
| 50 | This plug-in sorts entry of Feed.
|
|---|
| 51 |
|
|---|
| 52 | =head1 CONFIG
|
|---|
| 53 |
|
|---|
| 54 | =head2 property
|
|---|
| 55 |
|
|---|
| 56 | Property for sorting.
|
|---|
| 57 |
|
|---|
| 58 | =head2 reverse
|
|---|
| 59 |
|
|---|
| 60 | reverse of sort result
|
|---|
| 61 |
|
|---|
| 62 | =head1 AUTHOR
|
|---|
| 63 |
|
|---|
| 64 | Naoki Okamura (Nyarla,) E<lt>thotep@nyarla.netE<gt>
|
|---|
| 65 |
|
|---|
| 66 | =head1 LICENSE
|
|---|
| 67 |
|
|---|
| 68 | This 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 |
|
|---|
| 72 | L<Plagger>
|
|---|
| 73 |
|
|---|
| 74 | =cut
|
|---|