line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::CachedDisplay; |
2
|
1
|
|
|
1
|
|
1462
|
use Kwiki::Plugin -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
const class_id => 'cached_display'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub register { |
8
|
|
|
|
|
|
|
my $reg = shift; |
9
|
|
|
|
|
|
|
$reg->add(hook => 'display:display', pre => 'check_cached'); |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub check_cached { |
13
|
|
|
|
|
|
|
my $hook = pop; |
14
|
|
|
|
|
|
|
my $display = $self; |
15
|
|
|
|
|
|
|
$self = $display->hub->cached_display; |
16
|
|
|
|
|
|
|
my $page = $self->pages->current; |
17
|
|
|
|
|
|
|
return unless $page->exists; |
18
|
|
|
|
|
|
|
return if (defined $self->config->can('cached_display_ignore') and |
19
|
|
|
|
|
|
|
grep {$page->id} @{$self->config->cached_display_ignore}); |
20
|
|
|
|
|
|
|
my $html = io->catfile($self->plugin_directory,$page->id)->utf8; |
21
|
|
|
|
|
|
|
my $content; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $depup = 0; |
24
|
|
|
|
|
|
|
if (defined $self->config->can('cached_display_dependencies')){ |
25
|
|
|
|
|
|
|
for (@{$self->config->cached_display_dependencies}){ |
26
|
|
|
|
|
|
|
my $deppage = $self->pages->new_page($_); |
27
|
|
|
|
|
|
|
$depup = 1 if $deppage->modified_time > $html->mtime; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if($depup or |
32
|
|
|
|
|
|
|
!$html->exists or |
33
|
|
|
|
|
|
|
($page->modified_time > $html->mtime)) { |
34
|
|
|
|
|
|
|
my $code = $hook->code; |
35
|
|
|
|
|
|
|
$content = $code->($display); |
36
|
|
|
|
|
|
|
$html->print($content); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
$content ||= $html->all; |
39
|
|
|
|
|
|
|
$hook->cancel; |
40
|
|
|
|
|
|
|
return $content; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |