Plagger::Plugin::Filter::SortEntries #2
読了まで:約0分
概要: Plagger::Plugin::Filter::SortEntries を
前に
要するに、
plugins:
- module: Filter::SortEntries
config:
property: date->format('Epoch')
reverse: 1
こんな$entry->date->format(*Epoch*)
が
で、
package Plagger::Plugin::Filter::SortEntries;
use strict;
use warnings;
use base qw( Plagger::Plugin );
sub register {
my ( $self, $c ) = @_;
$c->register_hook(
$self,
'publish.feed' => $self->can('entries'),
);
}
sub entries {
my ( $self, $c, $args ) = @_;
my @entries = $args->{'feed'}->entries;
my $property = $self->conf->{'property'} or
$c->log( error => "Config 'property' is not specified." ) and return;
my $sort_sub = '$a->' . $property . ' cmp ' . '$b->' . $property;
@entries = sort { eval $sort_sub } @entries;
@entries = reverse @entries if ( $self->conf->{'reverse'} );
$args->{'feed'}->{'entries'} = \@entries;
return 1;
}
1;
__END__
=head1 NAME
Plagger::Plugin::Filter::SortEntries - Sort entries of Feed.
=head1 SYNOPSIS
- module: Filter::SortEntries
config:
property: date->format('Epoch')
reverse: 1
=head1 DESCRIPTION
This plug-in sorts entry of Feed.
=head1 CONFIG
=head2 property
specification property for sorting.
=head2 reverse
reverse of sort result
=head1 AUTHOR
Naoki Okamura (Nyarla,) [email protected]
=head1 LICENSE
This Plug-in is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
=head1 SEE ALSO
L
=cut
ちなみに
設定は
#FIXME