Reply/Plugin/ReadLine.pm

filter: Statementstmt 29.6% 24 / 81 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 46.6% 7 / 15 Podpod 50.0% 1 / 2 totaltotal 19.5% 32 / 164 CC 25 SCAR 41.4
CC
25
Cov
18%
new
156.0
DESTROY
56.0
_register_tab_complete
20.0
CRAP 62.8
« Reply/Plugin/Autocomplete/Methods.pm ↑ Summary Reply/App.pm »
1 package Reply::Plugin::ReadLine;
2 1 our $AUTHORITY = 'cpan:DOY';
3 1 $Reply::Plugin::ReadLine::VERSION = '0.42';
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: use Term::ReadLine for user input
7  
8 1 ▶use base 'Reply::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Term::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 0 ▶sub new {
Subroutine new: not called CC=12 SCAR=50.5
Pod undocumented
17 0 my $class = shift;
18 0 my %opts = @_;
19  
20 0 my $self = $class->SUPER::new(@_);
21 0 $self->{term} = Term::ReadLine->new('Reply');
22 0 ▶ my $history = $opts{history_file} || '.reply_history';
Condition0%0/2
$opts{'history_file'} || '.reply_history'
l!l
00
MC/DC0%0/1
$opts{'history_file'} || '.reply_history'
$opts{'history_file'}
Truth table0%0/2
A
A= $opts{'history_file'}
Aresult
11
00
23 0 $history =~ s{^~/}{$ENV{HOME}/};
24 0 ▶ $self->{history_file} = File::Spec->catfile(
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($history) ? : 0 0 0
25 (File::Spec->file_name_is_absolute($history)
26 ? ()
27 : (File::HomeDir->my_data)),
28 $history
29 );
30  
31 0 $self->{rl_gnu} = $self->{term}->ReadLine eq 'Term::ReadLine::Gnu';
32 0 $self->{rl_perl5} = $self->{term}->ReadLine eq 'Term::ReadLine::Perl5';
33 0 $self->{rl_caroline} = $self->{term}->ReadLine eq 'Term::ReadLine::Caroline';
34  
35 0 ▶ if ($self->{rl_perl5}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rl_perl5"}) 0 0 0
36 # output compatible with Term::ReadLine::Gnu
37 0 $readline::rl_scroll_nextline = 0;
38 }
39  
40 0 ▶ if ($self->{rl_perl5} || $self->{rl_gnu} || $self->{rl_caroline}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rl_perl5"} or $self->{"rl_gnu"} or $self->{"rl_caroline"}) 0 0 0
Condition0%0/6
$self->{"rl_perl5"} or $self->{"rl_gnu"} or $self->{"rl_caroline"}
l!l&&r!l&&!r
000
$self->{"rl_perl5"} or $self->{"rl_gnu"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"rl_perl5"} or $self->{"rl_gnu"} or $self->{"rl_caroline"}
$self->{"rl_perl5"} $self->{"rl_gnu"} $self->{"rl_caroline"}
Truth table0%0/4
A or B or C
A= $self->{"rl_perl5"}B= $self->{"rl_gnu"}C= $self->{"rl_caroline"}
ABCresult
1XX1
01X1
0011
0000
41 $self->{term}->StifleHistory($opts{history_length})
42 0 ▶ if defined $opts{history_length} && $opts{history_length} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"history_length"} and $opts{"history_length"} >= 0 0 0 0
Condition0%0/3
defined $opts{"history_length"} and $opts{"history_length"} >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts{"history_length"} and $opts{"history_length"} >= 0
defined $opts{"history_length"} $opts{"history_length"} >= 0
Truth table0%0/3
A and B
A= defined $opts{"history_length"}B= $opts{"history_length"} >= 0
ABresult
0X0
100
111
43 }
44  
45 0 ▶ if (open my $fh, '<', $self->{history_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '<', $self->{'history_file'}) { } 0 0 0
46 0 for my $line (<$fh>) {
47 0 chomp $line;
48 0 $self->{term}->addhistory($line);
49 }
50 }
51 else {
52 0 my $e = $!;
53 warn "Couldn't open $self->{history_file} for reading: $e"
54 0 ▶ if -e $self->{history_file};
Branch: 1 branch
BranchTrueFalseTotal
if -e $self->{"history_file"} 0 0 0
55 }
56  
57 0 $self->_register_tab_complete;
58  
59 0 return $self;
60 }
61  
62 0 ▶sub read_line {
Subroutine read_line: not called CC=1 SCAR=6.9
Pod documented
63 0 my $self = shift;
64 0 my ($next, $prompt) = @_;
65  
66 0 return $self->{term}->readline($prompt);
67 }
68  
69 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=7 SCAR=40.3
70 0 my $self = shift;
71  
72 0 ▶ return if defined $self->{history_length} && $self->{history_length} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"history_length"} and $self->{"history_length"} == 0 0 0 0
Condition0%0/3
defined $self->{"history_length"} and $self->{"history_length"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"history_length"} and $self->{"history_length"} == 0
defined $self->{"history_length"} $self->{"history_length"} == 0
Truth table0%0/3
A and B
A= defined $self->{"history_length"}B= $self->{"history_length"} == 0
ABresult
0X0
100
111
73  
74 # XXX support more later
75 0 ▶ return unless ($self->{rl_gnu} || $self->{rl_perl5} || $self->{rl_caroline});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"rl_gnu"} or $self->{"rl_perl5"} or $self->{"rl_caroline"} 0 0 0
Condition0%0/6
$self->{"rl_gnu"} or $self->{"rl_perl5"} or $self->{"rl_caroline"}
l!l&&r!l&&!r
000
$self->{"rl_gnu"} or $self->{"rl_perl5"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"rl_gnu"} or $self->{"rl_perl5"} or $self->{"rl_caroline"}
$self->{"rl_gnu"} $self->{"rl_perl5"} $self->{"rl_caroline"}
Truth table0%0/4
A or B or C
A= $self->{"rl_gnu"}B= $self->{"rl_perl5"}C= $self->{"rl_caroline"}
ABCresult
1XX1
01X1
0011
0000
76  
77 $self->{term}->WriteHistory($self->{history_file})
78 0 ▶ or warn "Couldn't write history to $self->{history_file}";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"term"}->WriteHistory($self->{"history_file"}) or warn qq[Couldn't write history to $self->{"history_file"}] 0 0 0
79 }
80  
81 0 ▶sub _register_tab_complete {
Subroutine _register_tab_complete: not called CC=4 SCAR=30.0
82 0 my $self = shift;
83  
84 0 my $term = $self->{term};
85  
86 0 weaken(my $weakself = $self);
87  
88 0 ▶ if ($self->{rl_gnu}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rl_gnu"}) 0 0 0
89 0 ▶ $term->Attribs->{attempted_completion_function} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 my ($text, $line, $start, $end) = @_;
91  
92 # discard everything after the cursor for completion purposes
93 0 substr($line, $end) = '';
94  
95 0 my @matches = $weakself->publish('tab_handler', $line);
96 0 my $match_index = 0;
97  
98 0 ▶ return $term->completion_matches($text, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 my ($text, $index) = @_;
100 0 return $matches[$index];
101 0 });
102 0 };
103 }
104  
105 0 ▶ if ($self->{rl_perl5}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rl_perl5"}) 0 0 0
106 0 ▶ $term->Attribs->{completion_function} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
107 0 my ($text, $line, $start) = @_;
108 0 my $end = $start + length($text);
109  
110 # discard everything after the cursor for completion purposes
111 0 substr($line, $end) = '';
112  
113 0 my @matches = $weakself->publish('tab_handler', $line);
114 0 ▶ return scalar(@matches) ? @matches : ();
Branch: 1 branch
BranchTrueFalseTotal
scalar @matches ? : 0 0 0
115 0 };
116 }
117  
118 0 ▶ if ($self->{rl_caroline}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rl_caroline"}) 0 0 0
119 0 ▶ $term->caroline->completion_callback(sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
120 0 my ($line) = @_;
121  
122 0 my @matches = $weakself->publish('tab_handler', $line);
123 # for variable completion, method name completion.
124 0 ▶ if (@matches && $line =~ /\W/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@matches and $line =~ /\W/) 0 0 0
Condition0%0/3
@matches and $line =~ /\W/
!ll&&!rl&&r
000
MC/DC0%0/2
@matches and $line =~ /\W/
@matches $line =~ /\W/
Truth table0%0/3
A and B
A= @matchesB= $line =~ /\W/
ABresult
0X0
100
111
125 0 $line =~ s/[:\w]+\z//;
126 0 @matches = map { $line.$_ } @matches;
127 }
128 0 ▶ return scalar(@matches) ? @matches : ();
Branch: 1 branch
BranchTrueFalseTotal
scalar @matches ? : 0 0 0
129 0 });
130 }
131 }
132  
133 1 1;
134  
135 __END__
« Reply/Plugin/Autocomplete/Methods.pm ↑ Summary Reply/App.pm »