lib/Mojolicious/Command/generate/qx_mojo_app.pm

filter: Statementstmt 38.7% 19 / 49 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 62.5% 5 / 8 Podpod 100% 2 / 2 totaltotal 37.1% 26 / 70 CC 7 SCAR 33.5
CC
7
Cov
32%
run
56.0
render_data
2.0
__ANON__
1.1
CRAP 28.6
↑ Summary blib/lib/Mojolicious/Command/generate/qx_mojo_app/bin/script.pl »
1 package Mojolicious::Command::generate::qx_mojo_app;
2 1 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mojo::Util qw(class_to_file class_to_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::File qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use POSIX qw(strftime);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.4.0';
9  
10 1 has description => 'Generate Qooxdoo Mojolicious web application directory structure.';
11 0 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: not called CC=1 SCAR=1.2
12  
13 0 ▶sub run {
Subroutine run: not called CC=7 SCAR=40.3
Pod documented
14 0 my ($self, $class) = @_;
15 0 ▶ $class ||= 'MyMojoQxApp';
Condition0%0/2
$class ||= "MyMojoQxApp"
l!l
00
MC/DC0%0/1
$class ||= "MyMojoQxApp"
$class
Truth table0%0/2
A
A= $class
Aresult
11
00
16  
17 # Prevent bad applications
18 0 ▶ die <<EOF unless $class =~ /^[A-Z](?:\w|::)+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $class =~ /^[A-Z](?:\w|::)+$/u 0 0 0
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 ▶ if ( -r $ENV{HOME} . '/.gitconfig' ){
Branch: 1 branch
BranchTrueFalseTotal
if (-r $ENV{"HOME"} . '/.gitconfig') 0 0 0
61 0 my $in = path($ENV{HOME} . '/.gitconfig')->slurp;
62 0 ▶ $in =~ /name\s*=\s*(\S.+\S)/ and $fullName = $1;
Branch: 1 branch
BranchTrueFalseTotal
$in =~ /name\s*=\s*(\S.+\S)/u and $fullName = $1 0 0 0
63 0 ▶ $in =~ /email\s*=\s*(\S+)/ and $email = $1;
Branch: 1 branch
BranchTrueFalseTotal
$in =~ /email\s*=\s*(\S+)/u and $email = $1 0 0 0
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 0 ▶sub render_data {
Subroutine render_data: not called CC=1 SCAR=6.9
Pod documented
94 0 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 1;
↑ Summary blib/lib/Mojolicious/Command/generate/qx_mojo_app/bin/script.pl »