File Coverage

blib/lib/Mojolicious/Command/version.pm
Criterion Covered Total %
statement 32 33 96.9
branch 10 20 50.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 50 61 81.9


line stmt bran cond sub pod time code
1             package Mojolicious::Command::version;
2 1     1   9 use Mojo::Base 'Mojolicious::Command';
  1         3  
  1         7  
3              
4 1     1   7 use Mojo::IOLoop::Client;
  1         2  
  1         29  
5 1     1   6 use Mojo::IOLoop::TLS;
  1         3  
  1         11  
6 1     1   7 use Mojo::JSON;
  1         2  
  1         37  
7 1     1   6 use Mojolicious;
  1         2  
  1         9  
8              
9             has description => 'Show versions of available modules';
10             has usage => sub { shift->extract_usage };
11              
12             sub run {
13 1     1 1 5 my $self = shift;
14              
15 1 50       20 my $json = Mojo::JSON->JSON_XS ? $Cpanel::JSON::XS::VERSION : 'n/a';
16 1 50       8 my $ev = eval { require Mojo::Reactor::EV; 1 } ? $EV::VERSION : 'n/a';
  1         994  
  0         0  
17 1 50       17 my $socks = Mojo::IOLoop::Client->can_socks ? $IO::Socket::Socks::VERSION : 'n/a';
18 1 50       12 my $tls = Mojo::IOLoop::TLS->can_tls ? $IO::Socket::SSL::VERSION : 'n/a';
19 1 50       8 my $nnr = Mojo::IOLoop::Client->can_nnr ? $Net::DNS::Native::VERSION : 'n/a';
20 1 50       7 my $roles = Mojo::Base->ROLES ? $Role::Tiny::VERSION : 'n/a';
21 1 50       7 my $async = Mojo::Base->ASYNC ? $Future::AsyncAwait::VERSION : 'n/a';
22              
23 1         45 print <
24             CORE
25             Perl ($^V, $^O)
26             Mojolicious ($Mojolicious::VERSION, $Mojolicious::CODENAME)
27              
28             OPTIONAL
29             Cpanel::JSON::XS 4.09+ ($json)
30             EV 4.32+ ($ev)
31             IO::Socket::Socks 0.64+ ($socks)
32             IO::Socket::SSL 2.009+ ($tls)
33             Net::DNS::Native 0.15+ ($nnr)
34             Role::Tiny 2.000001+ ($roles)
35             Future::AsyncAwait 0.52+ ($async)
36              
37             EOF
38              
39             # Check latest version on CPAN
40 1 50       3 my $latest = eval {
41 1     1   6 $self->app->ua->max_redirects(10)->tap(sub { $_->proxy->detect })
42 1         7 ->get('fastapi.metacpan.org/v1/release/Mojolicious')->result->json->{version};
43             } or return;
44              
45 1         7 my $msg = 'This version is up to date, have fun!';
46 1 50       49 $msg = 'Thanks for testing a development release, you are awesome!' if $latest < $Mojolicious::VERSION;
47 1 50       10 $msg = "You might want to update your Mojolicious to $latest!" if $latest > $Mojolicious::VERSION;
48 1         12 say $msg;
49             }
50              
51             1;
52              
53             =encoding utf8
54              
55             =head1 NAME
56              
57             Mojolicious::Command::version - Version command
58              
59             =head1 SYNOPSIS
60              
61             Usage: APPLICATION version [OPTIONS]
62              
63             mojo version
64              
65             Options:
66             -h, --help Show this summary of available options
67              
68             =head1 DESCRIPTION
69              
70             L shows version information for available core and optional modules.
71              
72             This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
73             you're welcome to fork it.
74              
75             See L for a list of commands that are available by default.
76              
77             =head1 ATTRIBUTES
78              
79             L inherits all attributes from L and implements the following new
80             ones.
81              
82             =head2 description
83              
84             my $description = $v->description;
85             $v = $v->description('Foo');
86              
87             Short description of this command, used for the command list.
88              
89             =head2 usage
90              
91             my $usage = $v->usage;
92             $v = $v->usage('Foo');
93              
94             Usage information for this command, used for the help screen.
95              
96             =head1 METHODS
97              
98             L inherits all methods from L and implements the following new
99             ones.
100              
101             =head2 run
102              
103             $v->run(@ARGV);
104              
105             Run this command.
106              
107             =head1 SEE ALSO
108              
109             L, L, L.
110              
111             =cut