Mojolicious/Command/Author/webpack.pm

filter: Statementstmt 86.0% 43 / 50 Branchbran 63.6% 14 / 22 Conditioncond 53.3% 8 / 15 MC/DCmcdc 44.4% 4 / 9 Subroutinesub 81.8% 9 / 11 Podpod 100% 1 / 1 totaltotal 73.1% 79 / 108 CC 18 SCAR 20.0
CC
18
Cov
75%
run
12.2
__ANON__
8.7
_build
6.0
CRAP 7.4
« Mojo/Alien/rollup.pm ↑ Summary Mojolicious/Plugin/Webpack.pm »
1 package Mojolicious::Command::Author::webpack;
2 1 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Mojo::File 'path';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::Util 'getopt';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # Less noisy test runs
8 1 ▶use constant SILENT => $ENV{HARNESS_ACTIVE} && !$ENV{HARNESS_IS_VERBOSE};
Subroutine BEGIN: called CC=2 SCAR=7.6
Condition33%1/3
$ENV{'HARNESS_ACTIVE'} && !$ENV{'HARNESS_IS_VERBOSE'}
!ll&&!rl&&r
001
MC/DC0%0/2
$ENV{'HARNESS_ACTIVE'} && !$ENV{'HARNESS_IS_VERBOSE'}
$ENV{'HARNESS_ACTIVE'} !$ENV{'HARNESS_IS_VERBOSE'}
Truth table33%1/3
A && not(B)
A= $ENV{'HARNESS_ACTIVE'}B= !$ENV{'HARNESS_IS_VERBOSE'}
ABresult
0X0
100
111
9  
10 # Ugly hack to prevent Mojo::Server::Morbo from exiting
11 1 our $WORKER_PID = -1;
12 0 ▶*CORE::GLOBAL::exit = sub { $WORKER_PID == $$ ? $_[0] : CORE::exit($_[0] // $!) };
Subroutine __ANON__: not called CC=3 SCAR=21.6
Branch: 1 branch
BranchTrueFalseTotal
$Mojolicious::Command::Author::webpack::WORKER_PID == $$ ? : 0 0 0
Condition0%0/3
$_[0] // $!
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] // $!
$_[0] $!
Truth table0%0/3
A // B
A= $_[0]B= $!
ABresult
1X1
011
000
13  
14 1 has description => 'Start application with HTTP, WebSocket and Webpack development server';
15 1 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: called CC=1 SCAR=0.0
16 1 ▶has _morbo => sub { require Mojo::Server::Morbo; Mojo::Server::Morbo->new };
Subroutine __ANON__: called CC=1 SCAR=0.0
17  
18 15 ▶sub run {
Subroutine run: called CC=12 SCAR=25.0
Pod documented
19 15 my ($self, @argv) = @_;
20  
21 # Need to run "mojo webpack" and not "./myapp.pl webpack" to have a clean environment
22 15 ▶ return $self->_exec_mojo_webpack($0, @argv) unless path($0)->basename eq 'mojo';
Branch: 1 branch
BranchTrueFalseTotal
unless path($0)->basename eq "mojo" 1 14 15
23  
24 # Parse command line options
25 getopt \@argv,
26 'B|build' => \my $build,
27 'b|backend=s' => \$ENV{MOJO_MORBO_BACKEND},
28 'h|help' => \my $help,
29 'l|listen=s' => \my @listen,
30 'm|mode=s' => \$ENV{MOJO_MODE},
31 'v|verbose' => \$ENV{MORBO_VERBOSE},
32 14 'w|watch=s' => \my @watch;
33  
34 14 ▶ die join "\n\n", $self->description, $self->usage if $help or !(my $app = shift @argv);
Branch: 1 branch
BranchTrueFalseTotal
if $help or not my $app = shift @argv 3 11 14
Condition100%3/3
$help or not my $app = shift @argv
l!l&&r!l&&!r
2111
MC/DC100%2/2
$help or not my $app = shift @argv
$help not my $app = shift @argv
Truth table100%3/3
A or not(B)
A= $helpB= not my $app = shift @argv
ABresult
1X1
011
000
35 11 ▶ return $self->_build($app) if $build;
Branch: 1 branch
BranchTrueFalseTotal
if $build 0 11 11
36  
37 # Start rollup/webpack
38 11 my $builder_pid = $self->_start_builder($app);
39 11 ▶ say "Bundler started with pid $builder_pid." if +($ENV{MORBO_VERBOSE} // 1) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MORBO_VERBOSE"} // 1) == 1 11 0 11
Condition100%2/2
$ENV{"MORBO_VERBOSE"} // 1
l!l
47
MC/DC100%1/1
$ENV{"MORBO_VERBOSE"} // 1
$ENV{"MORBO_VERBOSE"}
Truth table100%2/2
A
A= $ENV{"MORBO_VERBOSE"}
Aresult
11
00
40  
41 # Set up and start morbo - Mojo::Server::Morbo::run() will block until the the app is killed
42 11 local $ENV{MOJO_WEBPACK_BUILD} = ''; # Silence initial "Sure ... has been run ..." warning
43 11 local $WORKER_PID = $$;
44 11 ▶ $self->_morbo->backend->watch(\@watch) if @watch;
Branch: 1 branch
BranchTrueFalseTotal
if @watch 2 9 11
45 11 ▶ $self->_morbo->daemon->listen(\@listen) if @listen;
Branch: 1 branch
BranchTrueFalseTotal
if @listen 2 9 11
46 11 $self->_morbo->run($app);
47  
48 # Stop rollup/webpack after the app is killed
49 11 ▶ warn "[Webpack] [$$] Reaping builder with pid $builder_pid...\n" if $ENV{MORBO_VERBOSE} and !SILENT;
Branch: 1 branch
BranchTrueFalseTotal
if 0 11 11
Condition100%2/2
$ENV{"MORBO_VERBOSE"} and
!ll
74
MC/DC100%1/1
$ENV{"MORBO_VERBOSE"} and
$ENV{"MORBO_VERBOSE"}
Truth table100%2/2
A
A= $ENV{"MORBO_VERBOSE"}
Aresult
00
11
50 11 ▶ 1 while kill $builder_pid;
Branch: 1 branch
BranchTrueFalseTotal
kill($builder_pid) and do { 1 } 0 11 11
51 }
52  
53 0 ▶sub _build {
Subroutine _build: not called CC=2 SCAR=17.9
54 0 my ($self, $app) = @_;
55 0 ▶ $ENV{MOJO_WEBPACK_BUILD} ||= 'build';
Condition0%0/2
$ENV{"MOJO_WEBPACK_BUILD"} ||= "build"
l!l
00
MC/DC0%0/1
$ENV{"MOJO_WEBPACK_BUILD"} ||= "build"
$ENV{"MOJO_WEBPACK_BUILD"}
Truth table0%0/2
A
A= $ENV{"MOJO_WEBPACK_BUILD"}
Aresult
11
00
56 0 Mojo::Server->new->load_app($app);
57 }
58  
59 1 ▶sub _exec_mojo_webpack {
Subroutine _exec_mojo_webpack: called CC=1 SCAR=0.0
60 1 my ($self, @argv) = @_;
61 1 warn "Switching to `mojo webpack @argv` ...\n" unless SILENT;
62 1 { exec qw(mojo webpack), @argv };
63 1 die "exec mojo @argv: $!";
64 }
65  
66 11 ▶sub _start_builder {
Subroutine _start_builder: called CC=3 SCAR=14.2
67 11 my ($self, $app) = @_;
68 11 ▶ die "Can't fork: $!" unless defined(my $pid = fork);
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $pid = fork()) 0 11 11
69 11 ▶ return $pid if $pid;
Branch: 1 branch
BranchTrueFalseTotal
if $pid 11 0 11
70 0 local $ENV{MOJO_WEBPACK_BUILD} = 'watch';
71 0 Mojo::Server->new->load_app($app);
72 0 exit $!;
73 }
74  
75 1 1;
76  
77 =encoding utf8
78  
79 =head1 NAME
80  
81 Mojolicious::Command::Author::webpack - Mojolicious HTTP, WebSocket and Webpack development server
82  
83 =head1 SYNOPSIS
84  
85 Usage: mojo webpack [OPTIONS] [APPLICATION]
86  
87 mojo webpack ./script/my_app
88 mojo webpack ./myapp.pl
89 mojo webpack -m production -l https://*:443 -l http://[::]:3000 ./myapp.pl
90 mojo webpack -l 'https://*:443?cert=./server.crt&key=./server.key' ./myapp.pl
91 mojo webpack -w /usr/local/lib -w public -w myapp.conf ./myapp.pl
92 mojo webpack --build --mode production
93 MOJO_NPM_BINARY=pnpm mojo webpack --build
94  
95 Options:
96 -B, --build Build the assets and exit
97 -b, --backend <name> Morbo backend to use for reloading, defaults
98 to "Poll"
99 -h, --help Show this message
100 -l, --listen <location> One or more locations you want to listen on,
101 defaults to the value of MOJO_LISTEN or
102 "http://*:3000"
103 -m, --mode <name> Operating mode for your application,
104 defaults to the value of
105 MOJO_MODE/PLACK_ENV or "development"
106 -v, --verbose Print details about what files changed to
107 STDOUT
108 -w, --watch <directory/file> One or more directories and files to watch
109 for changes, defaults to the application
110 script as well as the "lib" and "templates"
111 directories in the current working
112 directory
113  
114 =head1 DESCRIPTION
115  
116 Start L<Mojolicious> and L<Mojolicious::Lite> applications with the
117 L<Mojo::Server::Morbo> web server.
118  
119 =head1 ATTRIBUTES
120  
121 =head2 description
122  
123 my $description = $daemon->description;
124 $daemon = $daemon->description('Foo');
125  
126 Short description of this command, used for the command list.
127  
128 =head2 usage
129  
130 my $usage = $daemon->usage;
131 $daemon = $daemon->usage('Foo');
132  
133 Usage information for this command, used for the help screen.
134  
135 =head1 METHODS
136  
137 =head2 run
138  
139 $daemon->run(@ARGV);
140  
141 Run this command.
142  
143 =head1 SEE ALSO
144  
145 L<Mojo::Server::Morbo>, L<Mojolicious::Plugin::Webpack>
146  
147 =cut
« Mojo/Alien/rollup.pm ↑ Summary Mojolicious/Plugin/Webpack.pm »