line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::Plugin; |
2
|
1
|
|
|
1
|
|
457
|
use Spoon::Plugin -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
stub 'class_id'; |
5
|
|
|
|
|
|
|
const cgi_class => ''; |
6
|
|
|
|
|
|
|
const config_file => ''; |
7
|
|
|
|
|
|
|
const css_file => ''; |
8
|
|
|
|
|
|
|
const javascript_file => ''; |
9
|
|
|
|
|
|
|
const screen_template => 'theme_screen.html'; |
10
|
|
|
|
|
|
|
const class_title_prefix => 'Kwiki'; |
11
|
|
|
|
|
|
|
const config_class => 'Kwiki::Config'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
field cgi => -init => '$self->hub->cgi'; |
14
|
|
|
|
|
|
|
field config => -init => '$self->hub->config'; |
15
|
|
|
|
|
|
|
field users => -init => '$self->hub->users'; |
16
|
|
|
|
|
|
|
field pages => -init => '$self->hub->pages'; |
17
|
|
|
|
|
|
|
field template => -init => '$self->hub->template'; |
18
|
|
|
|
|
|
|
field preferences => |
19
|
|
|
|
|
|
|
-init => '$self->users->current->preferences'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
|
|
|
|
|
|
return $self if ref $self; |
23
|
|
|
|
|
|
|
super; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub init { |
27
|
|
|
|
|
|
|
$self->init_cgi; |
28
|
|
|
|
|
|
|
$self->config->add_file($self->config_file); |
29
|
|
|
|
|
|
|
$self->hub->css->add_file($self->css_file); |
30
|
|
|
|
|
|
|
$self->hub->javascript->add_file($self->javascript_file); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub init_cgi { |
34
|
|
|
|
|
|
|
my $class = $self->cgi_class |
35
|
|
|
|
|
|
|
or return; |
36
|
|
|
|
|
|
|
eval qq{require $class} unless $class->can('new'); |
37
|
|
|
|
|
|
|
my $package = ref($self); |
38
|
|
|
|
|
|
|
field -package => $package, 'cgi'; |
39
|
|
|
|
|
|
|
my $object = $class->new; |
40
|
|
|
|
|
|
|
$object->init; |
41
|
|
|
|
|
|
|
$self->cgi($object); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub render_screen { |
45
|
|
|
|
|
|
|
$self->template_process($self->screen_template, |
46
|
|
|
|
|
|
|
content_pane => $self->class_id . '_content.html', |
47
|
|
|
|
|
|
|
@_, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub template_process { |
52
|
|
|
|
|
|
|
$self->hub->css->add_file($self->css_file) |
53
|
|
|
|
|
|
|
if $self->css_file; |
54
|
|
|
|
|
|
|
my $template = shift; |
55
|
|
|
|
|
|
|
$self->template->process($template, |
56
|
|
|
|
|
|
|
self => $self, |
57
|
|
|
|
|
|
|
$self->pages->current->all, |
58
|
|
|
|
|
|
|
$self->cgi->all, |
59
|
|
|
|
|
|
|
@_, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub redirect { |
64
|
|
|
|
|
|
|
$self->hub->headers->redirect($self->redirect_url(@_)); |
65
|
|
|
|
|
|
|
return ''; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub redirect_url { |
69
|
|
|
|
|
|
|
my $target = shift; |
70
|
|
|
|
|
|
|
return $target |
71
|
|
|
|
|
|
|
if $target =~ /^(https?:|\/)/i or |
72
|
|
|
|
|
|
|
$target =~ /\?/; |
73
|
|
|
|
|
|
|
CGI::url(-full => 1) . '?' . $target; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub new_preference { |
77
|
|
|
|
|
|
|
$self->hub->preferences->new_preference(scalar(caller), @_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__DATA__ |