File Coverage

lib/Mojolicious/Command/generate/qx_mojo_app.pm
Criterion Covered Total %
statement 12 41 29.2
branch 0 8 0.0
condition 0 2 0.0
subroutine 4 6 66.6
pod 2 2 100.0
total 18 59 30.5


line stmt bran cond sub pod time code
1             package Mojolicious::Command::generate::qx_mojo_app;
2 1     1   1158 use Mojo::Base 'Mojolicious::Command';
  1         8423  
  1         9  
3 1     1   138013 use File::Basename;
  1         4  
  1         86  
4 1     1   21 use Mojo::Util qw(class_to_file class_to_path slurp);
  1         2  
  1         76  
5 1     1   7 use POSIX qw(strftime);
  1         2  
  1         11  
6              
7             our $VERSION = '0.2.2';
8              
9             has description => 'Generate Qooxdoo Mojolicious web application directory structure.';
10             has usage => sub { shift->extract_usage };
11              
12             sub run {
13 0     0 1   my ($self, $class) = @_;
14 0   0       $class ||= 'MyMojoQxApp';
15              
16             # Prevent bad applications
17 0 0         die <
18             Your application name has to be a well formed (CamelCase) Perl module name
19             like "MyApp".
20             EOF
21              
22 0           my $name = class_to_file $class;
23 0           my $class_path = class_to_path $class;
24 0           my $controller = "${class}::Controller::RpcService";
25 0           my $controller_path = class_to_path $controller;
26              
27             # Configure Main Dir
28 0           my $file = {
29             'configure.ac' => 'configure.ac',
30             'bootstrap' => 'bootstrap',
31             'PERL_MODULES' => 'PERL_MODULES',
32             'VERSION' => 'VERSION',
33             'README' => 'README',
34             'AUTHORS' => 'AUTHORS',
35             'LICENSE' => 'LICENSE',
36             'COPYRIGHT' => 'COPYRIGHT',
37             'CHANGES' => 'CHANGES',
38             'Makefile.am' => 'Makefile.am',
39             'backend/Makefile.am' => 'backend/Makefile.am',
40             'backend/bin/script.pl' => 'backend/bin/'.$name.'.pl',
41             'backend/bin/source-mode.sh' => 'backend/bin/'.$name.'-source-mode.sh',
42             'backend/lib/App.pm' => 'backend/lib/'.$class_path,
43             'backend/lib/App/Controller/RpcService.pm' => 'backend/lib/'.$controller_path,
44             'frontend/Makefile.am' => 'frontend/Makefile.am',
45             'frontend/Manifest.json' => 'frontend/Manifest.json',
46             'frontend/config.json' => 'frontend/config.json',
47             'frontend/source/class/app/Application.js' => 'frontend/source/class/'.$name.'/Application.js',
48             'frontend/source/index.html' => 'frontend/source/index.html',
49             'frontend/source/class/app/data/RpcService.js' => 'frontend/source/class/'.$name.'/data/RpcService.js',
50             't/basic.t' => 't/basic.t',
51             };
52              
53 0           my ($userName,$fullName) = (getpwuid $<)[0,6];
54 0           $fullName =~ s/,.+//g;
55 0           chomp(my $domain = `hostname -d`);
56 0           my $email = $userName.'@'.$domain;
57              
58 0 0         if ( -r $ENV{HOME} . '/.gitconfig' ){
59 0           my $in = slurp $ENV{HOME} . '/.gitconfig';
60 0 0         $in =~ /name\s*=\s*(\S.+\S)/ and $fullName = $1;
61 0 0         $in =~ /email\s*=\s*(\S+)/ and $email = $1;
62             }
63              
64 0           for my $key (keys %$file){
65 0           $self->render_to_rel_file($key, $name.'/'.$file->{$key}, {
66             class => $class,
67             name => $name,
68             class_path => $class_path,
69             controller => $controller,
70             controller_path => $controller_path,
71             year => (localtime time)[5]+1900,
72             email => $email,
73             fullName => $fullName,
74             userName => $userName,
75             date => strftime('%Y-%M-%D',localtime(time)),
76             });
77             }
78              
79 0           $self->chmod_rel_file("$name/bootstrap", 0755);
80 0           $self->chmod_rel_file("$name/backend/bin/".$name.".pl", 0755);
81 0           $self->chmod_rel_file("$name/backend/bin/".$name."-source-mode.sh", 0755);
82              
83 0           $self->create_rel_dir("$name/backend/log");
84 0           $self->create_rel_dir("$name/backend/public");
85 0           $self->create_rel_dir("$name/frontend/source/resource/$name");
86 0           $self->create_rel_dir("$name/frontend/source/translation");
87 0           chdir $name;
88 0           system "./bootstrap";
89             }
90              
91             sub render_data {
92 0     0 1   my ($self, $name) = (shift, shift);
93 0           Mojo::Template->new->name("template $name")
94             ->render(slurp(dirname($INC{'Mojolicious/Command/generate/qx_mojo_app.pm'}).'/qx_mojo_app/'.$name), @_);
95             }
96             1;