| 1 | 3 | ▶ | use 5.008008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Ask::Clui; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '0.015'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Term::Clui 1.65 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Path::Tiny 'path'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | with 'Ask::API'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 0 | STDOUT->autoflush( 1 ); | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub is_usable { | ||||||||||||||||||||||||||
|
Subroutine
is_usable: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | -t STDIN and -t STDOUT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 15 | ▶ | sub quality { | ||||||||||||||||||||||||||
|
Subroutine
quality: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 15 | my ( $self ) = ( shift ); | |||||||||||||||||||||||||||
| 28 | 15 | ▶ | ( -t STDIN and -t STDOUT ) ? 91 : 30; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-t STDIN and -t STDOUT
MC/DC0%0/2
-t STDIN and -t STDOUT
-t STDIN
-t STDOUT
Truth table33%1/3
A and B
A= -t STDINB= -t STDOUT
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub info { | ||||||||||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | my ( $self, %opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||
| 33 | 0 | chomp( my $text = $opts{text} ); | |||||||||||||||||||||||||||
| 34 | 0 | Term::Clui::inform( $opts{text} ); | |||||||||||||||||||||||||||
| 35 | 0 | return; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub warning { | ||||||||||||||||||||||||||
|
Subroutine
warning: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 39 | 0 | my ( $self, %opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||
| 40 | 0 | chomp( my $text = $opts{text} ); | |||||||||||||||||||||||||||
| 41 | 0 | Term::Clui::inform( 'WARNING: ' . $opts{text} ); | |||||||||||||||||||||||||||
| 42 | 0 | return; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | my ( $self, %opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||
| 47 | 0 | chomp( my $text = $opts{text} ); | |||||||||||||||||||||||||||
| 48 | 0 | Term::Clui::inform( 'ERROR: ' . $opts{text} ); | |||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub entry { | ||||||||||||||||||||||||||
|
Subroutine
entry: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 0 | my ( $self, %opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( $opts{hide_text} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | return Term::Clui::ask_password( $opts{text} ); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return Term::Clui::ask( $opts{text}, $opts{default} || '' ); | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{'default'} || ''
MC/DC0%0/1
$opts{'default'} || ''
$opts{'default'}
Truth table0%0/2
A
A= $opts{'default'}
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub question { | ||||||||||||||||||||||||||
|
Subroutine
question: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 0 | my ( $self, %opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||
| 64 | 0 | chomp( my $text = $opts{text} ); | |||||||||||||||||||||||||||
| 65 | 0 | return Term::Clui::confirm( $opts{text} ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my $_choices = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 69 | 0 | my $ref = shift; | |||||||||||||||||||||||||||
| 70 | 0 | map $_->[0], @$ref; | |||||||||||||||||||||||||||
| 71 | 3 | }; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub single_choice { | ||||||||||||||||||||||||||
|
Subroutine
single_choice: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ( $self, %opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||
| 75 | 0 | local $ENV{CLUI_DIR} = 'OFF'; | |||||||||||||||||||||||||||
| 76 | 0 | scalar Term::Clui::choose( $opts{text}, $_choices->( $opts{choices} ) ); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub multiple_choice { | ||||||||||||||||||||||||||
|
Subroutine
multiple_choice: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 0 | my ( $self, %opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||
| 81 | 0 | local $ENV{CLUI_DIR} = 'OFF'; | |||||||||||||||||||||||||||
| 82 | 0 | Term::Clui::choose( $opts{text}, $_choices->( $opts{choices} ) ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub file_selection { | ||||||||||||||||||||||||||
|
Subroutine
file_selection: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 0 | my ( $self, %opts ) = ( shift, @_ ); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my @chosen; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | FILE: { | ||||||||||||||||||||||||||||
| 91 | 0 | my $got = Term::Clui::ask_filename( $opts{text} ); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ( not length $got ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | last FILE if $opts{multiple}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | redo FILE; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | $got = path $got; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ( $opts{existing} and not $got->exists ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"existing"} and not $got->exists
MC/DC0%0/2
$opts{"existing"} and not $got->exists
$opts{"existing"}
not $got->exists
Truth table0%0/3
A and not(B)
A= $opts{"existing"}B= not $got->exists
| |||||||||||||||||||||||||||||
| 101 | 0 | $self->error( text => 'Does not exist.' ); | |||||||||||||||||||||||||||
| 102 | 0 | redo FILE; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ( $opts{directory} and not $got->is_dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"directory"} and not $got->is_dir
MC/DC0%0/2
$opts{"directory"} and not $got->is_dir
$opts{"directory"}
not $got->is_dir
Truth table0%0/3
A and not(B)
A= $opts{"directory"}B= not $got->is_dir
| |||||||||||||||||||||||||||||
| 106 | 0 | $self->error( text => 'Is not a directory.' ); | |||||||||||||||||||||||||||
| 107 | 0 | redo FILE; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | push @chosen, $got; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ( $opts{multiple} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | $self->info( text => 'Enter another file, or leave blank to finish.' ); | |||||||||||||||||||||||||||
| 114 | 0 | redo FILE; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } #/ FILE: | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $opts{multiple} ? @chosen : $chosen[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } #/ sub file_selection | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 3 | 1; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||