File Coverage

lib/Mojolicious/Command/generate/qx_mojo_app.pm
Criterion Covered Total %
statement 15 44 34.0
branch 0 8 0.0
condition 0 2 0.0
subroutine 5 7 71.4
pod 2 2 100.0
total 22 63 34.9


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