| 1 | package MooseX::Getopt::Usage::Formatter; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 44 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 44 | our $VERSION = '0.24'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 44 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | #use MooseX::StrictConstructor; | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 44 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 44 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 44 | ▶ | use Term::ReadKey; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 44 | ▶ | use Text::Wrap; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 44 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 44 | ▶ | use Pod::Select; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 44 | ▶ | use Pod::Find qw(pod_where contains_pod); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 44 | ▶ | use MooseX::Getopt::Usage::Pod::Text; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 44 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 44 | ▶ | use Module::Loaded; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 44 | ▶ | use FindBin; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 44 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | # Grab prog name before someone decides to change it. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 44 | my $prog_name; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 82 | ▶ | sub prog_name { @_ ? ($prog_name = shift) : $prog_name } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prog_name: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 44 | prog_name(File::Basename::basename($0)); | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # Util wrapper for pod select and its file based API | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 51 | ▶ | sub podselect_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
podselect_text: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 51 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 51 | my $selected = ""; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 51 | ▶ | open my $fh, ">", \$selected or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 51 | ▶ | if ( exists $args[0] and ref $args[0] eq "HASH" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $args[0] and ref $args[0] eq "HASH"
MC/DC50%1/2
exists $args[0] and ref $args[0] eq "HASH"
exists $args[0]
ref $args[0] eq "HASH"
Truth table66%2/3
A and B
A= exists $args[0]B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 18 | $args[0]->{'-output'} = $fh; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 33 | unshift @args, { '-output' => $fh }; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 51 | podselect @args; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 51 | return $selected; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # Types | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 44 | subtype 'PodSelectList', as 'ArrayRef[Str]'; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 44 | enum 'ColorUsage', [qw(auto never always env)]; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # Attributes | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 44 | has getopt_class => ( | |||||||||||||||||||||||||||||||||||||||||
| 54 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 55 | isa => "ClassName", | ||||||||||||||||||||||||||||||||||||||||||
| 56 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 44 | has pod_file => ( | |||||||||||||||||||||||||||||||||||||||||
| 60 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 61 | isa => "Undef|Str", | ||||||||||||||||||||||||||||||||||||||||||
| 62 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 42 | ▶ | sub _build_pod_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_pod_file: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 42 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # Script file, may have inline pod docs | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 42 | my $file = "$FindBin::Bin/$FindBin::Script"; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 42 | ▶ | return $file if -f $file && contains_pod($file); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $file and contains_pod($file)
MC/DC50%1/2
-f $file and contains_pod($file)
-f $file
contains_pod($file)
Truth table66%2/3
A and B
A= -f $fileB= contains_pod($file)
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # Use the pod docs from the class | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | my $gclass = $self->getopt_class; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 13 | ▶ | return pod_where( {-inc => 1}, $gclass ) if is_loaded($gclass); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | has colours => ( | ||||||||||||||||||||||||||||||||||||||||||
| 80 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 81 | isa => "HashRef", | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 44 | ▶ | default => sub { { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 44 | flag => ['yellow'], | |||||||||||||||||||||||||||||||||||||||||
| 84 | heading => ['bold'], | ||||||||||||||||||||||||||||||||||||||||||
| 85 | command => ['green'], | ||||||||||||||||||||||||||||||||||||||||||
| 86 | type => ['magenta'], | ||||||||||||||||||||||||||||||||||||||||||
| 87 | default_value => ['cyan'], | ||||||||||||||||||||||||||||||||||||||||||
| 88 | error => ['red'] | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } }, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 44 | ); | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 44 | has headings => ( | |||||||||||||||||||||||||||||||||||||||||
| 93 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 94 | isa => "Bool", | ||||||||||||||||||||||||||||||||||||||||||
| 95 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 44 | has groups => ( | |||||||||||||||||||||||||||||||||||||||||
| 99 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 100 | isa => "Undef|Bool", | ||||||||||||||||||||||||||||||||||||||||||
| 101 | default => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 44 | has format => ( | |||||||||||||||||||||||||||||||||||||||||
| 105 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 106 | isa => "Str", | ||||||||||||||||||||||||||||||||||||||||||
| 107 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 26 | ▶ | sub _build_format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_format: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 26 | my $pod_file = $self->pod_file; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 26 | my $sections = $self->format_sections; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 26 | my $selected = ""; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 26 | ▶ | if ( $pod_file ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 18 | $selected = podselect_text { -sections => $sections }, $pod_file; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 18 | $selected =~ s{^=head1.*?\n$}{}mg; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 18 | $selected =~ s{^.*?\n}{}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 18 | $selected =~ s{\n$}{}; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 26 | ▶ | return $selected ? $selected : "%c [OPTIONS]"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 44 | has width => ( | |||||||||||||||||||||||||||||||||||||||||
| 125 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 126 | isa => "Int", | ||||||||||||||||||||||||||||||||||||||||||
| 127 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 26 | ▶ | sub _build_width { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_width: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 26 | my $w = 72; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 26 | ▶ | if (-t STDOUT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my ($tw) = GetTerminalSize(); | |||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | $w = $tw -1 if defined $tw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 26 | return $w; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | has attr_sort => ( | ||||||||||||||||||||||||||||||||||||||||||
| 142 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 143 | isa => "CodeRef", | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 42 | ▶ | default => sub { sub {0} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 44 | ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 44 | has use_color => ( | |||||||||||||||||||||||||||||||||||||||||
| 148 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 149 | isa => "ColorUsage", | ||||||||||||||||||||||||||||||||||||||||||
| 150 | default => "auto", | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | has format_sections => ( | ||||||||||||||||||||||||||||||||||||||||||
| 154 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 155 | isa => "PodSelectList", | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 44 | ▶ | default => sub { ["SYNOPSIS"] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 44 | ); | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | has usage_sections => ( | ||||||||||||||||||||||||||||||||||||||||||
| 160 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 161 | isa => "PodSelectList", | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 37 | ▶ | default => sub { ["SYNOPSIS|OPTIONS"] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 44 | ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | has man_sections => ( | ||||||||||||||||||||||||||||||||||||||||||
| 166 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 167 | isa => "PodSelectList", | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 39 | ▶ | default => sub { ["!ATTRIBUTES|METHODS"] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 44 | ); | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 44 | has unexpand => ( | |||||||||||||||||||||||||||||||||||||||||
| 172 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 173 | isa => "Int", | ||||||||||||||||||||||||||||||||||||||||||
| 174 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 44 | has tabstop => ( | |||||||||||||||||||||||||||||||||||||||||
| 178 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 179 | isa => "Int", | ||||||||||||||||||||||||||||||||||||||||||
| 180 | default => 4, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | # | ||||||||||||||||||||||||||||||||||||||||||
| 184 | # Methods | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 40 | ▶ | sub _set_color_handling { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_color_handling: called CC=7 SCAR=20.0
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 40 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 40 | my $mode = shift; | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 40 | ▶ | $ENV{ANSI_COLORS_DISABLED} = defined $ENV{ANSI_COLORS_DISABLED} ? 1 : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 40 | ▶ | if ($mode eq 'auto') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 26 | ▶ | if ( not defined $ENV{ANSI_COLORS_DISABLED} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 20 | ▶ | $ENV{ANSI_COLORS_DISABLED} = -t STDOUT ? undef : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | elsif ($mode eq 'always') { | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $ENV{ANSI_COLORS_DISABLED} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | elsif ($mode eq 'never') { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 14 | $ENV{ANSI_COLORS_DISABLED} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # 'env' is done in the env set line above | ||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 26 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 26 | my $args = { @_ }; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 26 | my $exit = $args->{exit}; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 26 | ▶ | my $err = $args->{err} || ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'err'} || ''
MC/DC100%1/1
$args->{'err'} || ''
$args->{'err'}
Truth table100%2/2
A
A= $args->{'err'}
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 26 | my $colours = $self->colours; | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | # Set the color handling for this call | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 26 | ▶ | $self->_set_color_handling( $args->{use_color} || $self->use_color ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'use_color'} || $self->use_color
MC/DC0%0/2
$args->{'use_color'} || $self->use_color
$args->{'use_color'}
$self->use_color
Truth table33%1/3
A || B
A= $args->{'use_color'}B= $self->use_color
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 26 | my $pod = $self->_get_pod( | |||||||||||||||||||||||||||||||||||||||||
| 217 | sections => $self->usage_sections, | ||||||||||||||||||||||||||||||||||||||||||
| 218 | options_style => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 219 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 26 | my $parser = MooseX::Getopt::Usage::Pod::Text->new( | |||||||||||||||||||||||||||||||||||||||||
| 221 | width => $self->width, | ||||||||||||||||||||||||||||||||||||||||||
| 222 | headings => $self->headings | ||||||||||||||||||||||||||||||||||||||||||
| 223 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 26 | my $out; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 26 | $parser->output_string(\$out); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 26 | $parser->parse_string_document($pod); | |||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 26 | ▶ | $out = colored($colours->{error}, $err)."\n".$out if $err; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 26 | ▶ | if ( defined $exit ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 24 | print $out; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 24 | exit $exit; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 14 | ▶ | sub manpage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
manpage: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 14 | $self->_set_color_handling('never'); | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 14 | my $pod = $self->_get_pod( sections => $self->man_sections ); | |||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 14 | ▶ | open my $fh, "<", \$pod or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 14 | pod2usage( -verbose => 2, -input => $fh ); | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | # Get the pod for the target class. Fills in missing sections. | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 40 | ▶ | sub _get_pod { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_pod: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 40 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 40 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 40 | ▶ | my $opt_style = $args{options_style} || "pod"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'options_style'} || 'pod'
MC/DC100%1/1
$args{'options_style'} || 'pod'
$args{'options_style'}
Truth table100%2/2
A
A= $args{'options_style'}
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 40 | ▶ | my $sections = $args{sections} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'sections'} || []
MC/DC0%0/1
$args{'sections'} || []
$args{'sections'}
Truth table50%1/2
A
A= $args{'sections'}
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 40 | my $gclass = $self->getopt_class; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | # Grab all the pod text (strips out the code). | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 40 | ▶ | my $pod = $self->pod_file ? podselect_text( $self->pod_file ) : ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | # XXX Some dirty pod regexp hacking. Needs moving to a real parser. | ||||||||||||||||||||||||||||||||||||||||||
| 260 | # Insert SYNOPSIS if not there. After NAME or top of pod. | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 40 | ▶ | unless ($pod =~ m/^=head1\s+SYNOPSIS\s*$/ms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 26 | my $synopsis = "\n=head1 SYNOPSIS\n\n".$self->format."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 26 | ▶ | if ($pod =~ m/^=head1\s+NAME\s*$/ms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 15 | $pod =~ s/(^=head1\s+NAME\s*\n.*?)(^=|\z)/$1$synopsis\n\n$2/ms; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 11 | $pod = "$synopsis\n$pod"; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | # Insert OPTIONS if not there. After DESCRIPTION or SYNOPSIS or end of pod. | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 40 | ▶ | unless ($pod =~ m/^=head1\s+OPTIONS\s*$/ms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 30 | my $newpod = "\n=head1 OPTIONS\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 30 | ▶ | if ($pod =~ m/^=head1\s+DESCRIPTION\s*$/ms) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 15 | $pod =~ s/(^=head1\s+DESCRIPTION\s*\n.*?)(^=|\z)/$1$newpod$2/ms; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | elsif ($pod =~ m/^=head1\s+SYNOPSIS\s*$/ms) { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 15 | $pod =~ s/(^=head1\s+SYNOPSIS\s*\n.*?)(^=|\z)/$1$newpod$2/ms; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $pod = "$pod\n$newpod"; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | # Add options list to OPTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 40 | my $meth = "_options_$opt_style"; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 40 | my $options = $self->$meth; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 40 | $pod =~ s/(^=head1\s+OPTIONS\s*\n.*?) | |||||||||||||||||||||||||||||||||||||||||
| 289 | (^=|\z) | ||||||||||||||||||||||||||||||||||||||||||
| 290 | /$1\n$options$2/msx; | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | # Process the SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 40 | $pod =~ s/(^=head1\s+SYNOPSIS\s*\n) # The header $1 | |||||||||||||||||||||||||||||||||||||||||
| 294 | (.*?) # Content $2 | ||||||||||||||||||||||||||||||||||||||||||
| 295 | (^=|\z) # Next section or eof $3 | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 40 | /$1.$self->_parse_format($2).$3/mesx; | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | # Select again to trim down to just the sections asked for. | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 40 | my $out = ""; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 40 | ▶ | open my $fhin, "<", \$pod or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 40 | ▶ | open my $fhout, ">", \$out or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 40 | my $selector = Pod::Select->new(); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 40 | $selector->select(@$sections); | |||||||||||||||||||||||||||||||||||||||||
| 304 | 40 | $selector->parse_from_filehandle($fhin, $fhout); | |||||||||||||||||||||||||||||||||||||||||
| 305 | 40 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | # Return list of class attributes that are options. | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 46 | ▶ | sub _getopt_attrs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getopt_attrs: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 46 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 46 | my $gclass = $self->getopt_class; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 46 | my $attr_sort = $self->attr_sort; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 46 | return sort { $attr_sort->($a, $b) } $gclass->_compute_getopt_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | # Generate POD version of the options from the meta info. | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 14 | ▶ | sub _options_pod { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_options_pod: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 14 | my @attrs = $self->_getopt_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 14 | my $options_pod = ""; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 14 | $options_pod .= "=over 4\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 14 | foreach my $attr (@attrs) { | |||||||||||||||||||||||||||||||||||||||||
| 324 | 41 | my $label = $self->_attr_label($attr); | |||||||||||||||||||||||||||||||||||||||||
| 325 | 41 | $options_pod .= "=item B<$label>\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 41 | ▶ | $options_pod .= ($attr->documentation || "")."\n\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attr->documentation || ''
MC/DC100%1/1
$attr->documentation || ''
$attr->documentation
Truth table100%2/2
A
A= $attr->documentation
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 14 | $options_pod .= "=back\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 14 | return $options_pod; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | # Generate (colored) text version of the options from meta info. | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 26 | ▶ | sub _options_text { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_options_text: called CC=15 SCAR=27.2
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 26 | my $args = { @_ }; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 26 | my $colours = $self->colours; | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 26 | my @attrs = $self->_getopt_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 26 | my $max_len = 0; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 26 | my (@req_attrs, @opt_attrs); | |||||||||||||||||||||||||||||||||||||||||
| 341 | 26 | foreach (@attrs) { | |||||||||||||||||||||||||||||||||||||||||
| 342 | 92 | my $len = length($self->_attr_label($_)); | |||||||||||||||||||||||||||||||||||||||||
| 343 | 92 | ▶ | $max_len = $len if $len > $max_len; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 92 | ▶ | if ( $_->is_required && !$_->has_default && !$_->has_builder ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$_->is_required and not $_->has_default and not $_->has_builder
$_->is_required and not $_->has_default
MC/DC66%2/3
$_->is_required and not $_->has_default and not $_->has_builder
$_->is_required
not $_->has_default
not $_->has_builder
Truth table75%3/4
A and not(B) and not(C)
A= $_->is_requiredB= not $_->has_defaultC= not $_->has_builder
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 3 | push @req_attrs, $_; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 89 | push @opt_attrs, $_; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 26 | my $groups = $self->groups; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 26 | ▶ | $groups = @req_attrs ? 1 : 0 if not defined $groups; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 26 | ▶ | my $indent = $groups ? 4 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 26 | my $out = " "; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 26 | ▶ | $out .= colored($colours->{heading}, "Required:")."\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$groups and @req_attrs
MC/DC50%1/2
$groups and @req_attrs
$groups
@req_attrs
Truth table66%2/3
A and B
A= $groupsB= @req_attrs
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | if $groups && @req_attrs; | ||||||||||||||||||||||||||||||||||||||||||
| 359 | $out .= $self->_attr_str($_, max_len => $max_len, indent => $indent )."\n" | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 26 | foreach @req_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 26 | ▶ | $out .= colored($colours->{heading}, "Optional:")."\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$groups and @opt_attrs
MC/DC50%1/2
$groups and @opt_attrs
$groups
@opt_attrs
Truth table66%2/3
A and B
A= $groupsB= @opt_attrs
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | if $groups && @opt_attrs; | ||||||||||||||||||||||||||||||||||||||||||
| 363 | $out .= $self->_attr_str($_, max_len => $max_len, indent => $indent )."\n" | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 26 | foreach @opt_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 26 | $out =~ s{\n}{\n }gsm; # Make into pod preformat para | |||||||||||||||||||||||||||||||||||||||||
| 366 | 26 | $out .= "\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | 26 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 40 | ▶ | sub _parse_format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_format: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 40 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 373 | 40 | ▶ | my $fmt = shift or confess "No format"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 40 | my $colours = $self->colours; | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 40 | $fmt =~ s/%c/colored $colours->{command}, prog_name()/ieg; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 40 | $fmt =~ s/%a/$self->_format_opt_line('a')/ieg; | |||||||||||||||||||||||||||||||||||||||||
| 378 | 40 | $fmt =~ s/%r/$self->_format_opt_line('r')/ieg; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 40 | $fmt =~ s/%o/$self->_format_opt_line('o')/ieg; | |||||||||||||||||||||||||||||||||||||||||
| 380 | 40 | $fmt =~ s/%%/%/g; | |||||||||||||||||||||||||||||||||||||||||
| 381 | # TODO - Be good to have a include that generates a list of the opts | ||||||||||||||||||||||||||||||||||||||||||
| 382 | # %r - required %a - all %o - options | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $fmt =~ s/^(.*?:\n)/colored $colours->{heading}, "$1"/egm; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 40 | $self->_colourise(\$fmt); | |||||||||||||||||||||||||||||||||||||||||
| 385 | 40 | return $fmt; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 6 | ▶ | sub _format_opt_line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_opt_line: called CC=14 SCAR=27.1
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 6 | my $group = shift; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 6 | my @attrs; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 6 | ▶ | if ( !$group || $group eq "a" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
not $group or $group eq "a"
MC/DC50%1/2
not $group or $group eq "a"
not $group
$group eq "a"
Truth table66%2/3
not(A) or B
A= not $groupB= $group eq "a"
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 2 | @attrs = $self->_getopt_attrs; | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | elsif ( $group eq "r" ) { | ||||||||||||||||||||||||||||||||||||||||||
| 397 | @attrs = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | ▶ | $_->is_required && !$_->has_default && !$_->has_builder | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$_->is_required && !$_->has_default && !$_->has_builder
$_->is_required and not $_->has_default
MC/DC33%1/3
$_->is_required && !$_->has_default && !$_->has_builder
$_->is_required
not $_->has_default
!$_->has_builder
Truth table50%2/4
A and not(B) && not(C)
A= $_->is_requiredB= not $_->has_defaultC= !$_->has_builder
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | } $self->_getopt_attrs; | ||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | elsif ( $group eq "o" ) { | ||||||||||||||||||||||||||||||||||||||||||
| 402 | @attrs = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 2 | ▶ | !($_->is_required && !$_->has_default && !$_->has_builder) | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$_->is_required && !$_->has_default && !$_->has_builder
$_->is_required and not $_->has_default
MC/DC33%1/3
$_->is_required && !$_->has_default && !$_->has_builder
$_->is_required
not $_->has_default
!$_->has_builder
Truth table50%2/4
A and not(B) && not(C)
A= $_->is_requiredB= not $_->has_defaultC= !$_->has_builder
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | } $self->_getopt_attrs; | ||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | confess "Unknown grouping: $group"; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 6 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 6 | foreach my $attr (@attrs) { | |||||||||||||||||||||||||||||||||||||||||
| 412 | 16 | my $opt = ""; | |||||||||||||||||||||||||||||||||||||||||
| 413 | 16 | my $label = $self->_attr_label($attr); | |||||||||||||||||||||||||||||||||||||||||
| 414 | 16 | $opt .= "$label"; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 16 | ▶ | if ( not $attr->type_constraint->is_a_type_of("Bool") ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 8 | $opt .= "=".uc($attr->name) | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 16 | ▶ | if (!$attr->is_required || $attr->has_default || $attr->has_builder) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $attr->is_required or $attr->has_default or $attr->has_builder
not $attr->is_required or $attr->has_default
MC/DC33%1/3
not $attr->is_required or $attr->has_default or $attr->has_builder
not $attr->is_required
$attr->has_default
$attr->has_builder
Truth table50%2/4
not(A) or B or C
A= not $attr->is_requiredB= $attr->has_defaultC= $attr->has_builder
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | 12 | $opt = "[$opt]"; | |||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 16 | push @out, $opt; | |||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 6 | return join(" ", @out);; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | # Return the full label, including aliases and dashes, for the passed attribute | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 241 | ▶ | sub _attr_label { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attr_label: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 241 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 241 | ▶ | my $attr = shift || confess "No attr"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || confess('No attr')
MC/DC0%0/1
shift() || confess('No attr')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 241 | my $gclass = $self->getopt_class; | |||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 241 | my ( $flag, @aliases ) = $gclass->_get_cmd_flags_for_attr($attr); | |||||||||||||||||||||||||||||||||||||||||
| 433 | my $label = join " ", map { | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 241 | ▶ | length($_) == 1 ? "-$_" : "--$_" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | } ($flag, @aliases); | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 241 | return $label; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | # Return the formated and coloured usage string for the passed attribute. | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 92 | ▶ | sub _attr_str { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attr_str: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 92 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 92 | ▶ | my $attr = shift or confess "No attr"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 92 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 92 | ▶ | my $max_len = $args{max_len} or confess "No max_len"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 92 | ▶ | my $indent = $args{indent} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'indent'} || 0
MC/DC100%1/1
$args{'indent'} || 0
$args{'indent'}
Truth table100%2/2
A
A= $args{'indent'}
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 92 | my $colours = $self->colours; | |||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 92 | local $Text::Wrap::columns = $self->width; | |||||||||||||||||||||||||||||||||||||||||
| 449 | 92 | local $Text::Wrap::unexpand = $self->unexpand; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 92 | local $Text::Wrap::tabstop = $self->tabstop; | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 92 | my $label = $self->_attr_label($attr); | |||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 92 | my $docs = ""; | |||||||||||||||||||||||||||||||||||||||||
| 455 | 92 | my $pad = $max_len - length($label); | |||||||||||||||||||||||||||||||||||||||||
| 456 | 92 | ▶ | my $def = $attr->has_default ? $attr->default : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 92 | (my $type = $attr->type_constraint) =~ s/(\w+::)*//g; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 92 | ▶ | $docs .= colored($colours->{type}, "$type. ") if $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 92 | ▶ | $docs .= colored($colours->{default_value}, "Default=$def").". " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $def and not ref $def
MC/DC50%1/2
defined $def and not ref $def
defined $def
not ref $def
Truth table66%2/3
A and not(B)
A= defined $defB= not ref $def
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | if defined $def && ! ref $def; | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 92 | ▶ | $docs .= $attr->documentation || ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attr->documentation || ''
MC/DC100%1/1
$attr->documentation || ''
$attr->documentation
Truth table100%2/2
A
A= $attr->documentation
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 92 | my $col1 = (" " x $indent).$label; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 92 | $col1 .= "".( " " x $pad ); | |||||||||||||||||||||||||||||||||||||||||
| 465 | 92 | my $out = wrap($col1, (" " x ($max_len + 9)), " - $docs" ); | |||||||||||||||||||||||||||||||||||||||||
| 466 | 92 | $self->_colourise(\$out); | |||||||||||||||||||||||||||||||||||||||||
| 467 | 92 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | # Extra colourisation for the attributes usage string. Think syntax highlight. | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 132 | ▶ | sub _colourise { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_colourise: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 132 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 132 | ▶ | my $out = shift || ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 132 | my $colours = $self->colours; | |||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 132 | ▶ | my $str = ref $out ? $out : \$out; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 132 | $$str =~ s/(^|\s|\[)(--?[\w?]+)/"$1".colored $colours->{flag},"$2"/ge; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 132 | ▶ | return ref $out ? $out : $$str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | 44 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 44 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 44 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 486 | __END__ | ||||||||||||||||||||||||||||||||||||||||||