Mojolicious/Command/eval.pm

filter: Statementstmt 100% 41 / 41 Branchbran 80.0% 8 / 10 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 85.5% 65 / 76 CC 9 SCAR 15.5
CC
9
Cov
88%
run
9.3
BEGIN
1.0
BEGIN
1.0
CRAP 4.7
« Mojo/Server.pm ↑ Summary Mojo/Cache.pm »
1 package Mojolicious::Command::eval;
2 1 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Mojo::Promise;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::Util qw(getopt);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 has description => 'Run code against application';
8 1 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: called CC=1 SCAR=0.0
9  
10 6 ▶sub run {
Subroutine run: called CC=9 SCAR=22.3
Pod documented
11 6 my ($self, @args) = @_;
12  
13 6 ▶ die $self->usage unless getopt \@args, 'v|verbose' => \my $v1, 'V' => \my $v2;
Branch: 1 branch
BranchTrueFalseTotal
unless getopt(\@args, "v|verbose", \my $v1, "V", \my $v2) 1 5 6
14 5 ▶ my $code = shift @args || '';
Condition50%1/2
shift @args || ''
l!l
50
MC/DC0%0/1
shift @args || ''
shift @args
Truth table50%1/2
A
A= shift @args
Aresult
11
00
15  
16 # Run code against application
17 5 my $app = $self->app;
18 1 ▶ my $result = eval "package main; no warnings 'redefine'; sub app; local *app = sub { \$app }; $code";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 4 5
20  
21 # Handle promises
22 4 my $err;
23 4 ▶ Mojo::Promise->resolve($result)->then(sub { $result = shift }, sub { $err = shift })->wait;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
24 4 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 1 3 4
25  
26 3 ▶ return $result unless defined $result && ($v1 || $v2);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result and $v1 || $v2 0 3 3
Condition33%2/6
defined $result and $v1 || $v2
!ll&&!rl&&r
003
$v1 or $v2
l!l&&r!l&&!r
300
MC/DC0%0/3
defined $result and $v1 || $v2
defined $result $v1 $v2
Truth table25%1/4
A and B or C
A= defined $resultB= $v1C= $v2
ABCresult
0XX0
1000
11X1
1011
27 3 ▶ $v2 ? print($app->dumper($result)) : say $result;
Branch: 1 branch
BranchTrueFalseTotal
$v2 ? : 0 3 3
28 }
29  
30 1 1;
31  
32 =encoding utf8
33  
34 =head1 NAME
35  
36 Mojolicious::Command::eval - Eval command
37  
38 =head1 SYNOPSIS
39  
40 Usage: APPLICATION eval [OPTIONS] CODE
41  
42 ./myapp.pl eval 'say app->ua->get("/")->result->body'
43 ./myapp.pl eval 'say for sort keys %{app->renderer->helpers}'
44 ./myapp.pl eval -v 'app->home'
45 ./myapp.pl eval -V 'app->renderer->paths'
46  
47 Options:
48 -h, --help Show this summary of available options
49 --home <path> Path to home directory of your application, defaults to
50 the value of MOJO_HOME or auto-detection
51 -m, --mode <name> Operating mode for your application, defaults to the
52 value of MOJO_MODE/PLACK_ENV or "development"
53 -v, --verbose Print return value to STDOUT
54 -V Print returned data structure to STDOUT
55  
56 =head1 DESCRIPTION
57  
58 L<Mojolicious::Command::eval> runs code against applications. If the result is a promise (then-able), it will wait
59 until the promise is fulfilled or rejected and the result is returned.
60  
61 This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
62 you're welcome to fork it.
63  
64 See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
65  
66 =head1 ATTRIBUTES
67  
68 L<Mojolicious::Command::eval> inherits all attributes from L<Mojolicious::Command> and implements the following new
69 ones.
70  
71 =head2 description
72  
73 my $description = $eval->description;
74 $eval = $eval->description('Foo');
75  
76 Short description of this command, used for the command list.
77  
78 =head2 usage
79  
80 my $usage = $eval->usage;
81 $eval = $eval->usage('Foo');
82  
83 Usage information for this command, used for the help screen.
84  
85 =head1 METHODS
86  
87 L<Mojolicious::Command::eval> inherits all methods from L<Mojolicious::Command> and implements the following new ones.
88  
89 =head2 run
90  
91 $eval->run(@ARGV);
92  
93 Run this command.
94  
95 =head1 SEE ALSO
96  
97 L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
98  
99 =cut
« Mojo/Server.pm ↑ Summary Mojo/Cache.pm »