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