Newer Older
105 lines | 2.473kb
add files
Yuki Kimoto authored on 2014-03-26
1
package Mojolicious::Command::version;
2
use Mojo::Base 'Mojolicious::Command';
3

            
4
use Mojo::IOLoop::Server;
5
use Mojo::UserAgent;
6
use Mojolicious;
7

            
8
has description => "Show versions of installed modules.\n";
9
has usage       => "usage: $0 version\n";
10

            
11
sub run {
12
  my $self = shift;
13

            
14
  my $ev = eval 'use Mojo::Reactor::EV; 1' ? $EV::VERSION : 'not installed';
15
  my $ipv6
16
    = Mojo::IOLoop::Server::IPV6 ? $IO::Socket::IP::VERSION : 'not installed';
17
  my $tls
18
    = Mojo::IOLoop::Server::TLS ? $IO::Socket::SSL::VERSION : 'not installed';
19

            
20
  print <<EOF;
21
CORE
22
  Perl        ($^V, $^O)
23
  Mojolicious ($Mojolicious::VERSION, $Mojolicious::CODENAME)
24

            
25
OPTIONAL
26
  EV 4.0+               ($ev)
27
  IO::Socket::IP 0.16+  ($ipv6)
28
  IO::Socket::SSL 1.75+ ($tls)
29

            
30
EOF
31

            
32
  # Check latest version on CPAN
33
  my $latest = eval {
34
    my $ua = Mojo::UserAgent->new(max_redirects => 10);
35
    $ua->proxy->detect;
36
    $ua->get('api.metacpan.org/v0/release/Mojolicious')->res->json->{version};
37
  };
38

            
39
  return unless $latest;
40
  my $msg = 'This version is up to date, have fun!';
41
  $msg = 'Thanks for testing a development release, you are awesome!'
42
    if $latest < $Mojolicious::VERSION;
43
  $msg = "You might want to update your Mojolicious to $latest."
44
    if $latest > $Mojolicious::VERSION;
45
  say $msg;
46
}
47

            
48
1;
49

            
50
=encoding utf8
51

            
52
=head1 NAME
53

            
54
Mojolicious::Command::version - Version command
55

            
56
=head1 SYNOPSIS
57

            
58
  use Mojolicious::Command::version;
59

            
60
  my $v = Mojolicious::Command::version->new;
61
  $v->run(@ARGV);
62

            
63
=head1 DESCRIPTION
64

            
65
L<Mojolicious::Command::version> shows version information for installed core
66
and optional modules.
67

            
68
This is a core command, that means it is always enabled and its code a good
69
example for learning to build new commands, you're welcome to fork it.
70

            
71
=head1 ATTRIBUTES
72

            
73
L<Mojolicious::Command::version> inherits all attributes from
74
L<Mojolicious::Command> and implements the following new ones.
75

            
76
=head2 description
77

            
78
  my $description = $v->description;
79
  $v              = $v->description('Foo!');
80

            
81
Short description of this command, used for the command list.
82

            
83
=head2 usage
84

            
85
  my $usage = $v->usage;
86
  $v        = $v->usage('Foo!');
87

            
88
Usage information for this command, used for the help screen.
89

            
90
=head1 METHODS
91

            
92
L<Mojolicious::Command::version> inherits all methods from
93
L<Mojolicious::Command> and implements the following new ones.
94

            
95
=head2 run
96

            
97
  $v->run(@ARGV);
98

            
99
Run this command.
100

            
101
=head1 SEE ALSO
102

            
103
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
104

            
105
=cut