Jifty/Plugin/Config/View.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 3 Podpod n/a totaltotal 0.0% 0 / 62 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use strict;
2 use warnings;
3  
4 =head1 NAME
5  
6 Jifty::Plugin::Config::View - Templates for Config plugin
7  
8 =head1 DESCRIPTION
9  
10 This provides two views for the configuration plugin.
11  
12 =head2 /__jifty/config
13  
14 This path (configurable by the C<config_url> setting of the plugin)
15 shows the L<Jifty::Plugin::Config::Action::Config> action.
16  
17 =cut
18  
19 package Jifty::Plugin::Config::View;
20 use Jifty::View::Declare -base;
21  
22 __PACKAGE__->use_mason_wrapper;
23 my $config_url = Jifty::Plugin::Config->config_url;
24 my $restart_url = Jifty::Plugin::Config->restart_url;
25 template $config_url => sub {
26 my $config = new_action( class => 'Config' );
27 $config->order(1);
28 my $restart = new_action( class => 'Restart' );
29 $restart->order(2);
30 form {
31 render_action( $config );
32 form_submit( label => _('Save') );
33 form_submit(
34 label => _('Save and Restart'),
35 # WARN: though it's an array, it doesn't mean the actions are run
36 # in this order, please set ->order for each action to do this
37 submit => [ $config, $restart ],
38 );
39 }
40 };
41  
42 =head2 /__jifty/config/restart.html
43  
44 This path (configurable by the C<restart_url> setting of the plugin)
45 waits five seconds, then redirects to the configured
46 C<after_restart_url>.
47  
48 =cut
49  
50 template $restart_url => sub {
51 my $seconds = get('seconds') || Jifty::Plugin::Config->wait_seconds || 5;
52 my $url = get('url') || Jifty::Plugin::Config->after_restart_url;
53 $url =
54 Jifty->config->framework('Web')->{BaseURL} . ':'
55 . Jifty->config->framework('Web')->{Port}
56 . $url
57 unless $url =~ /^https?:/;
58  
59 html {
60 head {
61 title {
62 outs "Restarting ";
63 outs( Jifty->config->framework('ApplicationName') );
64 };
65 meta {
66 attr {
67 'http-equiv' => 'refresh',
68 content => "$seconds;url=$url",
69 };
70 };
71 Jifty->web->include_javascript;
72
73 outs_raw( <<EOF );
74 <script type="text/javascript">
75  
76 var interval_id;
77 function reduceTime () {
78 var left = parseInt(jQuery('#seconds').html());
79 if ( left > 0 ) {
80 jQuery('#seconds').html(left-1 + '');
81 }
82 else {
83 clearInterval(interval_id);
84 }
85 };
86  
87 jQuery( function(){ interval_id = setInterval('reduceTime()', 1000 ) } );
88 </script>
89  
90 EOF
91 };
92 body {
93 outs "Please wait ";
94 div { attr { style => 'display: inline', id => 'seconds' } $seconds };
95 outs " seconds so the server can restart, then we'll redirect you ";
96 hyperlink(
97 label => "here",
98 url => $url,
99 );
100 outs ".";
101 }
102 };
103  
104 Jifty->handler->buffer->flush_output();
105 # XXX: hook into plack::loader to restart server
106 };
107  
108 1;