Mojolicious/Command/routes.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 65.0% 13 / 20 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 80.0% 64 / 80 CC 16 SCAR 24.8
CC
16
Cov
83%
_walk
17.1
run
3.0
BEGIN
1.0
CRAP 12.0
« Mojo/Cookie/Response.pm ↑ Summary Mojolicious/Validator.pm »
1 package Mojolicious::Command::routes;
2 1 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use re qw(regexp_pattern);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::Util qw(encode getopt tablify);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 has description => 'Show available routes';
8 1 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: called CC=1 SCAR=0.0
9  
10 3 ▶sub run {
Subroutine run: called CC=3 SCAR=11.0
Pod documented
11 3 my ($self, @args) = @_;
12  
13 3 ▶ die $self->usage unless getopt \@args, 'v|verbose' => \my $verbose;
Branch: 1 branch
BranchTrueFalseTotal
unless getopt(\@args, "v|verbose", \my $verbose) 1 2 3
14  
15 2 my $rows = [];
16 2 _walk($_, 0, $rows, $verbose) for @{$self->app->routes->children};
17 2 print encode('UTF-8', tablify($rows));
18 }
19  
20 2 ▶sub _walk {
Subroutine _walk: called CC=14 SCAR=28.4
21 2 my ($route, $depth, $rows, $verbose) = @_;
22  
23 # Pattern
24 2 my $prefix = '';
25 0 ▶ if (my $i = $depth * 2) { $prefix .= ' ' x $i . '+' }
Branch: 1 branch
BranchTrueFalseTotal
if (my $i = $depth * 2) 0 2 2
26 2 ▶ push @$rows, my $row = [$prefix . ($route->pattern->unparsed || '/')];
Condition50%1/2
$route->pattern->unparsed || '/'
l!l
20
MC/DC0%0/1
$route->pattern->unparsed || '/'
$route->pattern->unparsed
Truth table50%1/2
A
A= $route->pattern->unparsed
Aresult
11
00
27  
28 # Flags
29 2 my @flags;
30 2 ▶ push @flags, @{$route->requires // []} ? 'C' : '.';
Branch: 1 branch
BranchTrueFalseTotal
@{$route->requires // [];} ? : 0 2 2
Condition50%1/2
$route->requires // []
l!l
02
MC/DC0%0/1
$route->requires // []
$route->requires
Truth table50%1/2
A
A= $route->requires
Aresult
11
00
31 2 ▶ push @flags, (my $partial = $route->partial) ? 'P' : '.';
Branch: 1 branch
BranchTrueFalseTotal
(my $partial = $route->partial) ? : 0 2 2
32 2 ▶ push @flags, $route->inline ? 'U' : '.';
Branch: 1 branch
BranchTrueFalseTotal
$route->inline ? : 0 2 2
33 2 ▶ push @flags, $route->is_websocket ? 'W' : '.';
Branch: 1 branch
BranchTrueFalseTotal
$route->is_websocket ? : 0 2 2
34 2 ▶ push @$row, join('', @flags) if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 1 1 2
35  
36 # Methods
37 2 my $methods = $route->methods;
38 2 ▶ push @$row, !$methods ? '*' : uc join ',', @$methods;
Branch: 1 branch
BranchTrueFalseTotal
!$methods ? : 2 0 2
39  
40 # Name
41 2 my $name = $route->name;
42 2 ▶ push @$row, $route->has_custom_name ? qq{"$name"} : $name;
Branch: 1 branch
BranchTrueFalseTotal
$route->has_custom_name ? : 0 2 2
43  
44 # Regex (verbose)
45 2 my $pattern = $route->pattern;
46 2 ▶ $pattern->match('/', $route->is_endpoint && !$partial);
Condition33%1/3
$route->is_endpoint && !$partial
!ll&&!rl&&r
002
MC/DC0%0/2
$route->is_endpoint && !$partial
$route->is_endpoint !$partial
Truth table33%1/3
A && not(B)
A= $route->is_endpointB= !$partial
ABresult
0X0
100
111
47 2 ▶ push @$row, (regexp_pattern $pattern->regex)[0] if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 1 1 2
48  
49 2 $depth++;
50 2 _walk($_, $depth, $rows, $verbose) for @{$route->children};
51 2 $depth--;
52 }
53  
54 1 1;
55  
56 =encoding utf8
57  
58 =head1 NAME
59  
60 Mojolicious::Command::routes - Routes command
61  
62 =head1 SYNOPSIS
63  
64 Usage: APPLICATION routes [OPTIONS]
65  
66 ./myapp.pl routes
67 ./myapp.pl routes -v
68  
69 Options:
70 -h, --help Show this summary of available options
71 --home <path> Path to home directory of your application, defaults to
72 the value of MOJO_HOME or auto-detection
73 -m, --mode <name> Operating mode for your application, defaults to the
74 value of MOJO_MODE/PLACK_ENV or "development"
75 -v, --verbose Print additional details about routes, flags indicate
76 C=Conditions, P=Partial, U=Under and W=WebSocket
77  
78 =head1 DESCRIPTION
79  
80 L<Mojolicious::Command::routes> lists all your application routes.
81  
82 This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
83 you're welcome to fork it.
84  
85 See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
86  
87 =head1 ATTRIBUTES
88  
89 L<Mojolicious::Command::routes> inherits all attributes from L<Mojolicious::Command> and implements the following new
90 ones.
91  
92 =head2 description
93  
94 my $description = $routes->description;
95 $routes = $routes->description('Foo');
96  
97 Short description of this command, used for the command list.
98  
99 =head2 usage
100  
101 my $usage = $routes->usage;
102 $routes = $routes->usage('Foo');
103  
104 Usage information for this command, used for the help screen.
105  
106 =head1 METHODS
107  
108 L<Mojolicious::Command::routes> inherits all methods from L<Mojolicious::Command> and implements the following new
109 ones.
110  
111 =head2 run
112  
113 $routes->run(@ARGV);
114  
115 Run this command.
116  
117 =head1 SEE ALSO
118  
119 L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
120  
121 =cut
« Mojo/Cookie/Response.pm ↑ Summary Mojolicious/Validator.pm »