| 1 | package Term::Choose::Util; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.10.1; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.149'; | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT_OK = qw( choose_a_directory choose_a_file choose_directories choose_a_number choose_a_subset settings_menu | |||||||||||||||||||||||||||||
| 10 | insert_sep get_term_size get_term_width get_term_height unicode_sprintf ); | ||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Cwd qw( realpath ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Encode qw( decode encode ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use File::Basename qw( basename dirname ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use File::Spec::Functions qw( catdir catfile ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use List::Util qw( sum any ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Encode::Locale qw(); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use File::HomeDir qw(); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Term::Choose qw( choose ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use Term::Choose::Constants qw( SGR_ES PH ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Term::Choose::LineFold qw( cut_to_printwidth print_columns ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Term::Choose::ValidateOptions qw( validate_options ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 29 | 0 | my $class = shift; | |||||||||||||||||||||||||||||
| 30 | 0 | my ( $opt ) = @_; | |||||||||||||||||||||||||||||
| 31 | 0 | my $instance_defaults = _defaults(); | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ( defined $opt ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | croak "Options have to be passed as a HASH reference." if ref $opt ne 'HASH'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 34 | 0 | my $caller = 'new'; | |||||||||||||||||||||||||||||
| 35 | 0 | validate_options( _valid_options( $caller ), $opt, $caller ); | |||||||||||||||||||||||||||||
| 36 | 0 | for my $key ( keys %$opt ) { | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $instance_defaults->{$key} = $opt->{$key} if defined $opt->{$key}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||
| 40 | 0 | my $self = bless $instance_defaults, $class; | |||||||||||||||||||||||||||||
| 41 | 0 | $self->{backup_instance_defaults} = { %$instance_defaults }; | |||||||||||||||||||||||||||||
| 42 | 0 | return $self; | |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub __restore_defaults { | ||||||||||||||||||||||||||||
|
Subroutine
__restore_defaults: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||
| 47 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ( exists $self->{backup_instance_defaults} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 49 | 0 | my $instance_defaults = $self->{backup_instance_defaults}; | |||||||||||||||||||||||||||||
| 50 | 0 | for my $key ( keys %$self ) { | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ( $key eq 'backup_instance_defaults' ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 52 | 0 | next; | |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||
| 54 | elsif ( exists $instance_defaults->{$key} ) { | ||||||||||||||||||||||||||||||
| 55 | 0 | $self->{$key} = $instance_defaults->{$key}; | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||||||||||
| 58 | 0 | delete $self->{$key}; | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub __prepare_opt { | ||||||||||||||||||||||||||||
|
Subroutine
__prepare_opt: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||
| 66 | 0 | my ( $self, $opt, $subseq_tab ) = @_; | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( ! defined $opt ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 68 | 0 | $opt = {}; | |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | croak "Options have to be passed as a HASH reference." if ref $opt ne 'HASH'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( %$opt ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 72 | 0 | my $caller = ( caller( 1 ) )[3]; | |||||||||||||||||||||||||||||
| 73 | 0 | $caller =~ s/^.+::(?:__)?([^:]+)\z/$1/; | |||||||||||||||||||||||||||||
| 74 | 0 | validate_options( _valid_options( $caller ), $opt, $caller ); | |||||||||||||||||||||||||||||
| 75 | 0 | my $defaults = _defaults(); | |||||||||||||||||||||||||||||
| 76 | 0 | for my $key ( keys %$opt ) { | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( ! defined $opt->{$key} && defined $defaults->{$key} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $opt->{$key} and defined $defaults->{$key}
MC/DC0%0/2
not defined $opt->{$key} and defined $defaults->{$key}
not defined $opt->{$key}
defined $defaults->{$key}
Truth table0%0/3
not(A) and B
A= not defined $opt->{$key}B= defined $defaults->{$key}
| |||||||||||||||||||||||||||||||
| 78 | 0 | $self->{$key} = $defaults->{$key}; | |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||||
| 81 | 0 | $self->{$key} = $opt->{$key}; | |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( ! defined $self->{tabs_prompt} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( defined $self->{margin} ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 87 | 0 | $self->{tabs_prompt} = [ 0, $subseq_tab, $self->{margin}[3], $self->{margin}[1], $self->{max_width} ]; | |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||
| 89 | elsif ( $subseq_tab ) { | ||||||||||||||||||||||||||||||
| 90 | 0 | $self->{tabs_prompt} = [ 0, $subseq_tab, 0, 0, $self->{max_width} ]; | |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub _valid_options { | ||||||||||||||||||||||||||||
|
Subroutine
_valid_options: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 97 | 0 | my ( $caller ) = @_; | |||||||||||||||||||||||||||||
| 98 | 0 | my %valid = ( | |||||||||||||||||||||||||||||
| 99 | all_by_default => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 100 | clear_screen => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 101 | decoded => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 102 | hide_cursor => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 103 | index => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 104 | keep_chosen => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 105 | mouse => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 106 | order => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 107 | show_hidden => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 108 | small_first => '[ 0 1 ]', | ||||||||||||||||||||||||||||||
| 109 | alignment => '[ 0 1 2 ]', | ||||||||||||||||||||||||||||||
| 110 | color => '[ 0 1 2 ]', | ||||||||||||||||||||||||||||||
| 111 | layout => '[ 0 1 2 ]', | ||||||||||||||||||||||||||||||
| 112 | page => '[ 0 1 2 ]', # undocumented | ||||||||||||||||||||||||||||||
| 113 | keep => '[ 1-9 ][ 0-9 ]*', # undocumented | ||||||||||||||||||||||||||||||
| 114 | max_width => '(?:[2-9]|[ 1-9 ][ 0-9 ]+)', | ||||||||||||||||||||||||||||||
| 115 | default_number => '[ 0-9 ]+', | ||||||||||||||||||||||||||||||
| 116 | margin => 'Array_Int', | ||||||||||||||||||||||||||||||
| 117 | mark => 'Array_Int_Idx', | ||||||||||||||||||||||||||||||
| 118 | tabs_bottom_text => 'Array_Int', | ||||||||||||||||||||||||||||||
| 119 | tabs_info => 'Array_Int', | ||||||||||||||||||||||||||||||
| 120 | tabs_prompt => 'Array_Int', | ||||||||||||||||||||||||||||||
| 121 | bottom_text => 'Str', | ||||||||||||||||||||||||||||||
| 122 | busy_string => 'Str', | ||||||||||||||||||||||||||||||
| 123 | info => 'Str', | ||||||||||||||||||||||||||||||
| 124 | init_dir => 'Str', | ||||||||||||||||||||||||||||||
| 125 | back => 'Str', | ||||||||||||||||||||||||||||||
| 126 | filter => 'Str', | ||||||||||||||||||||||||||||||
| 127 | footer => 'Str', # undocumented | ||||||||||||||||||||||||||||||
| 128 | confirm => 'Str', | ||||||||||||||||||||||||||||||
| 129 | prefix => 'Str', | ||||||||||||||||||||||||||||||
| 130 | prompt => 'Str', | ||||||||||||||||||||||||||||||
| 131 | prompt2 => 'Str', | ||||||||||||||||||||||||||||||
| 132 | cs_begin => 'Str', | ||||||||||||||||||||||||||||||
| 133 | cs_end => 'Str', | ||||||||||||||||||||||||||||||
| 134 | cs_label => 'Str', | ||||||||||||||||||||||||||||||
| 135 | cs_separator => 'Str', | ||||||||||||||||||||||||||||||
| 136 | thousands_separator => 'Str', | ||||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||||
| 138 | 0 | my $options; | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ( $caller eq 'new' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 140 | 0 | $options = [ keys %valid ]; | |||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||||
| 143 | 0 | $options = _routine_options( $caller ); | |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||
| 145 | 0 | return { map { $_ => $valid{$_} } @$options }; | |||||||||||||||||||||||||||||
| 146 | }; | ||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | sub _defaults { | ||||||||||||||||||||||||||||
|
Subroutine
_defaults: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 150 | return { | ||||||||||||||||||||||||||||||
| 151 | 0 | alignment => 0, | |||||||||||||||||||||||||||||
| 152 | all_by_default => 0, | ||||||||||||||||||||||||||||||
| 153 | back => 'BACK', | ||||||||||||||||||||||||||||||
| 154 | #bottom_text => undef, | ||||||||||||||||||||||||||||||
| 155 | #busy_string => undef, | ||||||||||||||||||||||||||||||
| 156 | clear_screen => 0, | ||||||||||||||||||||||||||||||
| 157 | color => 0, | ||||||||||||||||||||||||||||||
| 158 | confirm => 'CONFIRM', | ||||||||||||||||||||||||||||||
| 159 | cs_begin => '', | ||||||||||||||||||||||||||||||
| 160 | cs_end => '', | ||||||||||||||||||||||||||||||
| 161 | #cs_label => undef, | ||||||||||||||||||||||||||||||
| 162 | cs_separator => ', ', | ||||||||||||||||||||||||||||||
| 163 | decoded => 1, | ||||||||||||||||||||||||||||||
| 164 | #default_number => undef, | ||||||||||||||||||||||||||||||
| 165 | #filter => undef, | ||||||||||||||||||||||||||||||
| 166 | #footer => undef, | ||||||||||||||||||||||||||||||
| 167 | hide_cursor => 1, | ||||||||||||||||||||||||||||||
| 168 | index => 0, | ||||||||||||||||||||||||||||||
| 169 | #info => undef, | ||||||||||||||||||||||||||||||
| 170 | #init_dir => undef, | ||||||||||||||||||||||||||||||
| 171 | keep_chosen => 0, | ||||||||||||||||||||||||||||||
| 172 | #keep => undef, | ||||||||||||||||||||||||||||||
| 173 | layout => 1, | ||||||||||||||||||||||||||||||
| 174 | #margin => undef, | ||||||||||||||||||||||||||||||
| 175 | #mark => undef, | ||||||||||||||||||||||||||||||
| 176 | #max_width => undef, | ||||||||||||||||||||||||||||||
| 177 | mouse => 0, | ||||||||||||||||||||||||||||||
| 178 | order => 1, | ||||||||||||||||||||||||||||||
| 179 | #page => undef, | ||||||||||||||||||||||||||||||
| 180 | parent_dir => '..', | ||||||||||||||||||||||||||||||
| 181 | prefix => '', | ||||||||||||||||||||||||||||||
| 182 | #prompt => undef, | ||||||||||||||||||||||||||||||
| 183 | #prompt2 => undef, | ||||||||||||||||||||||||||||||
| 184 | show_hidden => 1, | ||||||||||||||||||||||||||||||
| 185 | small_first => 0, | ||||||||||||||||||||||||||||||
| 186 | #tabs_bottom_text => undef, | ||||||||||||||||||||||||||||||
| 187 | #tabs_info => undef, | ||||||||||||||||||||||||||||||
| 188 | #tabs_prompt => undef, | ||||||||||||||||||||||||||||||
| 189 | thousands_separator => ',', | ||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||
| 191 | ## intern: | ||||||||||||||||||||||||||||||
| 192 | reset => 'reset', | ||||||||||||||||||||||||||||||
| 193 | }; | ||||||||||||||||||||||||||||||
| 194 | }; | ||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub _routine_options { | ||||||||||||||||||||||||||||
|
Subroutine
_routine_options: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||
| 198 | 0 | my ( $caller ) = @_; | |||||||||||||||||||||||||||||
| 199 | 0 | my @every = ( qw( back bottom_text clear_screen color confirm cs_label footer hide_cursor info keep margin max_width mouse page prompt tabs_bottom_text tabs_info tabs_prompt ) ); | |||||||||||||||||||||||||||||
| 200 | 0 | my $options; | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ( $caller eq 'choose_directories' ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 202 | 0 | $options = [ @every, qw( init_dir layout order alignment show_hidden decoded prompt2 ) ]; | |||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||
| 204 | elsif ( $caller eq 'choose_a_directory' ) { | ||||||||||||||||||||||||||||||
| 205 | 0 | $options = [ @every, qw( init_dir layout order alignment show_hidden decoded ) ]; | |||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||
| 207 | elsif ( $caller eq 'choose_a_file' ) { | ||||||||||||||||||||||||||||||
| 208 | 0 | $options = [ @every, qw( init_dir layout order alignment show_hidden decoded filter prompt2 ) ]; | |||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||
| 210 | elsif ( $caller eq 'choose_a_number' ) { | ||||||||||||||||||||||||||||||
| 211 | 0 | $options = [ @every, qw( small_first reset thousands_separator default_number ) ]; | |||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||
| 213 | elsif ( $caller eq 'choose_a_subset' ) { | ||||||||||||||||||||||||||||||
| 214 | 0 | $options = [ @every, qw( layout order alignment keep_chosen index prefix all_by_default cs_begin cs_end cs_separator mark busy_string ) ]; | |||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||
| 216 | elsif ( $caller eq 'settings_menu' ) { | ||||||||||||||||||||||||||||||
| 217 | 0 | $options = [ @every, qw( cs_begin cs_end cs_separator ) ]; | |||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||
| 219 | 0 | return $options; | |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | sub __error_message { | ||||||||||||||||||||||||||||
|
Subroutine
__error_message: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 224 | 0 | my ( $self, $message ) = @_; | |||||||||||||||||||||||||||||
| 225 | 0 | $message =~ s/\n\z//; | |||||||||||||||||||||||||||||
| 226 | # Choose | ||||||||||||||||||||||||||||||
| 227 | choose( | ||||||||||||||||||||||||||||||
| 228 | [ 'Press ENTER to continue' ], | ||||||||||||||||||||||||||||||
| 229 | { footer => $self->{footer}, hide_cursor => $self->{hide_cursor}, margin => $self->{margin}, | ||||||||||||||||||||||||||||||
| 230 | 0 | mouse => $self->{mouse}, page => $self->{page}, prompt => $message } | |||||||||||||||||||||||||||||
| 231 | ); | ||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub __prepare_path { | ||||||||||||||||||||||||||||
|
Subroutine
__prepare_path: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||
| 236 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 237 | 0 | my $init_dir_fs; | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if ( defined $self->{init_dir} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 239 | 0 | $init_dir_fs = encode( 'locale_fs', $self->{init_dir} ); | |||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ( ! -d $init_dir_fs ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 241 | 0 | my $message = 'Directory "'; | |||||||||||||||||||||||||||||
| 242 | 0 | $message .= decode 'locale_fs', $init_dir_fs; | |||||||||||||||||||||||||||||
| 243 | 0 | $message .= '" not found. Falling back to home directory.'; | |||||||||||||||||||||||||||||
| 244 | 0 | $self->__error_message( $message ); | |||||||||||||||||||||||||||||
| 245 | 0 | $init_dir_fs = File::HomeDir->my_home(); | |||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||
| 248 | else { | ||||||||||||||||||||||||||||||
| 249 | 0 | $init_dir_fs = File::HomeDir->my_home(); | |||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ( ! -d $init_dir_fs ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 252 | 0 | croak "Could not find the home directory."; | |||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $dir_fs = realpath( $init_dir_fs ) or die "$init_dir_fs: $!"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 255 | 0 | my $dir = decode( 'locale_fs', $dir_fs ); | |||||||||||||||||||||||||||||
| 256 | 0 | return $dir; | |||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub __available_dirs { | ||||||||||||||||||||||||||||
|
Subroutine
__available_dirs: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||
| 261 | 0 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||
| 262 | 0 | my $dir_fs = encode( 'locale_fs', $dir ); | |||||||||||||||||||||||||||||
| 263 | 0 | my $dh; | |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if ( ! eval { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | opendir( $dh, $dir_fs ) or croak "$dir_fs: $!"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 266 | 0 | 1 } | |||||||||||||||||||||||||||||
| 267 | ) { | ||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||
| 269 | 0 | $self->__error_message( $@ ); | |||||||||||||||||||||||||||||
| 270 | 0 | return; | |||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||
| 272 | 0 | my @dirs; | |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | while ( my $file_fs = readdir $dh ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | next if $file_fs =~ /^\.\.?\z/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | next if $file_fs =~ /^\./ && ! $self->{show_hidden}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file_fs =~ /^\./ and not $self->{"show_hidden"}
MC/DC0%0/2
$file_fs =~ /^\./ and not $self->{"show_hidden"}
$file_fs =~ /^\./
not $self->{"show_hidden"}
Truth table0%0/3
A and not(B)
A= $file_fs =~ /^\./B= not $self->{"show_hidden"}
| |||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ( -d catdir $dir_fs, $file_fs ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 277 | 0 | push @dirs, decode( 'locale_fs', $file_fs ); | |||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||
| 280 | 0 | closedir $dh; | |||||||||||||||||||||||||||||
| 281 | 0 | return [ sort @dirs ]; | |||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | sub choose_directories { | ||||||||||||||||||||||||||||
|
Subroutine
choose_directories: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if ( ref $_[0] ne __PACKAGE__ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 287 | 0 | my $ob = __PACKAGE__->new(); | |||||||||||||||||||||||||||||
| 288 | 0 | delete $ob->{backup_instance_defaults}; | |||||||||||||||||||||||||||||
| 289 | 0 | return $ob->choose_directories( @_ ); | |||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||
| 291 | 0 | my ( $self, $opt ) = @_; | |||||||||||||||||||||||||||||
| 292 | 0 | my $subseq_tab = 2; | |||||||||||||||||||||||||||||
| 293 | 0 | $self->__prepare_opt( $opt, $subseq_tab ); | |||||||||||||||||||||||||||||
| 294 | 0 | my $dir = $self->__prepare_path(); | |||||||||||||||||||||||||||||
| 295 | 0 | my $chosen_dirs = []; | |||||||||||||||||||||||||||||
| 296 | 0 | my ( $confirm, $change_path, $add_dirs ) = ( $self->{confirm}, '- Change Location', '- Add Directories' ); | |||||||||||||||||||||||||||||
| 297 | 0 | my @bu; | |||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||
| 299 | 0 | CHOOSE_MODE: while ( 1 ) { | |||||||||||||||||||||||||||||
| 300 | 0 | ▶ | my $key_dirs = $self->{cs_label} // 'Chosen Dirs: '; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"cs_label"} // "Chosen Dirs: "
MC/DC0%0/1
$self->{"cs_label"} // "Chosen Dirs: "
$self->{"cs_label"}
Truth table0%0/2
A
A= $self->{"cs_label"}
| |||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | my $dirs_chosen = $key_dirs . ( @$chosen_dirs ? join( ', ', @$chosen_dirs ) : '---' ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 302 | 0 | my $key_path = 'Location: '; | |||||||||||||||||||||||||||||
| 303 | 0 | my $path = $key_path . $dir; | |||||||||||||||||||||||||||||
| 304 | 0 | my $prompt = $dirs_chosen . "\n" . $path; | |||||||||||||||||||||||||||||
| 305 | # Choose | ||||||||||||||||||||||||||||||
| 306 | my $choice = choose( | ||||||||||||||||||||||||||||||
| 307 | [ undef, $confirm, $change_path, $add_dirs ], | ||||||||||||||||||||||||||||||
| 308 | { bottom_text => $self->{bottom_text}, clear_screen => $self->{clear_screen}, color => $self->{color}, | ||||||||||||||||||||||||||||||
| 309 | footer => $self->{footer}, hide_cursor => $self->{hide_cursor}, info => $self->{info}, | ||||||||||||||||||||||||||||||
| 310 | keep => $self->{keep}, layout => 2, margin => $self->{margin}, max_width => $self->{max_width}, | ||||||||||||||||||||||||||||||
| 311 | mouse => $self->{mouse}, page => $self->{page}, prompt => $prompt, | ||||||||||||||||||||||||||||||
| 312 | tabs_bottom_text => $self->{tabs_bottom_text}, tabs_info => $self->{tabs_info}, | ||||||||||||||||||||||||||||||
| 313 | tabs_prompt => $self->{tabs_prompt}, undef => $self->{back} } | ||||||||||||||||||||||||||||||
| 314 | 0 | ); | |||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if ( ! defined $choice ) { | ||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if ( @bu ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 317 | 0 | ( $dir, $chosen_dirs ) = @{pop @bu}; | |||||||||||||||||||||||||||||
| 318 | 0 | next CHOOSE_MODE; | |||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||
| 320 | 0 | $self->__restore_defaults(); # | |||||||||||||||||||||||||||||
| 321 | 0 | return; | |||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||
| 323 | elsif ( $choice eq $confirm ) { | ||||||||||||||||||||||||||||||
| 324 | 0 | my $decoded = $self->{decoded}; | |||||||||||||||||||||||||||||
| 325 | 0 | $self->__restore_defaults(); | |||||||||||||||||||||||||||||
| 326 | 0 | ▶ | return $decoded ? $chosen_dirs : [ map { encode 'locale_fs', $_ } @$chosen_dirs ]; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||
| 328 | elsif ( $choice eq $change_path ) { | ||||||||||||||||||||||||||||||
| 329 | 0 | my $prompt_fmt = $key_path . "%s"; | |||||||||||||||||||||||||||||
| 330 | 0 | ▶ | my $prompt = $self->{prompt} // 'Change Location:'; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"prompt"} // "Change Location:"
MC/DC0%0/1
$self->{"prompt"} // "Change Location:"
$self->{"prompt"}
Truth table0%0/2
A
A= $self->{"prompt"}
| |||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ( length $prompt ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 332 | 0 | $prompt_fmt .= "\n" . $prompt; | |||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||
| 334 | 0 | my $tmp_dir = $self->__choose_a_path( $dir, $prompt_fmt, '<<', 'OK' ); | |||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ( defined $tmp_dir ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 336 | 0 | $dir = $tmp_dir; | |||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||
| 339 | elsif ( $choice eq $add_dirs ) { | ||||||||||||||||||||||||||||||
| 340 | 0 | my $avail_dirs = $self->__available_dirs( $dir ); | |||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if ( ! defined $avail_dirs ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 342 | 0 | next CHOOSE_MODE; | |||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||
| 344 | 0 | my %bu_opt; | |||||||||||||||||||||||||||||
| 345 | 0 | my $options = _routine_options( 'choose_directories' ); | |||||||||||||||||||||||||||||
| 346 | 0 | for my $o ( @$options ) { | |||||||||||||||||||||||||||||
| 347 | 0 | $bu_opt{$o} = $self->{$o}; | |||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||
| 349 | 0 | my $cs_label = $dirs_chosen . "\n" . $path . "\n" . '+ '; | |||||||||||||||||||||||||||||
| 350 | 0 | ▶ | my $prompt = $self->{prompt2} // 'Add Directories:'; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"prompt2"} // "Add Directories:"
MC/DC0%0/1
$self->{"prompt2"} // "Add Directories:"
$self->{"prompt2"}
Truth table0%0/2
A
A= $self->{"prompt2"}
| |||||||||||||||||||||||||||||||
| 351 | # choose_a_subset | ||||||||||||||||||||||||||||||
| 352 | 0 | my $idxs = $self->choose_a_subset( | |||||||||||||||||||||||||||||
| 353 | [ sort @$avail_dirs ], | ||||||||||||||||||||||||||||||
| 354 | { back => '<<', confirm => 'OK', cs_begin => undef, cs_label => $cs_label, index => 1, keep_chosen => 1, | ||||||||||||||||||||||||||||||
| 355 | prompt => $prompt } # plus all the options already in $self | ||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||
| 357 | ); | ||||||||||||||||||||||||||||||
| 358 | 0 | for my $o ( keys %bu_opt ) { | |||||||||||||||||||||||||||||
| 359 | 0 | $self->{$o} = $bu_opt{$o}; | |||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ( defined $idxs && @$idxs ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $idxs and @$idxs
MC/DC0%0/2
defined $idxs and @$idxs
defined $idxs
@$idxs
Truth table0%0/3
A and B
A= defined $idxsB= @$idxs
| |||||||||||||||||||||||||||||||
| 362 | 0 | push @bu, [ $dir, [ @$chosen_dirs ] ]; | |||||||||||||||||||||||||||||
| 363 | 0 | push @$chosen_dirs, map { catdir $dir, $_ } @{$avail_dirs}[@$idxs]; | |||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | sub choose_a_file { | ||||||||||||||||||||||||||||
|
Subroutine
choose_a_file: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | if ( ref $_[0] ne __PACKAGE__ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 372 | 0 | my $ob = __PACKAGE__->new(); | |||||||||||||||||||||||||||||
| 373 | 0 | delete $ob->{backup_instance_defaults}; | |||||||||||||||||||||||||||||
| 374 | 0 | return $ob->choose_a_file( @_ ); | |||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||
| 376 | 0 | my ( $self, $opt ) = @_; | |||||||||||||||||||||||||||||
| 377 | 0 | $self->__prepare_opt( $opt ); | |||||||||||||||||||||||||||||
| 378 | 0 | my $init_dir = $self->__prepare_path(); | |||||||||||||||||||||||||||||
| 379 | 0 | my $prompt_fmt = "Source directory: %s"; | |||||||||||||||||||||||||||||
| 380 | 0 | ▶ | my $prompt = $self->{prompt} // 'Choose the source directory:'; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"prompt"} // "Choose the source directory:"
MC/DC0%0/1
$self->{"prompt"} // "Choose the source directory:"
$self->{"prompt"}
Truth table0%0/2
A
A= $self->{"prompt"}
| |||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ( length $prompt ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 382 | 0 | $prompt_fmt .= "\n" . $prompt; | |||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||
| 385 | 0 | CHOOSE_DIR: while ( 1 ) { | |||||||||||||||||||||||||||||
| 386 | 0 | my $chosen_dir = $self->__choose_a_path( $init_dir, $prompt_fmt, '<<', 'OK' ); | |||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if ( ! defined $chosen_dir ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 388 | 0 | $self->__restore_defaults(); # | |||||||||||||||||||||||||||||
| 389 | 0 | return; | |||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||
| 391 | 0 | my $chosen_file = $self->__a_file( $chosen_dir ); | |||||||||||||||||||||||||||||
| 392 | 0 | ▶ | if ( ! defined $chosen_file ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 393 | 0 | next CHOOSE_DIR; | |||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||
| 395 | 0 | my $decoded = $self->{decoded}; | |||||||||||||||||||||||||||||
| 396 | 0 | $self->__restore_defaults(); | |||||||||||||||||||||||||||||
| 397 | 0 | ▶ | return $decoded ? $chosen_file : encode( 'locale_fs', $chosen_file ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | sub choose_a_directory { | ||||||||||||||||||||||||||||
|
Subroutine
choose_a_directory: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if ( ref $_[0] ne __PACKAGE__ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 404 | 0 | my $ob = __PACKAGE__->new(); | |||||||||||||||||||||||||||||
| 405 | 0 | delete $ob->{backup_instance_defaults}; | |||||||||||||||||||||||||||||
| 406 | 0 | return $ob->choose_a_directory( @_ ); | |||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||
| 408 | 0 | my ( $self, $opt ) = @_; | |||||||||||||||||||||||||||||
| 409 | 0 | $self->__prepare_opt( $opt ); | |||||||||||||||||||||||||||||
| 410 | 0 | my $init_dir = $self->__prepare_path(); | |||||||||||||||||||||||||||||
| 411 | 0 | ▶ | my $prompt_fmt = ( $self->{cs_label} // 'Directory: ' ) . "%s"; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"cs_label"} // "Directory: "
MC/DC0%0/1
$self->{"cs_label"} // "Directory: "
$self->{"cs_label"}
Truth table0%0/2
A
A= $self->{"cs_label"}
| |||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | my $prompt = $self->{prompt} // 'Choose a Directory:'; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"prompt"} // "Choose a Directory:"
MC/DC0%0/1
$self->{"prompt"} // "Choose a Directory:"
$self->{"prompt"}
Truth table0%0/2
A
A= $self->{"prompt"}
| |||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if ( length $prompt ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 414 | 0 | $prompt_fmt .= "\n" . $prompt; | |||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||
| 416 | 0 | my $chosen_dir = $self->__choose_a_path( $init_dir, $prompt_fmt, $self->{back}, $self->{confirm} ); | |||||||||||||||||||||||||||||
| 417 | 0 | my $decoded = $self->{decoded}; | |||||||||||||||||||||||||||||
| 418 | 0 | $self->__restore_defaults(); | |||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if ( ! defined $chosen_dir ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 420 | 0 | return; | |||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | return $decoded ? $chosen_dir : encode( 'locale_fs', $chosen_dir ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | sub __choose_a_path { | ||||||||||||||||||||||||||||
|
Subroutine
__choose_a_path: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||
| 427 | 0 | my ( $self, $dir, $prompt_fmt, $back, $confirm ) = @_; | |||||||||||||||||||||||||||||
| 428 | 0 | my $prev_dir = $dir; | |||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||
| 430 | 0 | while ( 1 ) { | |||||||||||||||||||||||||||||
| 431 | 0 | my ( $dh, @dirs ); | |||||||||||||||||||||||||||||
| 432 | 0 | my $dir_fs = encode( 'locale_fs', $dir ); | |||||||||||||||||||||||||||||
| 433 | 0 | ▶ | if ( ! eval { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | opendir( $dh, $dir_fs ) or croak "$dir_fs: $!"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 435 | 0 | 1 } | |||||||||||||||||||||||||||||
| 436 | ) { | ||||||||||||||||||||||||||||||
| 437 | 0 | $self->__error_message( $@ ); | |||||||||||||||||||||||||||||
| 438 | 0 | $dir = dirname $dir; | |||||||||||||||||||||||||||||
| 439 | 0 | next; | |||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | while ( my $file_fs = readdir $dh ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | next if $file_fs =~ /^\.\.?\z/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | next if $file_fs =~ /^\./ && ! $self->{show_hidden}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file_fs =~ /^\./ and not $self->{"show_hidden"}
MC/DC0%0/2
$file_fs =~ /^\./ and not $self->{"show_hidden"}
$file_fs =~ /^\./
not $self->{"show_hidden"}
Truth table0%0/3
A and not(B)
A= $file_fs =~ /^\./B= not $self->{"show_hidden"}
| |||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ( -d catdir $dir_fs, $file_fs ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 445 | 0 | push @dirs, decode( 'locale_fs', $file_fs ); | |||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||
| 448 | 0 | closedir $dh; | |||||||||||||||||||||||||||||
| 449 | 0 | my $parent_dir = $self->{parent_dir}; | |||||||||||||||||||||||||||||
| 450 | 0 | my @pre = ( undef, $confirm, $parent_dir ); | |||||||||||||||||||||||||||||
| 451 | 0 | my $prompt = sprintf $prompt_fmt, $prev_dir; | |||||||||||||||||||||||||||||
| 452 | # Choose | ||||||||||||||||||||||||||||||
| 453 | my $choice = choose( | ||||||||||||||||||||||||||||||
| 454 | [ @pre, sort( @dirs ) ], | ||||||||||||||||||||||||||||||
| 455 | { alignment => $self->{alignment}, bottom_text => $self->{bottom_text}, | ||||||||||||||||||||||||||||||
| 456 | clear_screen => $self->{clear_screen}, color => $self->{color}, footer => $self->{footer}, | ||||||||||||||||||||||||||||||
| 457 | hide_cursor => $self->{hide_cursor}, info => $self->{info}, keep => $self->{keep}, | ||||||||||||||||||||||||||||||
| 458 | layout => $self->{layout}, margin => $self->{margin}, max_width => $self->{max_width}, | ||||||||||||||||||||||||||||||
| 459 | mouse => $self->{mouse}, order => $self->{order}, page => $self->{page}, prompt => $prompt, | ||||||||||||||||||||||||||||||
| 460 | tabs_bottom_text => $self->{tabs_bottom_text}, tabs_info => $self->{tabs_info}, | ||||||||||||||||||||||||||||||
| 461 | 0 | tabs_prompt => $self->{tabs_prompt}, undef => $back } | |||||||||||||||||||||||||||||
| 462 | ); | ||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | if ( ! defined $choice ) { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 464 | 0 | return; | |||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||
| 466 | elsif ( $choice eq $confirm ) { | ||||||||||||||||||||||||||||||
| 467 | 0 | return $prev_dir; | |||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||
| 469 | elsif ( $choice eq $parent_dir ) { | ||||||||||||||||||||||||||||||
| 470 | 0 | $dir = dirname $dir; | |||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||
| 472 | else { | ||||||||||||||||||||||||||||||
| 473 | 0 | $dir = catdir $dir, $choice; | |||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||
| 475 | 0 | $prev_dir = $dir; | |||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | sub __a_file { | ||||||||||||||||||||||||||||
|
Subroutine
__a_file: not called CC=20 SCAR=59.4
| |||||||||||||||||||||||||||||||
| 481 | 0 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||
| 482 | 0 | my $prev_dir = ''; | |||||||||||||||||||||||||||||
| 483 | 0 | my $chosen_file; | |||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||
| 485 | 0 | while ( 1 ) { | |||||||||||||||||||||||||||||
| 486 | 0 | my @files_fs; | |||||||||||||||||||||||||||||
| 487 | 0 | my $dir_fs = encode( 'locale_fs', $dir ); | |||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if ( ! eval { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | if ( $self->{filter} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | @files_fs = map { basename $_} grep { -e $_ } glob( encode( 'locale_fs', catfile $dir, $self->{filter} ) ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||
| 492 | else { | ||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | opendir( my $dh, $dir_fs ) or croak "$dir_fs: $!"; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 494 | 0 | @files_fs = readdir $dh; | |||||||||||||||||||||||||||||
| 495 | 0 | closedir $dh; | |||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||
| 497 | 0 | 1 } | |||||||||||||||||||||||||||||
| 498 | ) { | ||||||||||||||||||||||||||||||
| 499 | 0 | $self->__error_message( $@ ); | |||||||||||||||||||||||||||||
| 500 | 0 | return; | |||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||
| 502 | 0 | my @files; | |||||||||||||||||||||||||||||
| 503 | 0 | for my $file_fs ( @files_fs ) { | |||||||||||||||||||||||||||||
| 504 | 0 | ▶ | next if $file_fs =~ /^\.\.?\z/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | next if $file_fs =~ /^\./ && ! $self->{show_hidden}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file_fs =~ /^\./ and not $self->{"show_hidden"}
MC/DC0%0/2
$file_fs =~ /^\./ and not $self->{"show_hidden"}
$file_fs =~ /^\./
not $self->{"show_hidden"}
Truth table0%0/3
A and not(B)
A= $file_fs =~ /^\./B= not $self->{"show_hidden"}
| |||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | next if -d catdir $dir_fs, $file_fs; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 507 | 0 | push @files, decode( 'locale_fs', $file_fs ); | |||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||
| 509 | 0 | my $chosen_dir = "Source directory: $dir"; | |||||||||||||||||||||||||||||
| 510 | 0 | my @tmp_prompt; | |||||||||||||||||||||||||||||
| 511 | 0 | push @tmp_prompt, $chosen_dir; | |||||||||||||||||||||||||||||
| 512 | 0 | ▶ | push @tmp_prompt, ( $self->{cs_label} // 'File: ' ) . ( length $prev_dir ? $prev_dir : '' ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{"cs_label"} // "File: "
MC/DC0%0/1
$self->{"cs_label"} // "File: "
$self->{"cs_label"}
Truth table0%0/2
A
A= $self->{"cs_label"}
| |||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | my $prompt2 = $self->{prompt2} // 'Choose a File:'; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"prompt2"} // "Choose a File:"
MC/DC0%0/1
$self->{"prompt2"} // "Choose a File:"
$self->{"prompt2"}
Truth table0%0/2
A
A= $self->{"prompt2"}
| |||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | if ( length $prompt2 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 515 | 0 | push @tmp_prompt, $prompt2; | |||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||
| 517 | 0 | my $prompt = join( "\n", @tmp_prompt ); | |||||||||||||||||||||||||||||
| 518 | 0 | ▶ | if ( ! @files ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 519 | 0 | $prompt .= "\n"; | |||||||||||||||||||||||||||||
| 520 | 0 | ▶ | if ( $self->{filter} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 521 | 0 | $prompt .= 'No matches for filter "' . $self->{filter} . '".'; | |||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||
| 523 | else { | ||||||||||||||||||||||||||||||
| 524 | 0 | $prompt .= "No files in $dir."; | |||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||
| 526 | # Choose | ||||||||||||||||||||||||||||||
| 527 | choose( | ||||||||||||||||||||||||||||||
| 528 | [ ' < ' ], | ||||||||||||||||||||||||||||||
| 529 | { bottom_text => $self->{bottom_text}, color => $self->{color}, footer => $self->{footer}, | ||||||||||||||||||||||||||||||
| 530 | hide_cursor => $self->{hide_cursor}, info => $self->{info}, margin => $self->{margin}, | ||||||||||||||||||||||||||||||
| 531 | max_width => $self->{max_width}, mouse => $self->{mouse}, page => $self->{page}, prompt => $prompt, | ||||||||||||||||||||||||||||||
| 532 | tabs_bottom_text => $self->{tabs_bottom_text}, tabs_info => $self->{tabs_info} } | ||||||||||||||||||||||||||||||
| 533 | 0 | ); | |||||||||||||||||||||||||||||
| 534 | 0 | return; | |||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||
| 536 | 0 | my @pre = ( undef ); | |||||||||||||||||||||||||||||
| 537 | 0 | ▶ | if ( $chosen_file ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 538 | 0 | push @pre, $self->{confirm}; ## | |||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||
| 540 | # Choose | ||||||||||||||||||||||||||||||
| 541 | $chosen_file = choose( | ||||||||||||||||||||||||||||||
| 542 | [ @pre, sort( @files ) ], | ||||||||||||||||||||||||||||||
| 543 | { alignment => $self->{alignment}, bottom_text => $self->{bottom_text}, | ||||||||||||||||||||||||||||||
| 544 | clear_screen => $self->{clear_screen}, color => $self->{color}, footer => $self->{footer}, | ||||||||||||||||||||||||||||||
| 545 | hide_cursor => $self->{hide_cursor}, info => $self->{info}, keep => $self->{keep}, | ||||||||||||||||||||||||||||||
| 546 | layout => $self->{layout}, margin => $self->{margin}, max_width => $self->{max_width}, | ||||||||||||||||||||||||||||||
| 547 | mouse => $self->{mouse}, order => $self->{order}, page => $self->{page}, prompt => $prompt, | ||||||||||||||||||||||||||||||
| 548 | tabs_bottom_text => $self->{tabs_bottom_text}, tabs_info => $self->{tabs_info}, | ||||||||||||||||||||||||||||||
| 549 | tabs_prompt => $self->{tabs_prompt}, undef => $self->{back} } | ||||||||||||||||||||||||||||||
| 550 | 0 | ); | |||||||||||||||||||||||||||||
| 551 | 0 | ▶ | if ( ! length $chosen_file ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | if ( length $prev_dir ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 553 | 0 | $prev_dir = ''; | |||||||||||||||||||||||||||||
| 554 | 0 | next; | |||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||
| 556 | 0 | return; | |||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||
| 558 | elsif ( $chosen_file eq $self->{confirm} ) { | ||||||||||||||||||||||||||||||
| 559 | 0 | ▶ | return if ! length $prev_dir; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 560 | 0 | return catfile $dir, $prev_dir; | |||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||
| 562 | else { | ||||||||||||||||||||||||||||||
| 563 | 0 | $prev_dir = $chosen_file; | |||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | sub choose_a_number { | ||||||||||||||||||||||||||||
|
Subroutine
choose_a_number: not called CC=27 SCAR=66.3
Pod
documented
| |||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | if ( ref $_[0] ne __PACKAGE__ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 571 | 0 | my $ob = __PACKAGE__->new(); | |||||||||||||||||||||||||||||
| 572 | 0 | delete $ob->{backup_instance_defaults}; | |||||||||||||||||||||||||||||
| 573 | 0 | return $ob->choose_a_number( @_ ); | |||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||
| 575 | 0 | my ( $self, $digits, $opt ) = @_; | |||||||||||||||||||||||||||||
| 576 | 0 | my $default_digits = 7; | |||||||||||||||||||||||||||||
| 577 | 0 | ▶ | if ( ref $digits ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 578 | 0 | $opt = $digits; | |||||||||||||||||||||||||||||
| 579 | 0 | $digits = $default_digits; | |||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||
| 581 | elsif ( ! $digits ) { | ||||||||||||||||||||||||||||||
| 582 | 0 | $digits = $default_digits; | |||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||
| 584 | 0 | $self->__prepare_opt( $opt ); | |||||||||||||||||||||||||||||
| 585 | 0 | my $tab = ' - '; | |||||||||||||||||||||||||||||
| 586 | 0 | my $tab_w = print_columns( $tab ); | |||||||||||||||||||||||||||||
| 587 | 0 | my $sep_w = print_columns_ext( $self->{thousands_separator}, $self->{color} ); | |||||||||||||||||||||||||||||
| 588 | 0 | my $longest = $digits + int( ( $digits - 1 ) / 3 ) * $sep_w; | |||||||||||||||||||||||||||||
| 589 | 0 | my @ranges = (); | |||||||||||||||||||||||||||||
| 590 | 0 | for my $di ( 0 .. $digits - 1 ) { | |||||||||||||||||||||||||||||
| 591 | 0 | my $begin = 1 . '0' x $di; | |||||||||||||||||||||||||||||
| 592 | 0 | ▶ | $begin = 0 if $di == 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 593 | 0 | $begin = insert_sep( $begin, $self->{thousands_separator} ); | |||||||||||||||||||||||||||||
| 594 | 0 | ( my $end = $begin ) =~ s/^[01]/9/; | |||||||||||||||||||||||||||||
| 595 | unshift @ranges, unicode_sprintf( $begin, $longest, { right_justify => 1, color => $self->{color} } ) | ||||||||||||||||||||||||||||||
| 596 | . $tab | ||||||||||||||||||||||||||||||
| 597 | 0 | . unicode_sprintf( $end, $longest, { right_justify => 1, color => $self->{color} } ); | |||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||
| 599 | 0 | my $back_tmp = unicode_sprintf( $self->{back}, $longest * 2 + $tab_w + 1, { color => $self->{color} } ); | |||||||||||||||||||||||||||||
| 600 | 0 | my $confirm_tmp = unicode_sprintf( $self->{confirm}, $longest * 2 + $tab_w + 1, { color => $self->{color} } ); | |||||||||||||||||||||||||||||
| 601 | 0 | ▶ | if ( print_columns_ext( $ranges[0], $self->{color} ) > get_term_width() ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 602 | 0 | @ranges = (); | |||||||||||||||||||||||||||||
| 603 | 0 | for my $di ( 0 .. $digits - 1 ) { | |||||||||||||||||||||||||||||
| 604 | 0 | my $begin = 1 . '0' x $di; | |||||||||||||||||||||||||||||
| 605 | 0 | ▶ | $begin = 0 if $di == 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 606 | 0 | $begin = insert_sep( $begin, $self->{thousands_separator} ); | |||||||||||||||||||||||||||||
| 607 | 0 | unshift @ranges, unicode_sprintf( $begin, $longest, { color => $self->{color} } ); | |||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||
| 609 | 0 | $confirm_tmp = $self->{confirm}; | |||||||||||||||||||||||||||||
| 610 | 0 | $back_tmp = $self->{back}; | |||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||
| 612 | 0 | my %numbers; | |||||||||||||||||||||||||||||
| 613 | my $result; | ||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | if ( defined $self->{default_number} && length $self->{default_number} <= $digits ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"default_number"} and length $self->{"default_number"} <= $digits
MC/DC0%0/2
defined $self->{"default_number"} and length $self->{"default_number"} <= $digits
defined $self->{"default_number"}
length $self->{"default_number"} <= $digits
Truth table0%0/3
A and B
A= defined $self->{"default_number"}B= length $self->{"default_number"} <= $digits
| |||||||||||||||||||||||||||||||
| 615 | 0 | my $count_zeros = 0; | |||||||||||||||||||||||||||||
| 616 | 0 | for my $d ( reverse split '', $self->{default_number} ) { | |||||||||||||||||||||||||||||
| 617 | 0 | $numbers{$count_zeros} = $d * 10 ** $count_zeros; | |||||||||||||||||||||||||||||
| 618 | 0 | $count_zeros++; | |||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||
| 620 | 0 | $result = sum( @numbers{keys %numbers} ); | |||||||||||||||||||||||||||||
| 621 | 0 | $result = insert_sep( $result, $self->{thousands_separator} ); | |||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||
| 624 | 0 | NUMBER: while ( 1 ) { | |||||||||||||||||||||||||||||
| 625 | 0 | my $cs_row; | |||||||||||||||||||||||||||||
| 626 | 0 | ▶ | if ( defined $self->{cs_label} || length $result ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"cs_label"} or length $result
MC/DC0%0/2
defined $self->{"cs_label"} or length $result
defined $self->{"cs_label"}
length $result
Truth table0%0/3
A or B
A= defined $self->{"cs_label"}B= length $result
| |||||||||||||||||||||||||||||||
| 627 | 0 | ▶ | my $tmp_result = length $result ? $result : ''; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | my $tmp_cs_label = $self->{cs_label} // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"cs_label"} // ""
MC/DC0%0/1
$self->{"cs_label"} // ""
$self->{"cs_label"}
Truth table0%0/2
A
A= $self->{"cs_label"}
| |||||||||||||||||||||||||||||||
| 629 | 0 | $cs_row = sprintf( "%s%*s", $tmp_cs_label, $longest, $tmp_result ); | |||||||||||||||||||||||||||||
| 630 | 0 | ▶ | if ( print_columns( $cs_row ) > get_term_width() ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 631 | 0 | $cs_row = $tmp_result; | |||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||
| 634 | 0 | my @tmp_prompt; | |||||||||||||||||||||||||||||
| 635 | 0 | ▶ | if ( defined $cs_row ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 636 | 0 | push @tmp_prompt, $cs_row; | |||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | if ( ! defined $self->{prompt} ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 639 | 0 | push @tmp_prompt, 'Your choice:'; | |||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||
| 641 | elsif ( length $self->{prompt} ) { | ||||||||||||||||||||||||||||||
| 642 | 0 | push @tmp_prompt, $self->{prompt}; | |||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||
| 644 | 0 | my $prompt = join "\n", @tmp_prompt; | |||||||||||||||||||||||||||||
| 645 | 0 | my @pre = ( undef, $confirm_tmp ); # confirm if $result ? | |||||||||||||||||||||||||||||
| 646 | # Choose | ||||||||||||||||||||||||||||||
| 647 | my $range = choose( | ||||||||||||||||||||||||||||||
| 648 | $self->{small_first} ? [ @pre, reverse @ranges ] : [ @pre, @ranges ], | ||||||||||||||||||||||||||||||
| 649 | { alignment => 1, bottom_text => $self->{bottom_text}, clear_screen => $self->{clear_screen}, | ||||||||||||||||||||||||||||||
| 650 | color => $self->{color}, footer => $self->{footer}, hide_cursor => $self->{hide_cursor}, | ||||||||||||||||||||||||||||||
| 651 | info => $self->{info}, keep => $self->{keep}, layout => 2, margin => $self->{margin}, | ||||||||||||||||||||||||||||||
| 652 | max_width => $self->{max_width}, mouse => $self->{mouse}, page => $self->{page}, prompt => $prompt, | ||||||||||||||||||||||||||||||
| 653 | tabs_bottom_text => $self->{tabs_bottom_text}, tabs_info => $self->{tabs_info}, | ||||||||||||||||||||||||||||||
| 654 | 0 | ▶ | tabs_prompt => $self->{tabs_prompt}, undef => $back_tmp } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 655 | ); | ||||||||||||||||||||||||||||||
| 656 | 0 | ▶ | if ( ! defined $range ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | if ( defined $result ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 658 | 0 | $result = undef; | |||||||||||||||||||||||||||||
| 659 | 0 | %numbers = (); | |||||||||||||||||||||||||||||
| 660 | 0 | next NUMBER; | |||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||
| 662 | else { | ||||||||||||||||||||||||||||||
| 663 | 0 | $self->__restore_defaults(); | |||||||||||||||||||||||||||||
| 664 | 0 | return; | |||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | if ( $range eq $confirm_tmp ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 668 | 0 | $result = _remove_thousands_separators( $result, $self->{thousands_separator} ); | |||||||||||||||||||||||||||||
| 669 | 0 | $self->__restore_defaults(); | |||||||||||||||||||||||||||||
| 670 | 0 | return $result; | |||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||
| 672 | 0 | my $zeros = ( split /\s*-\s*/, $range )[0]; | |||||||||||||||||||||||||||||
| 673 | 0 | $zeros =~ s/^\s*\d//; | |||||||||||||||||||||||||||||
| 674 | 0 | my $zeros_no_sep = _remove_thousands_separators( $zeros, $self->{thousands_separator} ); | |||||||||||||||||||||||||||||
| 675 | 0 | my $count_zeros = length $zeros_no_sep; | |||||||||||||||||||||||||||||
| 676 | 0 | ▶ | my @choices = $count_zeros ? map( $_ . $zeros, 1 .. 9 ) : ( 0 .. 9 ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 677 | # Choose | ||||||||||||||||||||||||||||||
| 678 | my $number = choose( | ||||||||||||||||||||||||||||||
| 679 | [ undef, @choices, $self->{reset} ], | ||||||||||||||||||||||||||||||
| 680 | { alignment => 2, bottom_text => $self->{bottom_text}, clear_screen => $self->{clear_screen}, | ||||||||||||||||||||||||||||||
| 681 | color => $self->{color}, footer => $self->{footer}, hide_cursor => $self->{hide_cursor}, | ||||||||||||||||||||||||||||||
| 682 | info => $self->{info}, keep => $self->{keep}, layout => 1, margin => $self->{margin}, | ||||||||||||||||||||||||||||||
| 683 | max_width => $self->{max_width}, mouse => $self->{mouse}, order => 0, page => $self->{page}, | ||||||||||||||||||||||||||||||
| 684 | prompt => $prompt, tabs_bottom_text => $self->{tabs_bottom_text}, tabs_info => $self->{tabs_info}, | ||||||||||||||||||||||||||||||
| 685 | 0 | tabs_prompt => $self->{tabs_prompt}, undef => '<<' } | |||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||
| 687 | ); | ||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | next if ! defined $number; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | if ( $number eq $self->{reset} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 690 | 0 | delete $numbers{$count_zeros}; | |||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||
| 692 | else { | ||||||||||||||||||||||||||||||
| 693 | 0 | $numbers{$count_zeros} = _remove_thousands_separators( $number, $self->{thousands_separator} ); | |||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||
| 695 | 0 | $result = sum( @numbers{keys %numbers} ); | |||||||||||||||||||||||||||||
| 696 | 0 | $result = insert_sep( $result, $self->{thousands_separator} ); | |||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | sub _remove_thousands_separators { | ||||||||||||||||||||||||||||
|
Subroutine
_remove_thousands_separators: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||
| 702 | 0 | my ( $str, $sep ) = @_; | |||||||||||||||||||||||||||||
| 703 | # https://stackoverflow.com/questions/13119241/substitution-with-empty-string-unexpected-result | ||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | if ( defined $str && $sep ne '' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $str and $sep ne ""
MC/DC0%0/2
defined $str and $sep ne ""
defined $str
$sep ne ""
Truth table0%0/3
A and B
A= defined $strB= $sep ne ""
| |||||||||||||||||||||||||||||||
| 705 | 0 | $str =~ s/\Q$sep\E//g; | |||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||
| 707 | 0 | return $str; | |||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | sub choose_a_subset { | ||||||||||||||||||||||||||||
|
Subroutine
choose_a_subset: not called CC=27 SCAR=66.3
Pod
documented
| |||||||||||||||||||||||||||||||
| 712 | 0 | ▶ | if ( ref $_[0] ne __PACKAGE__ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 713 | 0 | my $ob = __PACKAGE__->new(); | |||||||||||||||||||||||||||||
| 714 | 0 | delete $ob->{backup_instance_defaults}; | |||||||||||||||||||||||||||||
| 715 | 0 | return $ob->choose_a_subset( @_ ); | |||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||
| 717 | 0 | my ( $self, $available, $opt ) = @_; | |||||||||||||||||||||||||||||
| 718 | 0 | ▶ | my $subseq_tab = length $opt->{cs_label} && $opt->{cs_label} !~ /\R\z/ ? 2 : 0; ## | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $opt->{"cs_label"} and not $opt->{"cs_label"} =~ /\R\z/
MC/DC0%0/2
length $opt->{"cs_label"} and not $opt->{"cs_label"} =~ /\R\z/
length $opt->{"cs_label"}
not $opt->{"cs_label"} =~ /\R\z/
Truth table0%0/3
A and not(B)
A= length $opt->{"cs_label"}B= not $opt->{"cs_label"} =~ /\R\z/
| |||||||||||||||||||||||||||||||
| 719 | 0 | $self->__prepare_opt( $opt, $subseq_tab ); | |||||||||||||||||||||||||||||
| 720 | 0 | my $new_idx = []; | |||||||||||||||||||||||||||||
| 721 | 0 | my $curr_avail = [ @$available ]; | |||||||||||||||||||||||||||||
| 722 | 0 | my $bu = []; | |||||||||||||||||||||||||||||
| 723 | 0 | my @pre = ( undef, $self->{confirm} ); | |||||||||||||||||||||||||||||
| 724 | 0 | my $mark; | |||||||||||||||||||||||||||||
| 725 | 0 | ▶ | if ( defined $self->{mark} && @{$self->{mark}} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"mark"} and @{$self->{"mark"};}
MC/DC0%0/2
defined $self->{"mark"} and @{$self->{"mark"};}
defined $self->{"mark"}
@{$self->{"mark"};}
Truth table0%0/3
A and B
A= defined $self->{"mark"}B= @{$self->{"mark"};}
| |||||||||||||||||||||||||||||||
| 726 | 0 | $mark = [ map { $_ + @pre } @{$self->{mark}} ]; | |||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||
| 729 | 0 | while ( 1 ) { | |||||||||||||||||||||||||||||
| 730 | 0 | my @tmp_prompt; | |||||||||||||||||||||||||||||
| 731 | my $cs; | ||||||||||||||||||||||||||||||
| 732 | 0 | ▶ | if ( defined $self->{cs_label} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 733 | 0 | $cs .= $self->{cs_label}; | |||||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||||
| 735 | 0 | ▶ | if ( @$new_idx ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 736 | 0 | ▶ | $cs .= $self->{cs_begin} . join( $self->{cs_separator}, map { defined $_ ? $_ : '' } @{$available}[@$new_idx] ) . $self->{cs_end}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||
| 738 | elsif ( $self->{all_by_default} ) { | ||||||||||||||||||||||||||||||
| 739 | 0 | $cs .= $self->{cs_begin} . '*' . $self->{cs_end}; | |||||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||||
| 741 | 0 | ▶ | if ( defined $cs ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 742 | 0 | @tmp_prompt = ( $cs ); | |||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||
| 744 | 0 | ▶ | if ( ! defined $self->{prompt} ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 745 | 0 | push @tmp_prompt, 'Your choice:'; | |||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||
| 747 | elsif ( length $self->{prompt} ) { | ||||||||||||||||||||||||||||||
| 748 | 0 | push @tmp_prompt, $self->{prompt}; | |||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||
| 750 | 0 | my $meta_items = [ 0 .. $#pre ]; | |||||||||||||||||||||||||||||
| 751 | 0 | my $prompt = join "\n", @tmp_prompt; | |||||||||||||||||||||||||||||
| 752 | # Choose | ||||||||||||||||||||||||||||||
| 753 | my @idx = choose( | ||||||||||||||||||||||||||||||
| 754 | 0 | ▶ | [ @pre, length( $self->{prefix} ) ? map { $self->{prefix} . ( defined $_ ? $_ : '' ) } @$curr_avail : @$curr_avail ], | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 755 | { alignment => $self->{alignment}, bottom_text => $self->{bottom_text}, busy_string => $self->{busy_string}, | ||||||||||||||||||||||||||||||
| 756 | clear_screen => $self->{clear_screen}, color => $self->{color}, footer => $self->{footer}, | ||||||||||||||||||||||||||||||
| 757 | hide_cursor => $self->{hide_cursor}, include_highlighted => 2, index => 1, info => $self->{info}, | ||||||||||||||||||||||||||||||
| 758 | keep => $self->{keep}, layout => $self->{layout}, margin => $self->{margin}, mark => $mark, | ||||||||||||||||||||||||||||||
| 759 | max_width => $self->{max_width}, meta_items => $meta_items, mouse => $self->{mouse}, | ||||||||||||||||||||||||||||||
| 760 | order => $self->{order}, page => $self->{page}, prompt => $prompt, | ||||||||||||||||||||||||||||||
| 761 | tabs_bottom_text => $self->{tabs_bottom_text}, tabs_info => $self->{tabs_info}, | ||||||||||||||||||||||||||||||
| 762 | tabs_prompt => $self->{tabs_prompt}, undef => $self->{back} } | ||||||||||||||||||||||||||||||
| 763 | 0 | ▶ | ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 764 | 0 | $mark = undef; | |||||||||||||||||||||||||||||
| 765 | 0 | ▶ | if ( ! defined $idx[0] || $idx[0] == 0 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $idx[0] or $idx[0] == 0
MC/DC0%0/2
not defined $idx[0] or $idx[0] == 0
not defined $idx[0]
$idx[0] == 0
Truth table0%0/3
not(A) or B
A= not defined $idx[0]B= $idx[0] == 0
| |||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | if ( @$bu ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 767 | 0 | ( $curr_avail, $new_idx ) = @{pop @$bu}; | |||||||||||||||||||||||||||||
| 768 | 0 | next; | |||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||
| 770 | 0 | $self->__restore_defaults(); | |||||||||||||||||||||||||||||
| 771 | 0 | return; | |||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||
| 773 | 0 | push @$bu, [ [ @$curr_avail ], [ @$new_idx ] ]; | |||||||||||||||||||||||||||||
| 774 | 0 | my $ok; | |||||||||||||||||||||||||||||
| 775 | 0 | ▶ | if ( $idx[0] == $#pre ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 776 | 0 | $ok = shift @idx; | |||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||
| 778 | 0 | my @tmp_idx; | |||||||||||||||||||||||||||||
| 779 | 0 | for my $i ( reverse @idx ) { | |||||||||||||||||||||||||||||
| 780 | 0 | $i -= @pre; | |||||||||||||||||||||||||||||
| 781 | 0 | ▶ | if ( ! $self->{keep_chosen} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 782 | 0 | splice( @$curr_avail, $i, 1 ); | |||||||||||||||||||||||||||||
| 783 | 0 | for my $used_i ( sort { $a <=> $b } @$new_idx ) { | |||||||||||||||||||||||||||||
| 784 | 0 | ▶ | last if $used_i > $i; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 785 | 0 | ++$i; | |||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||
| 788 | 0 | push @tmp_idx, $i; | |||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||
| 790 | 0 | push @$new_idx, reverse @tmp_idx; | |||||||||||||||||||||||||||||
| 791 | 0 | ▶ | if ( $ok ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 792 | 0 | ▶ | if ( ! @$new_idx && $self->{all_by_default} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not @$new_idx and $self->{"all_by_default"}
MC/DC0%0/2
not @$new_idx and $self->{"all_by_default"}
not @$new_idx
$self->{"all_by_default"}
Truth table0%0/3
not(A) and B
A= not @$new_idxB= $self->{"all_by_default"}
| |||||||||||||||||||||||||||||||
| 793 | 0 | $new_idx = [ 0 .. $#{$available} ]; | |||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||
| 795 | 0 | my $return_indexes = $self->{index}; # because __restore_defaults resets $self->{index} | |||||||||||||||||||||||||||||
| 796 | 0 | $self->__restore_defaults(); | |||||||||||||||||||||||||||||
| 797 | 0 | ▶ | return $return_indexes ? $new_idx : [ @{$available}[@$new_idx] ]; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||
| 803 | 0 | ▶ | sub settings_menu { | ||||||||||||||||||||||||||||
|
Subroutine
settings_menu: not called CC=25 SCAR=64.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | if ( ref $_[0] ne __PACKAGE__ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 805 | 0 | my $ob = __PACKAGE__->new(); | |||||||||||||||||||||||||||||
| 806 | 0 | delete $ob->{backup_instance_defaults}; | |||||||||||||||||||||||||||||
| 807 | 0 | return $ob->settings_menu( @_ ); | |||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||
| 809 | 0 | my ( $self, $menu, $curr, $opt ) = @_; | |||||||||||||||||||||||||||||
| 810 | 0 | $self->__prepare_opt( $opt ); | |||||||||||||||||||||||||||||
| 811 | 0 | my $longest = 0; | |||||||||||||||||||||||||||||
| 812 | 0 | my $new = {}; | |||||||||||||||||||||||||||||
| 813 | 0 | my $name_w = {}; | |||||||||||||||||||||||||||||
| 814 | 0 | for my $sub ( @$menu ) { | |||||||||||||||||||||||||||||
| 815 | 0 | my ( $key, $name, $values ) = @$sub; | |||||||||||||||||||||||||||||
| 816 | 0 | $name_w->{$key} = print_columns_ext( $name, $self->{color} ); | |||||||||||||||||||||||||||||
| 817 | 0 | ▶ | if ( $name_w->{$key} > $longest ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 818 | 0 | $longest = $name_w->{$key}; | |||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | $curr->{$key} = 0 if ! defined $curr->{$key}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 821 | 0 | ▶ | $curr->{$key} = 0 if $curr->{$key} > $#$values; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | $curr->{$key} = 0 if ! defined $values->[$curr->{$key}]; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | while ( ! defined $values->[$curr->{$key}] ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 825 | 0 | ++$curr->{$key}; | |||||||||||||||||||||||||||||
| 826 | 0 | ▶ | if ( $curr->{$key} > $#$values ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 827 | 0 | $curr->{$key} = 0; | |||||||||||||||||||||||||||||
| 828 | 0 | last; | |||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||
| 831 | 0 | $new->{$key} = $curr->{$key}; | |||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||
| 833 | 0 | my @print_keys; | |||||||||||||||||||||||||||||
| 834 | 0 | for my $sub ( @$menu ) { | |||||||||||||||||||||||||||||
| 835 | 0 | my ( $key, $name, $values ) = @$sub; | |||||||||||||||||||||||||||||
| 836 | 0 | ▶ | my $current = $values->[$new->{$key}] // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$$values[$new->{$key}] // ""
MC/DC0%0/1
$$values[$new->{$key}] // ""
$$values[$new->{$key}]
Truth table0%0/2
A
A= $$values[$new->{$key}]
| |||||||||||||||||||||||||||||||
| 837 | 0 | push @print_keys, $name . ( ' ' x ( $longest - $name_w->{$key} ) ) . " [$current]"; | |||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||
| 839 | 0 | my @pre = ( undef, $self->{confirm} ); | |||||||||||||||||||||||||||||
| 840 | 0 | $ENV{TC_RESET_AUTO_UP} = 0; | |||||||||||||||||||||||||||||
| 841 | 0 | my $default = 0; | |||||||||||||||||||||||||||||
| 842 | 0 | my $count = 0; | |||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||
| 844 | 0 | while ( 1 ) { | |||||||||||||||||||||||||||||
| 845 | 0 | my @tmp_prompt; | |||||||||||||||||||||||||||||
| 846 | 0 | ▶ | if ( defined $self->{cs_label} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 847 | 0 | push @tmp_prompt, $self->{cs_label} . $self->{cs_begin} . join( $self->{cs_separator}, map { "$_=$new->{$_}" } keys %$new ) . $self->{cs_end}; | |||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||
| 849 | 0 | ▶ | if ( ! defined $self->{prompt} ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 850 | 0 | push @tmp_prompt, 'Your choice:'; | |||||||||||||||||||||||||||||
| 851 | } | ||||||||||||||||||||||||||||||
| 852 | elsif ( length $self->{prompt} ) { | ||||||||||||||||||||||||||||||
| 853 | 0 | push @tmp_prompt, $self->{prompt}; | |||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||
| 855 | 0 | my $prompt = join( "\n", @tmp_prompt ); | |||||||||||||||||||||||||||||
| 856 | # Choose | ||||||||||||||||||||||||||||||
| 857 | my $idx = choose( | ||||||||||||||||||||||||||||||
| 858 | [ @pre, @print_keys ], | ||||||||||||||||||||||||||||||
| 859 | { alignment => 0, bottom_text => $self->{bottom_text}, clear_screen => $self->{clear_screen}, | ||||||||||||||||||||||||||||||
| 860 | color => $self->{color}, default => $default, footer => $self->{footer}, | ||||||||||||||||||||||||||||||
| 861 | hide_cursor => $self->{hide_cursor}, index => 1, info => $self->{info}, keep => $self->{keep}, | ||||||||||||||||||||||||||||||
| 862 | layout => 2, margin => $self->{margin}, max_width => $self->{max_width}, mouse => $self->{mouse}, | ||||||||||||||||||||||||||||||
| 863 | page => $self->{page}, prompt => $prompt, tabs_bottom_text => $self->{tabs_bottom_text}, | ||||||||||||||||||||||||||||||
| 864 | tabs_info => $self->{tabs_info}, tabs_prompt => $self->{tabs_prompt}, undef => $self->{back} } | ||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||
| 866 | 0 | ); | |||||||||||||||||||||||||||||
| 867 | 0 | ▶ | if ( ! $idx ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 868 | 0 | $self->__restore_defaults(); | |||||||||||||||||||||||||||||
| 869 | 0 | return; | |||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||
| 871 | elsif ( $idx == $#pre ) { | ||||||||||||||||||||||||||||||
| 872 | 0 | my $change = 0; | |||||||||||||||||||||||||||||
| 873 | 0 | for my $sub ( @$menu ) { | |||||||||||||||||||||||||||||
| 874 | 0 | my $key = $sub->[0]; | |||||||||||||||||||||||||||||
| 875 | 0 | ▶ | if ( $curr->{$key} == $new->{$key} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 876 | 0 | next; | |||||||||||||||||||||||||||||
| 877 | } | ||||||||||||||||||||||||||||||
| 878 | 0 | $curr->{$key} = $new->{$key}; | |||||||||||||||||||||||||||||
| 879 | 0 | $change++; | |||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||
| 881 | 0 | $self->__restore_defaults(); | |||||||||||||||||||||||||||||
| 882 | 0 | return $change; # | |||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||
| 884 | 0 | my $i = $idx - @pre; | |||||||||||||||||||||||||||||
| 885 | 0 | my $key = $menu->[$i][0]; | |||||||||||||||||||||||||||||
| 886 | 0 | my $values = $menu->[$i][2]; | |||||||||||||||||||||||||||||
| 887 | 0 | ▶ | if ( $default == $idx ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 888 | 0 | ▶ | if ( $ENV{TC_RESET_AUTO_UP} ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 889 | 0 | $count = 0; | |||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||
| 891 | elsif ( $count == @$values ) { | ||||||||||||||||||||||||||||||
| 892 | 0 | $default = 0; | |||||||||||||||||||||||||||||
| 893 | 0 | $count = 0; | |||||||||||||||||||||||||||||
| 894 | 0 | next; | |||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||
| 897 | else { | ||||||||||||||||||||||||||||||
| 898 | 0 | $count = 0; | |||||||||||||||||||||||||||||
| 899 | 0 | $default = $idx; | |||||||||||||||||||||||||||||
| 900 | } | ||||||||||||||||||||||||||||||
| 901 | 0 | ▶ | my $curr_value = $values->[$new->{$key}] // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$$values[$new->{$key}] // ""
MC/DC0%0/1
$$values[$new->{$key}] // ""
$$values[$new->{$key}]
Truth table0%0/2
A
A= $$values[$new->{$key}]
| |||||||||||||||||||||||||||||||
| 902 | 0 | my $new_value; | |||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||
| 904 | 0 | while ( 1 ) { | |||||||||||||||||||||||||||||
| 905 | 0 | ++$count; | |||||||||||||||||||||||||||||
| 906 | 0 | ▶ | if ( ++$new->{$key} > $#$values ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 907 | 0 | $new->{$key} = 0; | |||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||
| 909 | 0 | $new_value = $values->[$new->{$key}]; | |||||||||||||||||||||||||||||
| 910 | 0 | ▶ | if ( defined $new_value ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 911 | 0 | last; | |||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||||
| 913 | 0 | ▶ | if ( $count == @$values ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 914 | 0 | $new_value = ''; | |||||||||||||||||||||||||||||
| 915 | 0 | last; | |||||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||
| 918 | 0 | $print_keys[$i] =~ s/ \[ \Q$curr_value\E \] \z /[$new_value]/x; | |||||||||||||||||||||||||||||
| 919 | } | ||||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||
| 924 | 0 | ▶ | sub insert_sep { | ||||||||||||||||||||||||||||
|
Subroutine
insert_sep: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 925 | 0 | my ( $number, $separator ) = @_; | |||||||||||||||||||||||||||||
| 926 | 0 | ▶ | return $number if ! length $number; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 927 | 0 | ▶ | $separator = ',' if ! defined $separator; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 928 | 0 | ▶ | return $number if $separator eq ''; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 929 | 0 | ▶ | return $number if $number =~ /\Q$separator\E/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 930 | 0 | $number =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1$separator/g; | |||||||||||||||||||||||||||||
| 931 | # http://perldoc.perl.org/perlfaq5.html#How-can-I-output-my-numbers-with-commas-added? | ||||||||||||||||||||||||||||||
| 932 | 0 | return $number; | |||||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||
| 936 | 0 | ▶ | sub get_term_size { | ||||||||||||||||||||||||||||
|
Subroutine
get_term_size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 937 | 0 | require Term::Choose::Screen; | |||||||||||||||||||||||||||||
| 938 | 0 | return Term::Choose::Screen::get_term_size(); | |||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||
| 942 | 0 | ▶ | sub get_term_width { | ||||||||||||||||||||||||||||
|
Subroutine
get_term_width: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 943 | 0 | require Term::Choose::Screen; | |||||||||||||||||||||||||||||
| 944 | 0 | my $term_width = ( Term::Choose::Screen::get_term_size() )[0]; | |||||||||||||||||||||||||||||
| 945 | 0 | return $term_width; | |||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||
| 948 | 0 | ▶ | sub get_term_height { | ||||||||||||||||||||||||||||
|
Subroutine
get_term_height: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 949 | 0 | require Term::Choose::Screen; | |||||||||||||||||||||||||||||
| 950 | 0 | my $term_height = ( Term::Choose::Screen::get_term_size() )[1]; | |||||||||||||||||||||||||||||
| 951 | 0 | return $term_height; | |||||||||||||||||||||||||||||
| 952 | } | ||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||
| 955 | 0 | ▶ | sub unicode_sprintf { | ||||||||||||||||||||||||||||
|
Subroutine
unicode_sprintf: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 956 | 0 | my ( $str, $avail_w, $opt ) = @_; | |||||||||||||||||||||||||||||
| 957 | 0 | ▶ | $opt ||= {}; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$opt ||= {}
MC/DC0%0/1
$opt ||= {}
$opt
Truth table0%0/2
A
A= $opt
| |||||||||||||||||||||||||||||||
| 958 | 0 | my @color; | |||||||||||||||||||||||||||||
| 959 | 0 | ▶ | if ( $opt->{color} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 960 | 0 | $str =~ s/${\PH}//g; | |||||||||||||||||||||||||||||
| 961 | 0 | ▶ | $str =~ s/(${\SGR_ES})/push( @color, $1 ) && ${\PH}/ge; | ||||||||||||||||||||||||||||
|
Condition0%0/3
push(@color, $1) && ${\"\x{feff}";}
MC/DC0%0/2
push(@color, $1) && ${\"\x{feff}";}
push(@color, $1)
${\"\x{feff}";}
Truth table0%0/3
A && B
A= push(@color, $1)B= ${\"\x{feff}";}
| |||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||
| 963 | 0 | my $str_w = print_columns( $str ); | |||||||||||||||||||||||||||||
| 964 | 0 | ▶ | if ( $str_w > $avail_w ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 965 | 0 | ▶ | if ( @{$opt->{suffix_on_truncate}||[]} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$opt->{'suffix_on_truncate'} || []
MC/DC0%0/1
$opt->{'suffix_on_truncate'} || []
$opt->{'suffix_on_truncate'}
Truth table0%0/2
A
A= $opt->{'suffix_on_truncate'}
| |||||||||||||||||||||||||||||||
| 966 | 0 | $str = cut_to_printwidth( $str, $avail_w - $opt->{suffix_on_truncate}[1] ) . $opt->{suffix_on_truncate}[0]; | |||||||||||||||||||||||||||||
| 967 | } | ||||||||||||||||||||||||||||||
| 968 | 0 | $str = cut_to_printwidth( $str, $avail_w ); | |||||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||||
| 970 | 0 | ▶ | if ( @color ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 971 | 0 | $str =~ s/${\PH}/shift @color/ge; | |||||||||||||||||||||||||||||
| 972 | 0 | ▶ | if ( @color ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 973 | 0 | $str .= join '', @color; | |||||||||||||||||||||||||||||
| 974 | } | ||||||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||||
| 976 | 0 | ▶ | if ( $str_w < $avail_w ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | if ( $opt->{right_justify} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 978 | 0 | return " " x ( $avail_w - $str_w ) . $str; | |||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||
| 980 | else { | ||||||||||||||||||||||||||||||
| 981 | 0 | return $str . " " x ( $avail_w - $str_w ); | |||||||||||||||||||||||||||||
| 982 | } | ||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||
| 984 | else { | ||||||||||||||||||||||||||||||
| 985 | 0 | return $str; | |||||||||||||||||||||||||||||
| 986 | } | ||||||||||||||||||||||||||||||
| 987 | } | ||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||
| 990 | 0 | ▶ | sub print_columns_ext { | ||||||||||||||||||||||||||||
|
Subroutine
print_columns_ext: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 991 | 0 | my ( $str, $color ) = @_; | |||||||||||||||||||||||||||||
| 992 | 0 | ▶ | if ( $color ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 993 | 0 | $str =~ s/${\SGR_ES}//g; | |||||||||||||||||||||||||||||
| 994 | } | ||||||||||||||||||||||||||||||
| 995 | 0 | return print_columns( $str ); | |||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||
| 1001 | 1 | 1; | |||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||
| 1003 | __END__ | ||||||||||||||||||||||||||||||