Ask/Clui.pm

filter: Statementstmt 35.5% 27 / 76 Branchbran 5.5% 1 / 18 Conditioncond 9.0% 1 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 42.1% 8 / 19 Podpod 0.0% 0 / 11 totaltotal 26.0% 37 / 142 CC 14 SCAR 33.3
CC
14
Cov
28%
file_selection
90.0
entry
12.0
is_usable
6.0
CRAP 27.9
« Ask/Caroline.pm ↑ Summary Ask.pm »
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
BranchTrueFalseTotal
-t STDIN and -t STDOUT 0 0 0
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
BranchTrueFalseTotal
-t STDIN && -t STDOUT ? : 0 15 15
Condition33%1/3
-t STDIN and -t STDOUT
!ll&&!rl&&r
1500
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($opts{"hide_text"}) 0 0 0
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'} || ''
l!l
00
MC/DC0%0/1
$opts{'default'} || ''
$opts{'default'}
Truth table0%0/2
A
A= $opts{'default'}
Aresult
11
00
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
BranchTrueFalseTotal
unless (length $got) 0 0 0
94 0 ▶ last FILE if $opts{multiple};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"multiple"} 0 0 0
95 0 redo FILE;
96 }
97
98 0 $got = path $got;
99
100 0 ▶ if ( $opts{existing} and not $got->exists ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"existing"} and not $got->exists) 0 0 0
Condition0%0/3
$opts{"existing"} and not $got->exists
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($opts{"directory"} and not $got->is_dir) 0 0 0
Condition0%0/3
$opts{"directory"} and not $got->is_dir
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($opts{"multiple"}) 0 0 0
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
BranchTrueFalseTotal
$opts{'multiple'} ? : 0 0 0
119 } #/ sub file_selection
120  
121 3 1;
122  
123 __END__
« Ask/Caroline.pm ↑ Summary Ask.pm »