Mojolicious.pm untested

filter: Statementstmt 0.0% 0 / 83 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 113 CC 4 SCAR 13.6
CC
4
Cov
0%
on_start_server
12.0
on_stop_server
6.0
padre_interfaces
2.0
CRAP 3.9
1 package Padre::Plugin::Mojolicious;
2  
3 use 5.008;
4 use strict;
5 use warnings;
6  
7 our $VERSION = '0.06';
8  
9 use Padre::Plugin ();
10  
11 our @ISA = 'Padre::Plugin';
12  
13 ######################################################################
14 # Padre Integration
15  
16 sub padre_interfaces {
17 'Padre::Plugin' => 0.92,;
18 }
19  
20  
21 ######################################################################
22 # Padre::Plugin Methods
23  
24 sub plugin_name {
25 Wx::gettext('Mojolicious');
26 }
27  
28 sub plugin_disable {
29 require Padre::Unload;
30 Padre::Unload->unload('Padre::Plugin::Mojolicious::NewApp');
31 Padre::Unload->unload('Padre::Plugin::Mojolicious::Util');
32 Padre::Unload->unload('Mojolicious');
33 }
34  
35 # The command structure to show in the Plugins menu
36 sub menu_plugins_simple {
37 my $self = shift;
38 return $self->plugin_name => [
39 Wx::gettext('New Mojolicious Application') => sub {
40 require Padre::Plugin::Mojolicious::NewApp;
41 Padre::Plugin::Mojolicious::NewApp->new( $self->main )->run;
42 return;
43 },
44  
45 '---' => undef,
46  
47 Wx::gettext('Start Web Server') => sub {
48 $self->on_start_server;
49 },
50  
51 Wx::gettext('Stop Web Server') => sub {
52 $self->on_stop_server;
53 },
54  
55 '---' => undef,
56  
57 Wx::gettext('Mojolicious Online References') => [
58 Wx::gettext('Mojolicious Manual') => sub {
59 Padre::Wx::launch_browser('http://mojolicio.us/perldoc');
60 },
61 Wx::gettext('Mojolicious Website') => sub {
62 Padre::Wx::launch_browser('http://www.mojolicious.org/');
63 },
64 Wx::gettext('Mojolicious Community Live Support') => sub {
65 Padre::Wx::launch_irc( 'irc.perl.org' => 'mojo' );
66 },
67  
68 ],
69  
70 '---' => undef,
71  
72 Wx::gettext('About') => sub {
73 $self->on_show_about;
74 },
75 ];
76 }
77  
78 sub on_start_server {
79 my $self = shift;
80 my $main = $self->main;
81  
82 require Padre::Plugin::Mojolicious::Util;
83 my $project_dir = Padre::Plugin::Mojolicious::Util::get_document_base_dir();
84  
85 my $server_filename = Padre::Plugin::Mojolicious::Util::get_mojolicious_project_name($project_dir);
86  
87 my $server_full_path = File::Spec->catfile( $project_dir, 'script', $server_filename );
88 unless ( -e $server_full_path ) {
89 Wx::MessageBox(
90 sprintf(
91 Wx::gettext(
92 "Mojolicious application script not found at\n%s\n\nPlease make sure the active document is from your Mojolicious project."
93 ),
94 $server_full_path
95 ),
96 Wx::gettext('Server not found'),
97 Wx::wxOK, $main
98 );
99 return;
100 }
101  
102 # Go to the selected file's directory
103 # (Mojolicious instructs us to always run their scripts
104 # from the basedir)
105 my $pwd = Cwd::cwd();
106 chdir $project_dir;
107  
108 require Padre::Perl;
109 my $command = Padre::Perl->cperl . ' ' . File::Spec->catfile( 'script', $server_filename ) . ' daemon';
110  
111 $main->run_command($command);
112  
113 # restore current dir
114 chdir $pwd;
115  
116 # TODO: actually check whether this is true.
117 my $ret = Wx::MessageBox(
118 Wx::gettext('Web server appears to be running. Launch web browser now?'),
119 Wx::gettext('Start Web Browser?'),
120 Wx::wxYES_NO | Wx::wxCENTRE,
121 $main,
122 );
123 if ( $ret == Wx::wxYES ) {
124 Padre::Wx::launch_browser('http://localhost:3000');
125 }
126  
127 # TODO: handle menu greying
128  
129 return;
130 }
131  
132 sub on_stop_server {
133 my $self = shift;
134 my $main = $self->main;
135  
136 # TODO: Make this actually call
137 # Run -> Stop
138 if ( $main->{command} ) {
139 my $processid = $main->{command}->GetProcessId();
140 kill( 9, $processid );
141  
142 # $main->{command}->TerminateProcess;
143 }
144 delete $main->{command};
145 $main->menu->run->enable;
146 $main->output->AppendText( "\n" . Wx::gettext('Web server stopped successfully.') . "\n" );
147 return;
148 }
149  
150 sub on_show_about {
151 require Mojolicious;
152 require Padre::Unload;
153 my $about = Wx::AboutDialogInfo->new;
154 $about->SetName('Padre::Plugin::Mojolicious');
155 $about->SetDescription( Wx::gettext('Mojolicious support for Padre') . "\n\n"
156 . sprintf( Wx::gettext('This system is running Mojolicious version %s'), $Mojolicious::VERSION )
157 . "\n" );
158 $about->SetVersion($Padre::Plugin::Mojolicious::VERSION);
159 Padre::Unload->unload('Mojolicious');
160 Wx::AboutBox($about);
161 return;
162 }
163  
164  
165 1;
166  
167 __END__