File Coverage

blib/lib/Mojolicious/Command/version.pm
Criterion Covered Total %
statement 31 32 96.8
branch 9 18 50.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 48 58 82.7


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