| 1 | package P5U::Command::Version; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use strict; | ||
| 5 | use utf8; | ||
| 6 | use P5U-command; | ||
| 7 | |||
| 8 | use PerlX::Maybe 0 'maybe'; | ||
| 9 | |||
| 10 | BEGIN { | ||
| 11 | $P5U::Command::Version::AUTHORITY = 'cpan:TOBYINK'; | ||
| 12 | $P5U::Command::Version::VERSION = '0.100'; | ||
| 13 | }; | ||
| 14 | |||
| 15 | use constant { | ||
| 16 | abstract => q[show the version number of a module], | ||
| 17 | usage_desc => q[%c version %o Module], | ||
| 18 | }; | ||
| 19 | |||
| 20 | sub command_names | ||
| 21 | { | ||
| 22 | qw( | ||
| 23 | version | ||
| 24 | v | ||
| 25 | ); | ||
| 26 | } | ||
| 27 | |||
| 28 | sub description | ||
| 29 | { | ||
| 30 | <<'DESCRIPTION' | ||
| 31 | This command is inspired by V.pm. Given one or more module names, it | ||
| 32 | locates the modules on your local system and tells you the version | ||
| 33 | number. (Note that you may have multiple versions of a module installed | ||
| 34 | in different locations.) | ||
| 35 | |||
| 36 | p5u v MooseX::Types MouseX::Types | ||
| 37 | |||
| 38 | Unlike V.pm, it also has the ability to reach out to CPAN/BackPAN and find | ||
| 39 | versions of the module available there: | ||
| 40 | |||
| 41 | p5u v -c MooseX::Types | ||
| 42 | p5u v -b MooseX::Types | ||
| 43 | |||
| 44 | You can even combine options: | ||
| 45 | |||
| 46 | p5u v -lcb MooseX::Types | ||
| 47 | p5u v -lc MooseX::Types MouseX::Types | ||
| 48 | |||
| 49 | If no options are provided, defaults to "--local". | ||
| 50 | DESCRIPTION | ||
| 51 | } | ||
| 52 | |||
| 53 | sub opt_spec | ||
| 54 | { | ||
| 55 | return ( | ||
| 56 | ['cpan|c' => 'search CPAN'], | ||
| 57 | ['local|l' => 'search @INC'], | ||
| 58 | ['backpan|b' => 'search BackPAN'], | ||
| 59 | ); | ||
| 60 | } | ||
| 61 | |||
| 62 | sub execute | ||
| 63 | { | ||
| 64 | my ($self, $opt, $args) = @_; | ||
| 65 | |||
| 66 | $opt->{local}++ unless $opt->{cpan} || $opt->{backpan}; | ||
| 67 | $self->usage_error("You must provide a module name.") | ||
| 68 | unless @$args; | ||
| 69 | |||
| 70 | require P5U::Lib::Version; | ||
| 71 | my $helper = 'P5U::Lib::Version'; | ||
| 72 | |||
| 73 | while (my $m = shift @$args) | ||
| 74 | { | ||
| 75 | say $m; | ||
| 76 | |||
| 77 | my @lines; | ||
| 78 | push @lines, $helper->local_module_info($m) if $opt->{local}; | ||
| 79 | push @lines, $helper->cpan_module_info($m) if $opt->{cpan}; | ||
| 80 | push @lines, $helper->backpan_module_info($m) if $opt->{backpan}; | ||
| 81 | push @lines, q(Not found) unless @lines; | ||
| 82 | |||
| 83 | say "\t$_" for @lines; | ||
| 84 | say q() if @$args; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | 1; |