| 1 | package MooX::Options::Descriptive::Usage; | ||||||||||||||||||||||||||||
| 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 | =head1 NAME | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | MooX::Options::Descriptive::Usage - Usage class | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Usage class to display the error message. | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | This class use the full size of your terminal | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | ## no critic (ProhibitExcessComplexity) | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 22 | our $VERSION = "4.099_003"; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 22 | ▶ | use Getopt::Long::Descriptive; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 22 | ▶ | use Module::Runtime qw(use_module); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 22 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 22 | ▶ | use Text::LineFold (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 22 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 22 | with "MooX::Locale::Passthrough"; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 22 | has format_doc => ( is => "lazy" ); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | ## no critic (Subroutines::RequireFinalReturn, Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub _build_format_doc { | ||||||||||||||||||||||||||||
| 35 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_format_doc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 17 | +{ 's' => $self->__("String"), | |||||||||||||||||||||||||||
| 37 | 's@' => $self->__("[Strings]"), | ||||||||||||||||||||||||||||
| 38 | 'i' => $self->__("Int"), | ||||||||||||||||||||||||||||
| 39 | 'i@' => $self->__("[Ints]"), | ||||||||||||||||||||||||||||
| 40 | 'o' => $self->__("Ext. Int"), | ||||||||||||||||||||||||||||
| 41 | 'o@' => $self->__("[Ext. Ints]"), | ||||||||||||||||||||||||||||
| 42 | 'f' => $self->__("Real"), | ||||||||||||||||||||||||||||
| 43 | 'f@' => $self->__("[Reals]"), | ||||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 22 | has format_doc_long => ( is => "lazy" ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub _build_format_doc_long { | ||||||||||||||||||||||||||||
| 50 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_format_doc_long: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 3 | +{ 's' => $self->__("String"), | |||||||||||||||||||||||||||
| 52 | 's@' => $self->__("Array of Strings"), | ||||||||||||||||||||||||||||
| 53 | 'i' => $self->__("Integer"), | ||||||||||||||||||||||||||||
| 54 | 'i@' => $self->__("Array of Integers"), | ||||||||||||||||||||||||||||
| 55 | 'o' => $self->__("Extended Integer"), | ||||||||||||||||||||||||||||
| 56 | 'o@' => $self->__("Array of extended integers"), | ||||||||||||||||||||||||||||
| 57 | 'f' => $self->__("Real number"), | ||||||||||||||||||||||||||||
| 58 | 'f@' => $self->__("Array of real numbers"), | ||||||||||||||||||||||||||||
| 59 | }; | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Following attributes are present and behave as GLD::Usage describe them. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head2 leader_text | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Text that appear on top of your message | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head2 options | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | The options spec of your message | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 22 | has leader_text => ( is => "ro" ); | |||||||||||||||||||||||||||
| 77 | 22 | has options => ( is => "ro" ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 METHODS | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =head2 sub_commands_text | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Return the list of sub commands if available. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =cut | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | sub sub_commands_text { | ||||||||||||||||||||||||||||
| 88 | 91 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sub_commands_text: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 91 | my $sub_commands = []; | |||||||||||||||||||||||||||
| 90 | 91 | ▶ | if (defined $self->{target} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"target"} and defined(my $sub_commands_options = $self->{"target"}->_options_sub_commands)
MC/DC0%0/2
defined $self->{"target"} and defined(my $sub_commands_options = $self->{"target"}->_options_sub_commands)
defined $self->{"target"}
defined(my $sub_commands_options = $self->{"target"}->_options_sub_commands)
Truth table33%1/3
A and B
A= defined $self->{"target"}B= defined(my $sub_commands_options = $self->{"target"}->_options_sub_commands)
| |||||||||||||||||||||||||||||
| 91 | && defined( | ||||||||||||||||||||||||||||
| 92 | my $sub_commands_options = $self->{target}->_options_sub_commands | ||||||||||||||||||||||||||||
| 93 | ) | ||||||||||||||||||||||||||||
| 94 | ) | ||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||
| 96 | 0 | $sub_commands = $sub_commands_options; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 91 | ▶ | return if !@$sub_commands; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | return "", | ||||||||||||||||||||||||||||
| 100 | $self->__("SUB COMMANDS AVAILABLE: ") | ||||||||||||||||||||||||||||
| 101 | 0 | . join( ', ', map { $_->{name} } @$sub_commands ), ""; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head2 text | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Return a compact help message. | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub text { | ||||||||||||||||||||||||||||
| 111 | 81 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | my %options_data | ||||||||||||||||||||||||||||
| 113 | 81 | ▶ | = defined $self->{target} ? $self->{target}->_options_data : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | my %options_config | ||||||||||||||||||||||||||||
| 115 | = defined $self->{target} | ||||||||||||||||||||||||||||
| 116 | ? $self->{target}->_options_config | ||||||||||||||||||||||||||||
| 117 | 81 | ▶ | : ( spacer => " " ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 81 | my $getopt_options = $self->options; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 81 | my $lf = _get_line_fold(); | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 81 | my @to_fold; | |||||||||||||||||||||||||||
| 123 | 81 | my $max_spec_length = 0; | |||||||||||||||||||||||||||
| 124 | 81 | for my $opt (@$getopt_options) { | |||||||||||||||||||||||||||
| 125 | 529 | ▶ | if ( $opt->{desc} eq 'spacer' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 83 | push @to_fold, ''; | |||||||||||||||||||||||||||
| 127 | push @to_fold, | ||||||||||||||||||||||||||||
| 128 | 83 | $options_config{spacer} x ( $lf->config('ColMax') - 4 ); | |||||||||||||||||||||||||||
| 129 | 83 | next; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 446 | my ( $short, $format ) = $opt->{spec} =~ /(?:\|(\w))?(?:=(.*?))?$/x; | |||||||||||||||||||||||||||
| 132 | 446 | my $format_doc_str; | |||||||||||||||||||||||||||
| 133 | 446 | ▶ | $format_doc_str = $self->format_doc->{$format} if defined $format; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | $format_doc_str = 'JSON' | ||||||||||||||||||||||||||||
| 135 | 446 | ▶ | if defined $options_data{ $opt->{name} }{json}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | my $spec | ||||||||||||||||||||||||||||
| 138 | = ( defined $short ? "-" . $short . " " : "" ) . "-" | ||||||||||||||||||||||||||||
| 139 | . ( length( $opt->{name} ) > 1 ? "-" : "" ) | ||||||||||||||||||||||||||||
| 140 | . $opt->{name} | ||||||||||||||||||||||||||||
| 141 | 446 | ▶ | . ( defined $format_doc_str ? "=" . $format_doc_str : "" ); | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 446 | ▶ | $max_spec_length = length($spec) if $max_spec_length < length($spec); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 446 | push @to_fold, $spec, $opt->{desc}; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 81 | my @message; | |||||||||||||||||||||||||||
| 149 | 81 | ▶ | while (@to_fold) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 529 | my $spec = shift @to_fold; | |||||||||||||||||||||||||||
| 151 | 529 | my $desc = shift @to_fold; | |||||||||||||||||||||||||||
| 152 | 529 | ▶ | if ( length($spec) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 446 | push @message, | |||||||||||||||||||||||||||
| 154 | $lf->fold( | ||||||||||||||||||||||||||||
| 155 | " ", | ||||||||||||||||||||||||||||
| 156 | " " x ( 6 + $max_spec_length ), | ||||||||||||||||||||||||||||
| 157 | sprintf( | ||||||||||||||||||||||||||||
| 158 | "%-" . ( $max_spec_length + 1 ) . "s %s", | ||||||||||||||||||||||||||||
| 159 | $spec, $desc | ||||||||||||||||||||||||||||
| 160 | ) | ||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | else { | ||||||||||||||||||||||||||||
| 164 | 83 | push @message, $desc, "\n"; | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 81 | return join( "\n", | |||||||||||||||||||||||||||
| 169 | $self->leader_text, "", join( "", @message ), | ||||||||||||||||||||||||||||
| 170 | $self->sub_commands_text ); | ||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | # set the column size of your terminal into the wrapper | ||||||||||||||||||||||||||||
| 174 | sub _get_line_fold { | ||||||||||||||||||||||||||||
| 175 | my $columns = $ENV{TEST_FORCE_COLUMN_SIZE} | ||||||||||||||||||||||||||||
| 176 | 91 | ▶ | || eval { | ||||||||||||||||||||||||||
|
Subroutine
_get_line_fold: called CC=3 SCAR=11.3
Condition80%4/5
$ENV{'TEST_FORCE_COLUMN_SIZE'} || eval {
do {
&use_module('Term::Size::Any');
[Term::Size::Any::chars()]->[0]
}
} || 80
$ENV{"TEST_FORCE_COLUMN_SIZE"} or eval {
do {
&use_module("Term::Size::Any");
[Term::Size::Any::chars()]->[0]
}
}
MC/DC50%1/2
$ENV{'TEST_FORCE_COLUMN_SIZE'} || eval {
do {
&use_module('Term::Size::Any');
[Term::Size::Any::chars()]->[0]
}
} || 80
$ENV{"TEST_FORCE_COLUMN_SIZE"}
eval {
do {
&use_module("Term::Size::Any");
[Term::Size::Any::chars()]->[0]
}
}
Truth table66%2/3
A or B
A= $ENV{"TEST_FORCE_COLUMN_SIZE"}B= eval {
do {
&use_module("Term::Size::Any");
[Term::Size::Any::chars()]->[0]
}
}
| |||||||||||||||||||||||||||||
| 177 | 12 | use_module("Term::Size::Any"); | |||||||||||||||||||||||||||
| 178 | 0 | [ Term::Size::Any::chars() ]->[0]; | |||||||||||||||||||||||||||
| 179 | } || 80; | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 91 | return Text::LineFold->new( ColMax => $columns - 4 ); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head2 option_help | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Return the help message for your options | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | sub option_help { | ||||||||||||||||||||||||||||
| 191 | 10 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
option_help: called CC=12 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||
| 192 | my %options_data | ||||||||||||||||||||||||||||
| 193 | 10 | ▶ | = defined $self->{target} ? $self->{target}->_options_data : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | my %options_config | ||||||||||||||||||||||||||||
| 195 | = defined $self->{target} | ||||||||||||||||||||||||||||
| 196 | ? $self->{target}->_options_config | ||||||||||||||||||||||||||||
| 197 | 10 | ▶ | : ( spacer => " " ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 10 | my $getopt_options = $self->options; | |||||||||||||||||||||||||||
| 199 | 10 | my @message; | |||||||||||||||||||||||||||
| 200 | 10 | my $lf = _get_line_fold(); | |||||||||||||||||||||||||||
| 201 | 10 | for my $opt (@$getopt_options) { | |||||||||||||||||||||||||||
| 202 | 64 | ▶ | if ( $opt->{desc} eq 'spacer' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | push @message, | ||||||||||||||||||||||||||||
| 204 | 12 | $options_config{spacer} x ( $lf->config('ColMax') - 4 ); | |||||||||||||||||||||||||||
| 205 | 12 | push @message, ""; | |||||||||||||||||||||||||||
| 206 | 12 | next; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | 52 | my ( $short, $format ) = $opt->{spec} =~ /(?:\|(\w))?(?:=(.*?))?$/x; | |||||||||||||||||||||||||||
| 209 | 52 | my $format_doc_str; | |||||||||||||||||||||||||||
| 210 | 52 | ▶ | $format_doc_str = $self->format_doc->{$format} if defined $format; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | $format_doc_str = 'JSON' | ||||||||||||||||||||||||||||
| 212 | 52 | ▶ | if defined $options_data{ $opt->{name} }{json}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | push @message, | ||||||||||||||||||||||||||||
| 214 | ( defined $short ? "-" . $short . " " : "" ) . "-" | ||||||||||||||||||||||||||||
| 215 | . ( length( $opt->{name} ) > 1 ? "-" : "" ) | ||||||||||||||||||||||||||||
| 216 | 52 | ▶ | . $opt->{name} . ":" | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 217 | . ( defined $format_doc_str ? " " . $format_doc_str : "" ); | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 52 | my $opt_data = $options_data{ $opt->{name} }; | |||||||||||||||||||||||||||
| 220 | 52 | ▶ | $opt_data = {} if !defined $opt_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | push @message, | ||||||||||||||||||||||||||||
| 222 | $lf->fold( | ||||||||||||||||||||||||||||
| 223 | " ", | ||||||||||||||||||||||||||||
| 224 | " ", | ||||||||||||||||||||||||||||
| 225 | defined $opt_data->{long_doc} | ||||||||||||||||||||||||||||
| 226 | ? $self->__( $opt_data->{long_doc} ) | ||||||||||||||||||||||||||||
| 227 | : $self->__( $opt->{desc} ) | ||||||||||||||||||||||||||||
| 228 | 52 | ▶ | ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 10 | return join( "\n", | |||||||||||||||||||||||||||
| 232 | $self->leader_text, join( "\n ", "", @message ), | ||||||||||||||||||||||||||||
| 233 | $self->sub_commands_text ); | ||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =head2 option_pod | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | Return the usage message in pod format | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =cut | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | sub option_pod { | ||||||||||||||||||||||||||||
| 243 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
option_pod: called CC=25 SCAR=41.0
Pod
documented
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | my %options_data | ||||||||||||||||||||||||||||
| 246 | 3 | ▶ | = defined $self->{target} ? $self->{target}->_options_data : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | my %options_config | ||||||||||||||||||||||||||||
| 248 | = defined $self->{target} | ||||||||||||||||||||||||||||
| 249 | ? $self->{target}->_options_config | ||||||||||||||||||||||||||||
| 250 | 3 | ▶ | : ( spacer => " " ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 3 | my $prog_name = $self->{prog_name}; | |||||||||||||||||||||||||||
| 253 | 3 | ▶ | $prog_name = Getopt::Long::Descriptive::prog_name if !defined $prog_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 3 | my $sub_commands = []; | |||||||||||||||||||||||||||
| 256 | 3 | ▶ | if (defined $self->{target} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"target"} and defined(my $sub_commands_options = $self->{"target"}->_options_sub_commands)
MC/DC0%0/2
defined $self->{"target"} and defined(my $sub_commands_options = $self->{"target"}->_options_sub_commands)
defined $self->{"target"}
defined(my $sub_commands_options = $self->{"target"}->_options_sub_commands)
Truth table33%1/3
A and B
A= defined $self->{"target"}B= defined(my $sub_commands_options = $self->{"target"}->_options_sub_commands)
| |||||||||||||||||||||||||||||
| 257 | && defined( | ||||||||||||||||||||||||||||
| 258 | my $sub_commands_options | ||||||||||||||||||||||||||||
| 259 | = $self->{target}->_options_sub_commands() | ||||||||||||||||||||||||||||
| 260 | ) | ||||||||||||||||||||||||||||
| 261 | ) | ||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||
| 263 | 0 | $sub_commands = $sub_commands_options; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 3 | my @man = ( "=encoding UTF-8", "=head1 NAME", $prog_name, ); | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 3 | ▶ | if ( defined( my $description = $options_config{description} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 0 | push @man, "=head1 DESCRIPTION", $description; | |||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 3 | push @man, | |||||||||||||||||||||||||||
| 273 | ( | ||||||||||||||||||||||||||||
| 274 | "=head1 SYNOPSIS", | ||||||||||||||||||||||||||||
| 275 | $prog_name . " [-h] [" . $self->__("long options ...") . "]" | ||||||||||||||||||||||||||||
| 276 | ); | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 3 | ▶ | if ( defined( my $synopsis = $options_config{synopsis} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | 0 | push @man, $synopsis; | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 3 | push @man, ( "=head1 OPTIONS", "=over" ); | |||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 3 | my $spacer_escape = "E<" . ord( $options_config{spacer} ) . ">"; | |||||||||||||||||||||||||||
| 285 | 3 | for my $opt ( @{ $self->options } ) { | |||||||||||||||||||||||||||
| 286 | 18 | ▶ | if ( $opt->{desc} eq 'spacer' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 3 | push @man, "=back"; | |||||||||||||||||||||||||||
| 288 | 3 | push @man, $spacer_escape x 40; | |||||||||||||||||||||||||||
| 289 | 3 | push @man, "=over"; | |||||||||||||||||||||||||||
| 290 | 3 | next; | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | 15 | my ( $short, $format ) = $opt->{spec} =~ /(?:\|(\w))?(?:=(.*?))?$/x; | |||||||||||||||||||||||||||
| 293 | 15 | my $format_doc_str; | |||||||||||||||||||||||||||
| 294 | 15 | ▶ | $format_doc_str = $self->format_doc_long->{$format} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | if defined $format; | ||||||||||||||||||||||||||||
| 296 | $format_doc_str = 'JSON' | ||||||||||||||||||||||||||||
| 297 | 15 | ▶ | if defined $options_data{ $opt->{name} }{json}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | my $opt_long_name | ||||||||||||||||||||||||||||
| 300 | 15 | ▶ | = "-" . ( length( $opt->{name} ) > 1 ? "-" : "" ) . $opt->{name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 15 | ▶ | my $opt_name | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 302 | = ( defined $short ? "-" . $short . " " : "" ) | ||||||||||||||||||||||||||||
| 303 | . $opt_long_name . ":" | ||||||||||||||||||||||||||||
| 304 | . ( defined $format_doc_str ? " " . $format_doc_str : "" ); | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 15 | push @man, "=item B<" . $opt_name . ">"; | |||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 15 | my $opt_data = $options_data{ $opt->{name} }; | |||||||||||||||||||||||||||
| 309 | 15 | ▶ | $opt_data = {} if !defined $opt_data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | push @man, defined $opt_data->{long_doc} | ||||||||||||||||||||||||||||
| 311 | ? $opt_data->{long_doc} | ||||||||||||||||||||||||||||
| 312 | 15 | ▶ | : $opt->{desc}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | 3 | push @man, "=back"; | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 3 | ▶ | if (@$sub_commands) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 0 | push @man, "=head1 AVAILABLE SUB COMMANDS"; | |||||||||||||||||||||||||||
| 318 | 0 | push @man, "=over"; | |||||||||||||||||||||||||||
| 319 | 0 | for my $sub_command (@$sub_commands) { | |||||||||||||||||||||||||||
| 320 | 0 | ▶ | if ($sub_command->{command}->can("_options_config") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sub_command->{"command"}->can("_options_config") and defined(my $desc = {$sub_command->{"command"}->_options_config}->{"description"})
MC/DC0%0/2
$sub_command->{"command"}->can("_options_config") and defined(my $desc = {$sub_command->{"command"}->_options_config}->{"description"})
$sub_command->{"command"}->can("_options_config")
defined(my $desc = {$sub_command->{"command"}->_options_config}->{"description"})
Truth table0%0/3
A and B
A= $sub_command->{"command"}->can("_options_config")B= defined(my $desc = {$sub_command->{"command"}->_options_config}->{"description"})
| |||||||||||||||||||||||||||||
| 321 | && defined( | ||||||||||||||||||||||||||||
| 322 | my $desc | ||||||||||||||||||||||||||||
| 323 | = { $sub_command->{command}->_options_config } | ||||||||||||||||||||||||||||
| 324 | ->{description} | ||||||||||||||||||||||||||||
| 325 | ) | ||||||||||||||||||||||||||||
| 326 | ) | ||||||||||||||||||||||||||||
| 327 | { | ||||||||||||||||||||||||||||
| 328 | 0 | push @man, "=item B<" . $sub_command->{name} . "> : " . $desc; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | else { | ||||||||||||||||||||||||||||
| 331 | 0 | push @man, "=item B<" . $sub_command->{name} . "> :"; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | push @man, | ||||||||||||||||||||||||||||
| 335 | $prog_name . " " | ||||||||||||||||||||||||||||
| 336 | . $sub_command->{name} | ||||||||||||||||||||||||||||
| 337 | 0 | . " [-h] [" | |||||||||||||||||||||||||||
| 338 | . $self->__("long options ...") . "]"; | ||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | 0 | push @man, "=back"; | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 3 | ▶ | if ( defined( my $authors = $options_config{authors} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 3 | ▶ | if ( !ref $authors && length($authors) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $authors and length $authors
MC/DC0%0/2
not ref $authors and length $authors
not ref $authors
length $authors
Truth table33%1/3
not(A) and B
A= not ref $authorsB= length $authors
| |||||||||||||||||||||||||||||
| 345 | 0 | $authors = [$authors]; | |||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | 3 | ▶ | if (@$authors) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 0 | push @man, ( "=head1 AUTHORS", "=over" ); | |||||||||||||||||||||||||||
| 349 | 0 | push @man, map { "=item B<" . $_ . ">" } @$authors; | |||||||||||||||||||||||||||
| 350 | 0 | push @man, "=back"; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 3 | return join( "\n\n", @man ); | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | =head2 option_short_usage | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | All options message without help | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | =cut | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | sub option_short_usage { | ||||||||||||||||||||||||||||
| 364 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
option_short_usage: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||
| 365 | my %options_data | ||||||||||||||||||||||||||||
| 366 | 2 | ▶ | = defined $self->{target} ? $self->{target}->_options_data : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 2 | my $getopt_options = $self->options; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 2 | my $prog_name = $self->{prog_name}; | |||||||||||||||||||||||||||
| 370 | 2 | ▶ | $prog_name = Getopt::Long::Descriptive::prog_name if !defined $prog_name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 2 | my @message; | |||||||||||||||||||||||||||
| 373 | 2 | for my $opt (@$getopt_options) { | |||||||||||||||||||||||||||
| 374 | 14 | ▶ | if ( $opt->{desc} eq 'spacer' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 2 | push @message, ''; | |||||||||||||||||||||||||||
| 376 | 2 | next; | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | 12 | my ($format) = $opt->{spec} =~ /(?:\|\w)?(?:=(.*?))?$/x; | |||||||||||||||||||||||||||
| 379 | 12 | my $format_doc_str; | |||||||||||||||||||||||||||
| 380 | 12 | ▶ | $format_doc_str = $self->format_doc->{$format} if defined $format; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | $format_doc_str = 'JSON' | ||||||||||||||||||||||||||||
| 382 | 12 | ▶ | if defined $options_data{ $opt->{name} }{json}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | push @message, | ||||||||||||||||||||||||||||
| 384 | "-" | ||||||||||||||||||||||||||||
| 385 | . ( length( $opt->{name} ) > 1 ? "-" : "" ) | ||||||||||||||||||||||||||||
| 386 | . $opt->{name} | ||||||||||||||||||||||||||||
| 387 | 12 | ▶ | . ( defined $format_doc_str ? "=" . $format_doc_str : "" ); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | return | ||||||||||||||||||||||||||||
| 390 | 2 | ▶ | join( " ", $prog_name, map { $_ eq '' ? " | " : "[ $_ ]" } @message ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | =head2 warn | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | Warn your options help message | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | =cut | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 0 | ▶ | sub warn { return CORE::warn shift->text } | ||||||||||||||||||||||||||
|
Subroutine
warn: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | =head2 die | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | Croak your options help message | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | =cut | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | sub die { | ||||||||||||||||||||||||||||
| 408 | 9 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
die: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 409 | 9 | $self->{should_die} = 1; | |||||||||||||||||||||||||||
| 410 | 9 | return; | |||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | use overload ( | ||||||||||||||||||||||||||||
| 414 | q{""} => "text", | ||||||||||||||||||||||||||||
| 415 | '&{}' => sub { | ||||||||||||||||||||||||||||
| 416 | return | ||||||||||||||||||||||||||||
| 417 | 0 | ▶ | sub { my ($self) = @_; return $self ? $self->text : $self->warn; }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | 22 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | perldoc MooX::Options | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | You can also look for information at: | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | =over 4 | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooX-Options> | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | L<http://annocpan.org/dist/MooX-Options> | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | L<http://cpanratings.perl.org/d/MooX-Options> | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | L<http://search.cpan.org/dist/MooX-Options/> | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | =back | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | celogeek <me@celogeek.com> | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | This software is copyright (c) 2013 by celogeek <me@celogeek.com>. | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | This software is copyright (c) 2017 by Jens Rehsack. | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | =cut | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 22 | 1; | |||||||||||||||||||||||||||