File Coverage

blib/lib/Ado/Command/version.pm
Criterion Covered Total %
statement 6 16 37.5
branch 0 8 0.0
condition n/a
subroutine 2 3 66.6
pod 1 1 100.0
total 9 28 32.1


line stmt bran cond sub pod time code
1             package Ado::Command::version;
2 1     1   875 use Mojo::Base 'Ado::Command';
  1         3  
  1         6  
3 1     1   715 use Mojolicious::Command::version;
  1         744  
  1         10  
4              
5              
6             has description => "Show versions of installed modules.\n";
7             has usage => "usage: $0 version\n";
8              
9             has latest => sub {
10             my $latest = eval {
11             my $ua = Mojo::UserAgent->new(max_redirects => 10);
12             $ua->proxy->detect;
13             $ua->get('api.metacpan.org/v0/release/Ado')->res->json->{version};
14             };
15             return $latest;
16             };
17              
18              
19             #the only action this command implements
20             sub version {
21 0     0 1   my $self = shift;
22              
23 0           my $msg = "$/ADO:$/ "
24             . Mojo::Util::encode(Mojo::Message->new->default_charset,
25             $Ado::VERSION . ' - ' . $Ado::CODENAME);
26 0           my $latest = $self->latest;
27 0 0         if ($latest) {
28 0 0         $msg .= "$/ This version is up to date, have fun!$/"
29             if $latest == $Ado::VERSION;
30 0 0         $msg .= "$/ Thanks for testing a development release, you are awesome!$/"
31             if $latest < $Ado::VERSION;
32 0 0         $msg .= "$/ You might want to update your Ado to $latest.$/"
33             if $latest > $Ado::VERSION;
34             }
35 0           say $msg;
36 0           Mojolicious::Command::version->new->run();
37 0           return;
38             }
39              
40             1;
41              
42             =pod
43              
44             =encoding utf8
45              
46             =head1 NAME
47              
48             Ado::Command::version - Version command
49              
50             =head1 SYNOPSIS
51              
52             use Ado::Command::version;
53              
54             my $v = Ado::Command::version->new;
55             $v->run();
56              
57             =head1 DESCRIPTION
58              
59             L shows version information for installed core
60             and optional modules.
61              
62             This is a core command, that means it is always enabled and its code a good
63             example for learning to build new commands, you're welcome to fork it.
64              
65             =head1 ATTRIBUTES
66              
67             L inherits all attributes from
68             L and implements the following new ones.
69              
70             =head2 description
71              
72             my $description = $v->description;
73             $v = $v->description('Foo!');
74              
75             Short description of this command, used for the command list.
76              
77             =head2 usage
78              
79             my $usage = $v->usage;
80             $v = $v->usage('Foo!');
81              
82             Usage information for this command, used for the help screen.
83              
84             =head2 latest
85              
86             Checks for the latest version on metacpan.org and returns it
87             if successfully connected
88              
89             =head1 METHODS
90              
91             L inherits all methods from
92             L and implements the following new ones.
93              
94             =head2 init
95              
96             Default initialization.
97              
98             =head2 version
99              
100             #set in init().
101             $self->args->{do} ='version';
102              
103             The default and only action this command implements.
104             See L.
105              
106              
107             =head1 SEE ALSO
108              
109             L, L L,
110             L, L.
111              
112             =cut
113