Raps2/UI.pm

filter: Statementstmt 26.7% 19 / 71 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 46.1% 6 / 13 Podpod 100% 7 / 7 totaltotal 26.8% 32 / 119 CC 13 SCAR 23.6
CC
13
Cov
20%
read_pw
20.0
to_clipboard
20.0
list
12.0
CRAP 10.6
↑ Summary Raps2.pm »
1 package App::Raps2::UI;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Carp qw(cluck confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Term::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.54';
12  
13 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
14 0 my ($obj) = @_;
15  
16 0 my $ref = {};
17  
18 0 return bless( $ref, $obj );
19 }
20  
21 0 ▶sub list {
Subroutine list: not called CC=3 SCAR=24.8
Pod documented
22 0 my ( $self, @list ) = @_;
23  
24 0 my $format = "%-20s %-20s %s\n";
25  
26 0 ▶ if ( not $self->{list}->{header} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"list"}{"header"}) 0 0 0
27 0 printf( $format, map { $_->[0] } @list );
28 0 $self->{list}->{header} = 1;
29 }
30 0 ▶ printf( $format, map { $_->[1] // q{} } @list );
Condition0%0/2
$_->[1] // ""
l!l
00
MC/DC0%0/1
$_->[1] // ""
$_->[1]
Truth table0%0/2
A
A= $_->[1]
Aresult
11
00
31  
32 0 return 1;
33 }
34  
35 0 ▶sub read_line {
Subroutine read_line: not called CC=2 SCAR=17.9
Pod documented
36 0 my ( $self, $str, $pre ) = @_;
37  
38 # Term::ReadLine->new() takes quite long but is not always required.
39 # So create it here (if needed) instead of in ->new
40 0 ▶ if ( not $self->{term_readline} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"term_readline"}) 0 0 0
41 0 $self->{term_readline} = Term::ReadLine->new('App::Raps2');
42 }
43  
44 0 my $input = $self->{term_readline}->readline( "${str}: ", $pre );
45  
46 0 return $input;
47 }
48  
49 0 ▶sub read_multiline {
Subroutine read_multiline: not called CC=2 SCAR=17.9
Pod documented
50 0 my ( $self, $str ) = @_;
51  
52 0 my $in;
53  
54 0 say "${str} (^D or empty line to quit)";
55  
56 0 ▶ while ( my $line = $self->read_line('multiline') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $self->read_line("multiline")) 0 0 0
57 0 $in .= "${line}\n";
58 }
59  
60 0 return $in;
61 }
62  
63 0 ▶sub read_pw {
Subroutine read_pw: not called CC=4 SCAR=30.0
Pod documented
64 0 my ( $self, $str, $verify ) = @_;
65  
66 0 my ( $in1, $in2 );
67 0 my $term = POSIX::Termios->new();
68  
69 0 $term->getattr(0);
70 0 $term->setlflag( $term->getlflag() & ~POSIX::ECHO );
71 0 $term->setattr( 0, POSIX::TCSANOW );
72  
73 0 print "${str}: ";
74 0 $in1 = readline(STDIN);
75 0 print "\n";
76  
77 0 ▶ if ($verify) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verify) 0 0 0
78 0 print 'Verify: ';
79 0 $in2 = readline(STDIN);
80 0 print "\n";
81 }
82  
83 0 $term->setlflag( $term->getlflag() | POSIX::ECHO );
84 0 $term->setattr( 0, POSIX::TCSANOW );
85  
86 0 ▶ if ( $verify and $in1 ne $in2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verify and $in1 ne $in2) 0 0 0
Condition0%0/3
$verify and $in1 ne $in2
!ll&&!rl&&r
000
MC/DC0%0/2
$verify and $in1 ne $in2
$verify $in1 ne $in2
Truth table0%0/3
A and B
A= $verifyB= $in1 ne $in2
ABresult
0X0
100
111
87 0 confess('Input lines did not match');
88 }
89  
90 0 chomp $in1;
91  
92 0 return $in1;
93 }
94  
95 0 ▶sub to_clipboard {
Subroutine to_clipboard: not called CC=4 SCAR=30.0
Pod documented
96 0 my ( $self, $str, $cmd ) = @_;
97  
98 0 ▶ $cmd //= 'xclip -l 1';
Condition0%0/2
$cmd //= "xclip -l 1"
l!l
00
MC/DC0%0/1
$cmd //= "xclip -l 1"
$cmd
Truth table0%0/2
A
A= $cmd
Aresult
11
00
99  
100 0 ▶ open( my $clipboard, q{|-}, $cmd )
Branch: 1 branch
BranchTrueFalseTotal
open my $clipboard, "|-", $cmd or return 0 0 0
101 or return;
102  
103 0 print $clipboard $str;
104  
105 0 ▶ close($clipboard)
Branch: 1 branch
BranchTrueFalseTotal
close $clipboard or cluck("Failed to close pipe to ${cmd}: $!") 0 0 0
106 or cluck("Failed to close pipe to ${cmd}: ${!}");
107  
108 0 return 1;
109 }
110  
111 0 ▶sub output {
Subroutine output: not called CC=3 SCAR=24.8
Pod documented
112 0 my ( $self, @out ) = @_;
113  
114 0 for my $pair (@out) {
115 0 ▶ printf( "%-8s : %s\n", $pair->[0], $pair->[1] // q{}, );
Condition0%0/2
$pair->[1] // ""
l!l
00
MC/DC0%0/1
$pair->[1] // ""
$pair->[1]
Truth table0%0/2
A
A= $pair->[1]
Aresult
11
00
116 }
117  
118 0 return 1;
119 }
120  
121 1 1;
122  
123 __END__
↑ Summary Raps2.pm »