| 1 | package Analizo::Command; | ||||||||||||||||||
| 2 | 18 | ▶ | use App::Cmd::Setup -command; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 18 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 18 | ▶ | use Class::Inspector; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | 18 | ▶ | use Env::Path qw( PATH ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 18 | ▶ | use File::Temp qw( tmpnam ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | Analizo::Command - global options for tools | ||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | Following the instructions from the L<App::Cmd::Tutorial> we create this module | ||||||||||||||||||
| 16 | to be a superclass of every analizo tool, in that way we can have global | ||||||||||||||||||
| 17 | options to every analizo tool: | ||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | analizo <tool> --help | ||||||||||||||||||
| 20 | analizo <tool> --usage | ||||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | Any analizo tool should implement B<validate()>, method which is called by | ||||||||||||||||||
| 23 | B<validate_args()> implemented here. See L<App::Cmd::Command> for details about | ||||||||||||||||||
| 24 | B<validate_args()>. | ||||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | =cut | ||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | 2 | ▶ | sub validate_args { | ||||||||||||||||
|
Subroutine
validate_args: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||
| 29 | 2 | my ($self, $opt, $args) = @_; | |||||||||||||||||
| 30 | 2 | ▶ | if ($self->app->global_options->version) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 31 | 1 | $self->usage_error("Invalid option: --version"); | |||||||||||||||||
| 32 | } | ||||||||||||||||||
| 33 | elsif ($self->app->global_options->usage) { | ||||||||||||||||||
| 34 | 0 | print $self->app->usage, "\n", $self->usage; | |||||||||||||||||
| 35 | 0 | exit 0; | |||||||||||||||||
| 36 | } | ||||||||||||||||||
| 37 | 1 | $self->validate($opt, $args); | |||||||||||||||||
| 38 | } | ||||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | 1 | ▶ | sub version_information { | ||||||||||||||||
|
Subroutine
version_information: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 41 | 1 | my ($self) = @_; | |||||||||||||||||
| 42 | 1 | sprintf("%s version %s", $self->app->arg0, $Analizo::VERSION); | |||||||||||||||||
| 43 | } | ||||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | 0 | ▶ | sub show_manpage { | ||||||||||||||||
|
Subroutine
show_manpage: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||
| 46 | 0 | my ($self, $package, $command_name) = @_; | |||||||||||||||||
| 47 | 0 | my $version_information = $self->version_information; | |||||||||||||||||
| 48 | 0 | my $file = Class::Inspector->resolved_filename($package); | |||||||||||||||||
| 49 | 0 | ▶ | if (scalar PATH->Whence('man')) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 50 | 0 | my $pod2man = "pod2man --name='analizo-$command_name' --release='$version_information' --center='Analizo documentation'"; | |||||||||||||||||
| 51 | 0 | ▶ | if ($^O eq 'freebsd') { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 52 | 0 | my $tmpfile = tmpnam(); | |||||||||||||||||
| 53 | 0 | exec("$pod2man '$file' > $tmpfile && man $tmpfile && rm -f $tmpfile"); | |||||||||||||||||
| 54 | } | ||||||||||||||||||
| 55 | else { | ||||||||||||||||||
| 56 | 0 | exec("$pod2man '$file' | man -l -"); | |||||||||||||||||
| 57 | } | ||||||||||||||||||
| 58 | } | ||||||||||||||||||
| 59 | elsif (scalar PATH->Whence('less')) { | ||||||||||||||||||
| 60 | 0 | exec("pod2text '$file' | less"); | |||||||||||||||||
| 61 | } | ||||||||||||||||||
| 62 | elsif (scalar PATH->Whence('more')) { | ||||||||||||||||||
| 63 | 0 | exec("pod2text '$file' | more"); | |||||||||||||||||
| 64 | } | ||||||||||||||||||
| 65 | else { | ||||||||||||||||||
| 66 | 0 | exec("pod2text '$file'"); | |||||||||||||||||
| 67 | } | ||||||||||||||||||
| 68 | } | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | 18 | 1; | |||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | =head1 COPYRIGHT AND AUTHORS | ||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | See B<analizo(1)>. | ||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | =cut | ||||||||||||||||||