| 1 | package Algorithm::Classifier::IsolationForest::App::Command; | ||||||||||
| 2 | 86 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 86 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 86 | ▶ | use App::Cmd::Setup -command; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 0 | ▶ | sub global_opt_spec { | ||||||||
|
Subroutine
global_opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 7 | 0 | my ( $class, $app ) = @_; | |||||||||
| 8 | 0 | return ( $class->options($app), ); | |||||||||
| 9 | } | ||||||||||
| 10 | |||||||||||
| 11 | 86 | ▶ | sub validate_args { | ||||||||
|
Subroutine
validate_args: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||
| 12 | 86 | my ( $self, $opt, $args ) = @_; | |||||||||
| 13 | 86 | ▶ | if ( $opt->{help} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 0 | my ($command) = $self->command_names; | |||||||||
| 15 | 0 | $self->app->execute_command( $self->app->prepare_command( "help", $command ) ); | |||||||||
| 16 | 0 | exit; | |||||||||
| 17 | } | ||||||||||
| 18 | 86 | $self->validate( $opt, $args ); | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | =head1 NAME | ||||||||||
| 22 | |||||||||||
| 23 | Algorithm::Classifier::IsolationForest::App::Command - base class for the iforest subcommands | ||||||||||
| 24 | |||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||
| 26 | |||||||||||
| 27 | Every C<iforest> subcommand inherits from this. L<App::Cmd> finds it by | ||||||||||
| 28 | name alone -- L<Algorithm::Classifier::IsolationForest::App>'s C<-app> | ||||||||||
| 29 | setup looks for C<< <app class>::Command >> -- so the command modules | ||||||||||
| 30 | never mention it. | ||||||||||
| 31 | |||||||||||
| 32 | It earns its keep through L</validate_args>, which makes C<-h> print a | ||||||||||
| 33 | command's help instead of being validated like any other flag. | ||||||||||
| 34 | |||||||||||
| 35 | =head1 METHODS | ||||||||||
| 36 | |||||||||||
| 37 | =head2 global_opt_spec | ||||||||||
| 38 | |||||||||||
| 39 | Option-spec hook delegating to an C<options> method on the command, | ||||||||||
| 40 | taking the L<App::Cmd> application object and returning whatever that | ||||||||||
| 41 | method returns. | ||||||||||
| 42 | |||||||||||
| 43 | Nothing reaches this in practice: App::Cmd calls C<global_opt_spec> on | ||||||||||
| 44 | the application class rather than on the command base, and no command | ||||||||||
| 45 | here defines C<options> -- they all use App::Cmd's own C<opt_spec>. | ||||||||||
| 46 | Calling it would die on the missing method. | ||||||||||
| 47 | |||||||||||
| 48 | =head2 validate_args | ||||||||||
| 49 | |||||||||||
| 50 | App::Cmd's per-command validation hook, wrapped so C<-h> short-circuits | ||||||||||
| 51 | it. Without this, C<-h> would fall through to the command's own | ||||||||||
| 52 | C<validate> and trip over whatever required options the user has not | ||||||||||
| 53 | typed yet -- which is exactly the moment they are reaching for the help. | ||||||||||
| 54 | |||||||||||
| 55 | Takes the parsed options hashref and the arrayref of remaining | ||||||||||
| 56 | arguments, and returns whatever the command's C<validate> returns. Under | ||||||||||
| 57 | C<-h> it does not return at all: the help command runs and the process | ||||||||||
| 58 | exits. | ||||||||||
| 59 | |||||||||||
| 60 | iforest predict -h # prints predict's help, exits | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||
| 63 | |||||||||||
| 64 | 86 | return 1; | |||||||||