|
Revision 268, 1.5 kB
(checked in by nyarla, 12 months ago)
|
|
lang/perl/plagger: I imported making plugin files.
|
| Line | |
|---|
| 1 | package Plagger::Plugin::Filter::ForceDate;
|
|---|
| 2 |
|
|---|
| 3 | use strict;
|
|---|
| 4 | use warnings;
|
|---|
| 5 |
|
|---|
| 6 | use Plagger::CacheProxy;
|
|---|
| 7 | use Plagger::Date;
|
|---|
| 8 |
|
|---|
| 9 | use base qw( Plagger::Plugin );
|
|---|
| 10 |
|
|---|
| 11 | sub register {
|
|---|
| 12 | my ( $self, $c ) = @_;
|
|---|
| 13 | $c->register_hook(
|
|---|
| 14 | $self,
|
|---|
| 15 | 'update.entry.fixup' => $self->can('update'),
|
|---|
| 16 | );
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | sub init {
|
|---|
| 20 | my $self = shift;
|
|---|
| 21 | $self->SUPER::init( @_ );
|
|---|
| 22 |
|
|---|
| 23 | $self->{'cache'} = Plagger::CacheProxy->new( $self, Plagger->context->cache );
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | sub update {
|
|---|
| 27 | my ( $self, $c, $args ) = @_;
|
|---|
| 28 | my $entry = $args->{'entry'};
|
|---|
| 29 |
|
|---|
| 30 | return if ( ref $entry->date );
|
|---|
| 31 |
|
|---|
| 32 | my $cache = $self->{'cache'};
|
|---|
| 33 |
|
|---|
| 34 | my $data = $cache->get( $entry->permalink );
|
|---|
| 35 |
|
|---|
| 36 | if ( defined $data && $data->{'body'} eq $entry->body ) {
|
|---|
| 37 | $entry->date( $data->{'date'} );
|
|---|
| 38 | }
|
|---|
| 39 | else {
|
|---|
| 40 | $entry->date( Plagger::Date->now );
|
|---|
| 41 | $cache->set(
|
|---|
| 42 | $entry->permalink => {
|
|---|
| 43 | date => $entry->date,
|
|---|
| 44 | body => $entry->body,
|
|---|
| 45 | },
|
|---|
| 46 | );
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | 1;
|
|---|
| 52 | __END__
|
|---|
| 53 |
|
|---|
| 54 | =head1 NAME
|
|---|
| 55 |
|
|---|
| 56 | Plagger::Plugin::Filter::ForceDate - Force set C<$entry-E<gt>date>
|
|---|
| 57 |
|
|---|
| 58 | =head1 SYNOPSIS
|
|---|
| 59 |
|
|---|
| 60 | - module: Filter::ForceDate
|
|---|
| 61 |
|
|---|
| 62 | =head1 DESCRIPTION
|
|---|
| 63 |
|
|---|
| 64 | When C<$entry-E<gt>date> isn't set, this plug-in sets C<$entry-E<gt>date> compulsorily.
|
|---|
| 65 |
|
|---|
| 66 | =head1 AUTHOR
|
|---|
| 67 |
|
|---|
| 68 | Naoki Okamura (Nyarla,) E<lt>thotep@nyarla.netE<gt>
|
|---|
| 69 |
|
|---|
| 70 | =head1 LICENSE
|
|---|
| 71 |
|
|---|
| 72 | This Plug-in is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
|---|
| 73 |
|
|---|
| 74 | =head1 SEE ALSO
|
|---|
| 75 |
|
|---|
| 76 | L<Plagger>
|
|---|
| 77 |
|
|---|
| 78 | =cut
|
|---|