root/lang/perl/Moxy/trunk/lib/Moxy/Plugin/Filter/ControlPanel.pm @ 5041

Revision 5041, 1.7 kB (checked in by tokuhirom, 6 years ago)

いろいろとコアを変更しまくった。

Line 
1package Moxy::Plugin::Filter::ControlPanel;
2use strict;
3use warnings;
4use base qw/Moxy::Plugin/;
5use Path::Class;
6use B;
7use Moxy::Util;
8
9sub register {
10    my ($class, $context) = @_;
11
12    $context->register_hook(
13        response_filter => sub {
14            my ($context, $args) = @_;
15
16            return unless (($args->{response}->header('Content-Type')||'') =~ /html/);
17
18            $context->log("debug" => "generate ControlPanel");
19
20            my @parts;
21            for my $action ($context->get_hooks('control_panel')) {
22                push @parts,
23                    {
24                    module => B::svref_2object($action)->GV->STASH->NAME,
25                    html   => $action->( $context, $args )
26                    };
27            }
28
29            my $output = $class->render_template(
30                $context,
31                'panelcontainer.tt' => {
32                    parts => \@parts,
33                }
34            );
35
36            my $charset = Moxy::Util->detect_charset($args->{response}, ${$args->{content_ref}});
37
38            # convert html charset to response charset.
39            my $enc = Encode::find_encoding($charset);
40            Encode::from_to($output, 'utf-8', $enc ? $enc->name : 'utf-8');
41
42            # insert control panel to html response.
43            ${ $args->{content_ref} } =~ s!(<body.*?>)!"$1$output"!ie;
44        }
45    );
46}
47
481;
49__END__
50
51=head1 NAME
52
53Moxy::Plugin::Filter::ControlPanel - control panel for moxy
54
55=head1 SYNOPSIS
56
57  - module: ControlPanel
58
59=head1 DESCRIPTION
60
61Moxy's control panel.
62
63A lot of plugins depend to this plugin.We recommends you enable this plugin.
64
65=head1 AUTHOR
66
67    Kan Fushihara
68    Tokuhiro Matsuno
69
70=head1 SEE ALSO
71
72L<Moxy>
Note: See TracBrowser for help on using the browser.