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

Revision 268, 1.5 kB (checked in by nyarla, 12 months ago)

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

Line 
1package Plagger::Plugin::Filter::ForceDate;
2
3use strict;
4use warnings;
5
6use Plagger::CacheProxy;
7use Plagger::Date;
8
9use base qw( Plagger::Plugin );
10
11sub register {
12    my ( $self, $c ) = @_;
13    $c->register_hook(
14        $self,
15        'update.entry.fixup'    => $self->can('update'),
16    );
17}
18
19sub init {
20    my $self = shift;
21    $self->SUPER::init( @_ );
22
23    $self->{'cache'} = Plagger::CacheProxy->new( $self, Plagger->context->cache );
24}
25
26sub 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
511;
52__END__
53
54=head1 NAME
55
56Plagger::Plugin::Filter::ForceDate - Force set C<$entry-E<gt>date>
57
58=head1 SYNOPSIS
59
60  - module: Filter::ForceDate
61
62=head1 DESCRIPTION
63
64When C<$entry-E<gt>date> isn't set, this plug-in sets C<$entry-E<gt>date> compulsorily.
65
66=head1 AUTHOR
67
68Naoki Okamura (Nyarla,) E<lt>thotep@nyarla.netE<gt>
69
70=head1 LICENSE
71
72This 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
76L<Plagger>
77
78=cut
Note: See TracBrowser for help on using the browser.