| 1 | package MooX::Options::Role; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 22 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 22 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | ## no critic (ProhibitExcessComplexity) | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 22 | our $VERSION = "4.099_003"; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | MooX::Options::Role - role that is apply to your object | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 USAGE | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | Don't use MooX::Options::Role directly. It is used by L<MooX::Options> to upgrade your module. But it is useless alone. | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 22 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 22 | ▶ | use Module::Runtime qw(use_module); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 22 | ▶ | use MooX::Options::Descriptive; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 22 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ### PRIVATE | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub _option_name { | ||||||||||||||||||||||||||||
| 28 | 357 | ▶ | my ( $name, %data ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_option_name: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 29 | 357 | my $cmdline_name = join( '|', grep {defined} ( $name, $data{short} ) ); | |||||||||||||||||||||||||||
| 30 | ## no critic (RegularExpressions::RequireExtendedFormatting) | ||||||||||||||||||||||||||||
| 31 | 357 | ▶ | $cmdline_name =~ m/[^\w]$/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | and croak | ||||||||||||||||||||||||||||
| 33 | "cmdline argument '$cmdline_name' should end with a word character"; | ||||||||||||||||||||||||||||
| 34 | 356 | ▶ | $cmdline_name .= '+' if $data{repeatable} && !defined $data{format}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data{"repeatable"} and not defined $data{"format"}
MC/DC100%2/2
$data{"repeatable"} and not defined $data{"format"}
$data{"repeatable"}
not defined $data{"format"}
Truth table100%3/3
A and not(B)
A= $data{"repeatable"}B= not defined $data{"format"}
| |||||||||||||||||||||||||||||
| 35 | 356 | ▶ | $cmdline_name .= '!' if $data{negativable}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 356 | ▶ | $cmdline_name .= '!' if $data{negatable}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 356 | ▶ | $cmdline_name .= '=' . $data{format} if defined $data{format}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 356 | return $cmdline_name; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub _options_prepare_descriptive { | ||||||||||||||||||||||||||||
| 42 | 153 | ▶ | my ($options_data) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_options_prepare_descriptive: called CC=17 SCAR=28.3
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 153 | my @options; | |||||||||||||||||||||||||||
| 45 | my %all_options; | ||||||||||||||||||||||||||||
| 46 | 153 | my %has_to_split; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 153 | my $data_record_loaded = 0; | |||||||||||||||||||||||||||
| 49 | 153 | for my $name ( | |||||||||||||||||||||||||||
| 50 | sort { | ||||||||||||||||||||||||||||
| 51 | $options_data->{$a}{order} | ||||||||||||||||||||||||||||
| 52 | <=> $options_data->{$b}{order} # sort by order | ||||||||||||||||||||||||||||
| 53 | 404 | ▶ | or $a cmp $b # sort by attr name | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | } keys %$options_data | ||||||||||||||||||||||||||||
| 55 | ) | ||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 357 | my %data = %{ $options_data->{$name} }; | |||||||||||||||||||||||||||
| 58 | 357 | my $doc = $data{doc}; | |||||||||||||||||||||||||||
| 59 | 357 | ▶ | $doc = "no doc for $name" if !defined $doc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 357 | my $option = {}; | |||||||||||||||||||||||||||
| 61 | 357 | ▶ | $option->{hidden} = 1 if $data{hidden}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 357 | ▶ | push @options, [] if $data{spacer_before}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 357 | push @options, [ _option_name( $name, %data ), $doc, $option ]; | |||||||||||||||||||||||||||
| 65 | 356 | ▶ | push @options, [] if $data{spacer_after}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 356 | push @{ $all_options{$name} }, $name; | |||||||||||||||||||||||||||
| 68 | croak | ||||||||||||||||||||||||||||
| 69 | "There is already an option '$data{short}' - can't use it to shorten '$name'" | ||||||||||||||||||||||||||||
| 70 | 356 | ▶ | if $data{short} and exists $options_data->{ $data{short} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data{"short"} and exists $$options_data{$data{"short"}}
MC/DC100%2/2
$data{"short"} and exists $$options_data{$data{"short"}}
$data{"short"}
exists $$options_data{$data{"short"}}
Truth table100%3/3
A and B
A= $data{"short"}B= exists $$options_data{$data{"short"}}
| |||||||||||||||||||||||||||||
| 71 | croak | ||||||||||||||||||||||||||||
| 72 | "There is already an abbreviation '$data{short}' - can't use it to shorten '$name'" | ||||||||||||||||||||||||||||
| 73 | 355 | ▶ | if $data{short} and defined $all_options{ $data{short} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data{"short"} and defined $all_options{$data{"short"}}
MC/DC100%2/2
$data{"short"} and defined $all_options{$data{"short"}}
$data{"short"}
defined $all_options{$data{"short"}}
Truth table100%3/3
A and B
A= $data{"short"}B= defined $all_options{$data{"short"}}
| |||||||||||||||||||||||||||||
| 74 | 51 | push @{ $all_options{ $data{short} } }, $name | |||||||||||||||||||||||||||
| 75 | 354 | ▶ | if $data{short}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 354 | ▶ | for ( my $i = 1; $i <= length($name); $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 3105 | my $long_short = substr( $name, 0, $i ); | |||||||||||||||||||||||||||
| 79 | 1753 | push @{ $all_options{$long_short} }, $name | |||||||||||||||||||||||||||
| 80 | unless exists $options_data->{$long_short} | ||||||||||||||||||||||||||||
| 81 | 3105 | ▶ | or defined $all_options{$long_short}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $options_data->{$long_short} or defined $all_options{$long_short}
MC/DC100%2/2
exists $options_data->{$long_short} or defined $all_options{$long_short}
exists $options_data->{$long_short}
defined $all_options{$long_short}
Truth table100%3/3
A or B
A= exists $options_data->{$long_short}B= defined $all_options{$long_short}
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 354 | ▶ | if ( defined $data{autosplit} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 153 | ▶ | if ( !$data_record_loaded ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 64 | use_module("Data::Record"); | |||||||||||||||||||||||||||
| 87 | 64 | use_module("Regexp::Common"); | |||||||||||||||||||||||||||
| 88 | 64 | Regexp::Common->import; | |||||||||||||||||||||||||||
| 89 | 64 | $data_record_loaded = 1; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | $has_to_split{$name} = Data::Record->new( | ||||||||||||||||||||||||||||
| 92 | { split => $data{autosplit}, | ||||||||||||||||||||||||||||
| 93 | unless => $Regexp::Common::RE{quoted} | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 153 | ); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 150 | return \@options, \%has_to_split, \%all_options; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub _options_fix_argv { | ||||||||||||||||||||||||||||
| 103 | 150 | ▶ | my ( $option_data, $has_to_split, $all_options ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_options_fix_argv: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 150 | my @new_argv; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | #parse all argv | ||||||||||||||||||||||||||||
| 108 | 150 | ▶ | while ( defined( my $arg = shift @ARGV ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 161 | ▶ | if ( $arg eq '--' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 1 | push @new_argv, $arg, @ARGV; | |||||||||||||||||||||||||||
| 111 | 1 | last; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 160 | ▶ | if ( index( $arg, '-' ) != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 3 | push @new_argv, $arg; | |||||||||||||||||||||||||||
| 115 | 3 | next; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 157 | my ( $arg_name_with_dash, $arg_values ) = split( /=/x, $arg, 2 ); | |||||||||||||||||||||||||||
| 119 | 157 | ▶ | if ( index( $arg_name_with_dash, '--' ) < 0 && !defined $arg_values ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
index($arg_name_with_dash, "--") == -1 and not defined $arg_values
MC/DC100%2/2
index($arg_name_with_dash, "--") == -1 and not defined $arg_values
index($arg_name_with_dash, "--") == -1
not defined $arg_values
Truth table100%3/3
A and not(B)
A= index($arg_name_with_dash, "--") == -1B= not defined $arg_values
| |||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | 7 | ▶ | $arg_values | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | = length($arg_name_with_dash) > 2 | ||||||||||||||||||||||||||||
| 123 | ? substr( $arg_name_with_dash, 2 ) | ||||||||||||||||||||||||||||
| 124 | : undef; | ||||||||||||||||||||||||||||
| 125 | 7 | $arg_name_with_dash = substr( $arg_name_with_dash, 0, 2 ); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 157 | ▶ | unshift @ARGV, $arg_values if defined $arg_values; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 157 | my ( $dash, $negative, $arg_name_without_dash ) | |||||||||||||||||||||||||||
| 130 | = $arg_name_with_dash =~ /^(\-+)(no\-)?(.*)$/x; | ||||||||||||||||||||||||||||
| 131 | 157 | $arg_name_without_dash =~ s/\-/_/gx; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 157 | my $original_long_option = $all_options->{$arg_name_without_dash}; | |||||||||||||||||||||||||||
| 134 | 157 | ▶ | if ( defined $original_long_option ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | ## no critic (ErrorHandling::RequireCarping) | ||||||||||||||||||||||||||||
| 136 | # uncoverable branch false | ||||||||||||||||||||||||||||
| 137 | 146 | ▶ | @$original_long_option == 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | or die | ||||||||||||||||||||||||||||
| 139 | "Internal error, duplicate map for abbreviation detected!"; | ||||||||||||||||||||||||||||
| 140 | 146 | $original_long_option = $original_long_option->[0]; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 157 | my $arg_name = $dash; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 157 | ▶ | if ( defined $negative && defined $original_long_option ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $negative and defined $original_long_option
MC/DC50%1/2
defined $negative and defined $original_long_option
defined $negative
defined $original_long_option
Truth table66%2/3
A and B
A= defined $negativeB= defined $original_long_option
| |||||||||||||||||||||||||||||
| 146 | $arg_name .= | ||||||||||||||||||||||||||||
| 147 | $option_data->{$original_long_option}{negatable} | ||||||||||||||||||||||||||||
| 148 | 2 | ▶ | ? 'no-' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | : 'no_'; | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 157 | $arg_name .= $arg_name_without_dash; | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 157 | ▶ | if ( defined $original_long_option | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $original_long_option and defined(my $arg_value = shift @ARGV)
MC/DC100%2/2
defined $original_long_option and defined(my $arg_value = shift @ARGV)
defined $original_long_option
defined(my $arg_value = shift @ARGV)
Truth table100%3/3
A and B
A= defined $original_long_optionB= defined(my $arg_value = shift @ARGV)
| |||||||||||||||||||||||||||||
| 155 | && ( defined( my $arg_value = shift @ARGV ) ) ) | ||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||
| 157 | 140 | my $autorange = $option_data->{$original_long_option}{autorange}; | |||||||||||||||||||||||||||
| 158 | my $argv_processor = sub { | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | #remove the quoted if exist to chain | ||||||||||||||||||||||||||||
| 161 | 189 | ▶ | $_[0] =~ s/^['"]|['"]$//gx; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 162 | 189 | ▶ | if ($autorange) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | push @new_argv, | ||||||||||||||||||||||||||||
| 164 | 90 | map { $arg_name => $_ } _expand_autorange( $_[0] ); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | else { | ||||||||||||||||||||||||||||
| 167 | 99 | push @new_argv, $arg_name, $_[0]; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 140 | }; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 140 | ▶ | if ( my $rec = $has_to_split->{$original_long_option} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 106 | foreach my $record ( $rec->records($arg_value) ) { | |||||||||||||||||||||||||||
| 174 | 155 | $argv_processor->($record); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | else { | ||||||||||||||||||||||||||||
| 178 | 34 | $argv_processor->($arg_value); | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||
| 182 | 17 | push @new_argv, $arg_name; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 150 | return @new_argv; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | sub _expand_autorange { | ||||||||||||||||||||||||||||
| 190 | 90 | ▶ | my ($arg_value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_expand_autorange: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 90 | my @expanded_arg_value; | |||||||||||||||||||||||||||
| 193 | 90 | my ( $left_figure, $autorange_found, $right_figure ) | |||||||||||||||||||||||||||
| 194 | = $arg_value =~ /^(\d*)(\.\.)(\d*)$/x; | ||||||||||||||||||||||||||||
| 195 | 90 | ▶ | if ($autorange_found) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 31 | ▶ | $left_figure = $right_figure unless length($left_figure); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 31 | ▶ | $right_figure = $left_figure unless length($right_figure); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 31 | ▶ | if ( length $left_figure && length $right_figure ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $left_figure and length $right_figure
MC/DC50%1/2
length $left_figure and length $right_figure
length $left_figure
length $right_figure
Truth table66%2/3
A and B
A= length $left_figureB= length $right_figure
| |||||||||||||||||||||||||||||
| 199 | 29 | push @expanded_arg_value, $left_figure .. $right_figure; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 90 | ▶ | return @expanded_arg_value ? @expanded_arg_value : $arg_value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | ### PRIVATE | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 22 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 208 | 22 | with "MooX::Locale::Passthrough"; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 22 | requires qw/_options_data _options_config/; | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =head1 METHODS | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | These methods will be composed into your class | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | =head2 new_with_options | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | Same as new but parse ARGV with L<Getopt::Long::Descriptive> | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | Check full doc L<MooX::Options> for more details. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =cut | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | sub new_with_options { | ||||||||||||||||||||||||||||
| 225 | 126 | ▶ | my ( $class, %params ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new_with_options: called CC=12 SCAR=29.8
Pod
documented
| |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | #save subcommand | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 126 | ▶ | if ( ref( my $command_chain = $params{command_chain} ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | $class->can('around')->( | ||||||||||||||||||||||||||||
| 231 | _options_prog_name => sub { | ||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my $prog_name = Getopt::Long::Descriptive::prog_name; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 233 | 0 | for my $cmd (@$command_chain) { | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | next if !blessed $cmd || !$cmd->can('command_name'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($cmd) and $cmd->can("command_name")
MC/DC0%0/2
builtin::blessed($cmd) and $cmd->can("command_name")
builtin::blessed($cmd)
$cmd->can("command_name")
Truth table0%0/3
A and B
A= builtin::blessed($cmd)B= $cmd->can("command_name")
| |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ( defined( my $cmd_name = $cmd->command_name ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 0 | $prog_name .= ' ' . $cmd_name; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | return $prog_name; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | 0 | ); | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 126 | ▶ | if ( ref( my $command_commands = $params{command_commands} ) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | $class->can('around')->( | ||||||||||||||||||||||||||||
| 247 | _options_sub_commands => sub { | ||||||||||||||||||||||||||||
| 248 | return [ | ||||||||||||||||||||||||||||
| 249 | ## no critic (BuiltinFunctions::RequireBlockMap) | ||||||||||||||||||||||||||||
| 250 | map +{ | ||||||||||||||||||||||||||||
| 251 | name => $_, | ||||||||||||||||||||||||||||
| 252 | 0 | ▶ | command => $command_commands->{$_}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 253 | }, | ||||||||||||||||||||||||||||
| 254 | sort keys %$command_commands | ||||||||||||||||||||||||||||
| 255 | ]; | ||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | 0 | ); | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 126 | my %cmdline_params = $class->parse_options(%params); | |||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 112 | ▶ | if ( $cmdline_params{h} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 1 | return $class->options_usage( $params{h}, $cmdline_params{h} ); | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | 111 | ▶ | if ( $cmdline_params{help} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | 5 | return $class->options_help( $params{help}, $cmdline_params{help} ); | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | 106 | ▶ | if ( $cmdline_params{man} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 1 | return $class->options_man( $cmdline_params{man} ); | |||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | 105 | ▶ | if ( $cmdline_params{usage} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | return $class->options_short_usage( $params{usage}, | ||||||||||||||||||||||||||||
| 273 | 1 | $cmdline_params{usage} ); | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 104 | my $self; | |||||||||||||||||||||||||||
| 277 | return $self | ||||||||||||||||||||||||||||
| 278 | 104 | ▶ | if eval { $self = $class->new(%cmdline_params); 1 }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 4 | ▶ | if ( $@ =~ /^Attribute\s\((.*?)\)\sis\srequired/x ) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 280 | 0 | print STDERR "$1 is missing\n"; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | elsif ( $@ =~ /^Missing\srequired\sarguments:\s(.*)\sat\s/x ) { | ||||||||||||||||||||||||||||
| 283 | 2 | my @missing_required = split /,\s/x, $1; | |||||||||||||||||||||||||||
| 284 | print STDERR | ||||||||||||||||||||||||||||
| 285 | join( "\n", | ||||||||||||||||||||||||||||
| 286 | 2 | ( map { $_ . " is missing" } @missing_required ), '' ); | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | elsif ( $@ =~ /^(.*?)\srequired/x ) { | ||||||||||||||||||||||||||||
| 289 | 0 | print STDERR "$1 is missing\n"; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | elsif ( $@ =~ /^isa\scheck.*?failed:\s/x ) { | ||||||||||||||||||||||||||||
| 292 | 2 | print STDERR substr( $@, index( $@, ':' ) + 2 ); | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | else { | ||||||||||||||||||||||||||||
| 295 | 0 | print STDERR $@; | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | 4 | %cmdline_params = $class->parse_options( h => 1 ); | |||||||||||||||||||||||||||
| 298 | 4 | return $class->options_usage( 1, $cmdline_params{h} ); | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | =head2 parse_options | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | Parse your options, call L<Getopt::Long::Descriptive> and convert the result for the "new" method. | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | It is use by "new_with_options". | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 22 | my $decode_json; | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | sub parse_options { | ||||||||||||||||||||||||||||
| 312 | 153 | ▶ | my ( $class, %params ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse_options: called CC=23 SCAR=31.4
Pod
documented
| |||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 153 | my %options_data = $class->_options_data; | |||||||||||||||||||||||||||
| 315 | 153 | my %options_config = $class->_options_config; | |||||||||||||||||||||||||||
| 316 | 153 | ▶ | if ( defined $options_config{skip_options} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 150 | delete @options_data{ @{ $options_config{skip_options} } }; | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 153 | my ( $options, $has_to_split, $all_options ) | |||||||||||||||||||||||||||
| 321 | = _options_prepare_descriptive( \%options_data ); | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 150 | ▶ | local @ARGV = @ARGV if $options_config{protect_argv}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | 150 | @ARGV = _options_fix_argv( \%options_data, $has_to_split, $all_options ); | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 150 | my @flavour; | |||||||||||||||||||||||||||
| 327 | 150 | ▶ | if ( defined $options_config{flavour} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 147 | push @flavour, { getopt_conf => $options_config{flavour} }; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 150 | my $prog_name = $class->_options_prog_name(); | |||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | # create usage str | ||||||||||||||||||||||||||||
| 334 | 150 | my $usage_str = $options_config{usage_string}; | |||||||||||||||||||||||||||
| 335 | 150 | ▶ | $usage_str = sprintf( $class->__("USAGE: %s %s"), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | $prog_name, " [-h] [" . $class->__("long options ...") . "]" ) | ||||||||||||||||||||||||||||
| 337 | if !defined $usage_str; | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 150 | my ( $opt, $usage ) = describe_options( | |||||||||||||||||||||||||||
| 340 | ($usage_str), | ||||||||||||||||||||||||||||
| 341 | @$options, | ||||||||||||||||||||||||||||
| 342 | [], | ||||||||||||||||||||||||||||
| 343 | [ 'usage', $class->__("show a short help message") ], | ||||||||||||||||||||||||||||
| 344 | [ 'h', $class->__("show a compact help message") ], | ||||||||||||||||||||||||||||
| 345 | [ 'help', $class->__("show a long help message") ], | ||||||||||||||||||||||||||||
| 346 | [ 'man', $class->__("show the manual") ], | ||||||||||||||||||||||||||||
| 347 | , | ||||||||||||||||||||||||||||
| 348 | @flavour | ||||||||||||||||||||||||||||
| 349 | ); | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 150 | $usage->{prog_name} = $prog_name; | |||||||||||||||||||||||||||
| 352 | 150 | $usage->{target} = $class; | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 150 | ▶ | if ( $usage->{should_die} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | 9 | return $class->options_usage( 1, $usage ); | |||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 141 | my %cmdline_params = %params; | |||||||||||||||||||||||||||
| 359 | 141 | for my $name ( keys %options_data ) { | |||||||||||||||||||||||||||
| 360 | 335 | my %data = %{ $options_data{$name} }; | |||||||||||||||||||||||||||
| 361 | 335 | ▶ | if ( !defined $cmdline_params{$name} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $cmdline_params{$name} or $options_config{"prefer_commandline"}
MC/DC100%2/2
not defined $cmdline_params{$name} or $options_config{"prefer_commandline"}
not defined $cmdline_params{$name}
$options_config{"prefer_commandline"}
Truth table100%3/3
not(A) or B
A= not defined $cmdline_params{$name}B= $options_config{"prefer_commandline"}
| |||||||||||||||||||||||||||||
| 362 | || $options_config{prefer_commandline} ) | ||||||||||||||||||||||||||||
| 363 | { | ||||||||||||||||||||||||||||
| 364 | 332 | my $val = $opt->$name(); | |||||||||||||||||||||||||||
| 365 | 332 | ▶ | if ( defined $val ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 87 | ▶ | if ( $data{json} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | defined $decode_json | ||||||||||||||||||||||||||||
| 368 | 4 | ▶ | or $decode_json = eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 1 | use_module("JSON::MaybeXS"); | |||||||||||||||||||||||||||
| 370 | 1 | JSON::MaybeXS->can("decode_json"); | |||||||||||||||||||||||||||
| 371 | }; | ||||||||||||||||||||||||||||
| 372 | defined $decode_json | ||||||||||||||||||||||||||||
| 373 | 4 | ▶ | or $decode_json = eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | 0 | use_module("JSON::PP"); | |||||||||||||||||||||||||||
| 375 | 0 | JSON::PP->can("decode_json"); | |||||||||||||||||||||||||||
| 376 | }; | ||||||||||||||||||||||||||||
| 377 | ## no critic (ErrorHandling::RequireCarping) | ||||||||||||||||||||||||||||
| 378 | 4 | ▶ | $@ and die $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 4 | ▶ | if (!eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 380 | 4 | $cmdline_params{$name} = $decode_json->($val); | |||||||||||||||||||||||||||
| 381 | 2 | 1; | |||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | ) | ||||||||||||||||||||||||||||
| 384 | { | ||||||||||||||||||||||||||||
| 385 | 2 | print STDERR $@; | |||||||||||||||||||||||||||
| 386 | 2 | return $class->options_usage( 1, $usage ); | |||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | else { | ||||||||||||||||||||||||||||
| 390 | 83 | $cmdline_params{$name} = $val; | |||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 139 | ▶ | if ( $opt->h() || defined $params{h} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt->h or defined $params{"h"}
MC/DC50%1/2
$opt->h or defined $params{"h"}
$opt->h
defined $params{"h"}
Truth table66%2/3
A or B
A= $opt->hB= defined $params{"h"}
| |||||||||||||||||||||||||||||
| 397 | 5 | $cmdline_params{h} = $usage; | |||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 139 | ▶ | if ( $opt->help() || defined $params{help} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opt->help or defined $params{"help"}
MC/DC100%2/2
$opt->help or defined $params{"help"}
$opt->help
defined $params{"help"}
Truth table100%3/3
A or B
A= $opt->helpB= defined $params{"help"}
| |||||||||||||||||||||||||||||
| 401 | 26 | $cmdline_params{help} = $usage; | |||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 139 | ▶ | if ( $opt->man() || defined $params{man} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opt->man or defined $params{"man"}
MC/DC100%2/2
$opt->man or defined $params{"man"}
$opt->man
defined $params{"man"}
Truth table100%3/3
A or B
A= $opt->manB= defined $params{"man"}
| |||||||||||||||||||||||||||||
| 405 | 3 | $cmdline_params{man} = $usage; | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 139 | ▶ | if ( $opt->usage() || defined $params{usage} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt->usage or defined $params{"usage"}
MC/DC50%1/2
$opt->usage or defined $params{"usage"}
$opt->usage
defined $params{"usage"}
Truth table66%2/3
A or B
A= $opt->usageB= defined $params{"usage"}
| |||||||||||||||||||||||||||||
| 409 | 1 | $cmdline_params{usage} = $usage; | |||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 139 | return %cmdline_params; | |||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | =head2 options_usage | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | Display help message. | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | Check full doc L<MooX::Options> for more details. | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | =cut | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | sub options_usage { | ||||||||||||||||||||||||||||
| 424 | 31 | ▶ | my ( $class, $code, @messages ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
options_usage: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 425 | 31 | my $usage; | |||||||||||||||||||||||||||
| 426 | 31 | ▶ | if ( @messages | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@messages and ref $messages[-1] eq "MooX::Options::Descriptive::Usage"
MC/DC100%2/2
@messages and ref $messages[-1] eq "MooX::Options::Descriptive::Usage"
@messages
ref $messages[-1] eq "MooX::Options::Descriptive::Usage"
Truth table100%3/3
A and B
A= @messagesB= ref $messages[-1] eq "MooX::Options::Descriptive::Usage"
| |||||||||||||||||||||||||||||
| 427 | && ref $messages[-1] eq 'MooX::Options::Descriptive::Usage' ) | ||||||||||||||||||||||||||||
| 428 | { | ||||||||||||||||||||||||||||
| 429 | 16 | $usage = shift @messages; | |||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | 31 | ▶ | $code = 0 if !defined $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | 31 | ▶ | if ( !$usage ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | 15 | local @ARGV = (); | |||||||||||||||||||||||||||
| 434 | 15 | my %cmdline_params = $class->parse_options( help => $code ); | |||||||||||||||||||||||||||
| 435 | 15 | $usage = $cmdline_params{help}; | |||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | 31 | my $message = ""; | |||||||||||||||||||||||||||
| 438 | 31 | ▶ | $message .= join( "\n", @messages, '' ) if @messages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | 31 | $message .= $usage . "\n"; | |||||||||||||||||||||||||||
| 440 | 31 | ▶ | if ( $code > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 441 | 17 | CORE::warn $message; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | else { | ||||||||||||||||||||||||||||
| 444 | 14 | print $message; | |||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||
| 446 | 31 | ▶ | exit($code) if $code >= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | 1 | return; | |||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | =head2 options_help | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | Display long usage message | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | =cut | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | sub options_help { | ||||||||||||||||||||||||||||
| 457 | 10 | ▶ | my ( $class, $code, $usage ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
options_help: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 458 | 10 | ▶ | $code = 0 if !defined $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 10 | ▶ | if ( !defined $usage || !ref $usage ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $usage and ref $usage
MC/DC50%1/2
defined $usage and ref $usage
defined $usage
ref $usage
Truth table66%2/3
A and B
A= defined $usageB= ref $usage
| |||||||||||||||||||||||||||||
| 461 | 5 | local @ARGV = (); | |||||||||||||||||||||||||||
| 462 | 5 | my %cmdline_params = $class->parse_options( help => $code ); | |||||||||||||||||||||||||||
| 463 | 5 | $usage = $cmdline_params{help}; | |||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | 10 | my $message = $usage->option_help . "\n"; | |||||||||||||||||||||||||||
| 466 | 10 | ▶ | if ( $code > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | 0 | CORE::warn $message; | |||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | else { | ||||||||||||||||||||||||||||
| 470 | 10 | print $message; | |||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | 10 | ▶ | exit($code) if $code >= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 473 | 1 | return; | |||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | =head2 options_short_usage | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | Display quick usage message, with only the list of options | ||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | =cut | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | sub options_short_usage { | ||||||||||||||||||||||||||||
| 483 | 2 | ▶ | my ( $class, $code, $usage ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
options_short_usage: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 484 | 2 | ▶ | $code = 0 if !defined $code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 2 | ▶ | if ( !defined $usage || !ref $usage ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $usage and ref $usage
MC/DC50%1/2
defined $usage and ref $usage
defined $usage
ref $usage
Truth table66%2/3
A and B
A= defined $usageB= ref $usage
| |||||||||||||||||||||||||||||
| 487 | 1 | local @ARGV = (); | |||||||||||||||||||||||||||
| 488 | 1 | my %cmdline_params = $class->parse_options( help => $code ); | |||||||||||||||||||||||||||
| 489 | 1 | $usage = $cmdline_params{help}; | |||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||
| 491 | 2 | my $message = "USAGE: " . $usage->option_short_usage . "\n"; | |||||||||||||||||||||||||||
| 492 | 2 | ▶ | if ( $code > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 493 | 1 | CORE::warn $message; | |||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | else { | ||||||||||||||||||||||||||||
| 496 | 1 | print $message; | |||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | 2 | ▶ | exit($code) if $code >= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 499 | 0 | return; | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | =head2 options_man | ||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | Display a pod like a manual | ||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | =cut | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | sub options_man { | ||||||||||||||||||||||||||||
| 509 | 3 | ▶ | my ( $class, $usage, $output ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
options_man: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 510 | 3 | local @ARGV = (); | |||||||||||||||||||||||||||
| 511 | 3 | ▶ | if ( !$usage ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 512 | 2 | local @ARGV = (); | |||||||||||||||||||||||||||
| 513 | 2 | my %cmdline_params = $class->parse_options( man => 1 ); | |||||||||||||||||||||||||||
| 514 | 2 | $usage = $cmdline_params{man}; | |||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | 3 | use_module( "Path::Class", "0.32" ); | |||||||||||||||||||||||||||
| 518 | 3 | my $man_file | |||||||||||||||||||||||||||
| 519 | = Path::Class::file( Path::Class::tempdir( CLEANUP => 1 ), | ||||||||||||||||||||||||||||
| 520 | 'help.pod' ); | ||||||||||||||||||||||||||||
| 521 | 3 | $man_file->spew( iomode => '>:encoding(UTF-8)', $usage->option_pod ); | |||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | 3 | use_module("Pod::Usage"); | |||||||||||||||||||||||||||
| 524 | 3 | Pod::Usage::pod2usage( | |||||||||||||||||||||||||||
| 525 | -verbose => 2, | ||||||||||||||||||||||||||||
| 526 | -input => $man_file->stringify, | ||||||||||||||||||||||||||||
| 527 | -exitval => 'NOEXIT', | ||||||||||||||||||||||||||||
| 528 | -output => $output | ||||||||||||||||||||||||||||
| 529 | ); | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 3 | exit(0); | |||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | ### PRIVATE NEED TO BE EXPORTED | ||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | sub _options_prog_name { | ||||||||||||||||||||||||||||
| 537 | 150 | ▶ | return Getopt::Long::Descriptive::prog_name; | ||||||||||||||||||||||||||
|
Subroutine
_options_prog_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | sub _options_sub_commands { | ||||||||||||||||||||||||||||
| 541 | 94 | ▶ | return; | ||||||||||||||||||||||||||
|
Subroutine
_options_sub_commands: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | ### PRIVATE NEED TO BE EXPORTED | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | perldoc MooX::ConfigFromFile | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | You can also look for information at: | ||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | =over 4 | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooX-ConfigFromFile> | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | L<http://annocpan.org/dist/MooX-ConfigFromFile> | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | L<http://cpanratings.perl.org/d/MooX-ConfigFromFile> | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | L<http://search.cpan.org/dist/MooX-ConfigFromFile/> | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | =back | ||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | celogeek <me@celogeek.com> | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | This software is copyright (c) 2013 by celogeek <me@celogeek.com>. | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | This software is copyright (c) 2017 by Jens Rehsack. | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | =cut | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | 22 | 1; | |||||||||||||||||||||||||||