lib/Lingy/ReadLine.pm

filter: Statementstmt 28.8% 17 / 59 Branchbran 5.0% 1 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod n/a totaltotal 26.6% 25 / 94 CC 13 SCAR 32.6
CC
13
Cov
22%
readline
44.4
complete
42.0
END
2.1
CRAP 26.2
« lib/Lingy/Lang/HashMap.pm ↑ Summary lib/Lingy/Lang/Character.pm »
1 34 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::ReadLine;
3  
4 34 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 34 ▶BEGIN { $ENV{PERL_RL} = 'Gnu' }
Subroutine BEGIN: called CC=1 SCAR=0.0
7 34 ▶use Term::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 my $history_file = "$ENV{HOME}/.lingy_history";
10  
11 my $tty;
12 {
13 local @ENV{qw(HOME EDITOR)};
14 local $^W;
15 $tty = Term::ReadLine->new('Lingy');
16 }
17  
18 die "Please install Term::ReadLine::Gnu from CPAN\n"
19 if $tty->ReadLine ne 'Term::ReadLine::Gnu';
20  
21 my $tested = 0;
22 our $input;
23 sub readline {
24 0 ▶ if (my $input = $ENV{LINGY_TEST_INPUT}) {
Subroutine readline: not called CC=7 SCAR=37.9
Branch: 1 branch
BranchTrueFalseTotal
if (my $input = $ENV{"LINGY_TEST_INPUT"}) 0 0 0
25 0 ▶ return if $tested++;
Branch: 1 branch
BranchTrueFalseTotal
if $tested++ 0 0 0
26 0 return $input;
27 }
28  
29 0 my ($continue) = @_;
30  
31 0 ▶ my $prompt = RT->current_ns_name or die;
Branch: 1 branch
BranchTrueFalseTotal
my $prompt = "Lingy::Lang::RT"->current_ns_name or die 0 0 0
32 0 ▶ if ($continue) {
Branch: 1 branch
BranchTrueFalseTotal
if ($continue) { } 0 0 0
33 34 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 0 $prompt = (' ' x (length($prompt) - 2)) . '#_';
35 }
36 else {
37 0 $input = '';
38 }
39 0 $prompt .= '=> ';
40  
41 0 $tty->ornaments(0);
42  
43 local $SIG{INT} = sub {
44 0 ▶ print("\n");
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 $tty->replace_line('', 0);
46 0 $tty->on_new_line;
47 0 $tty->redisplay;
48 0 };
49  
50 0 $tty->parse_and_bind($_) for (
51 'set blink-matching-paren on',
52 'set show-all-if-ambiguous on',
53 );
54  
55 0 $tty->Attribs->{completion_query_items} = 1000;
56 0 $tty->Attribs->{completion_function} = \&complete;
57  
58 0 my $line = $tty->readline($prompt);
59 0 ▶ return unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
60 0 $input .= $line;
61 0 return $line;
62 }
63  
64 sub complete {
65 0 ▶ my ($text, $line, $start) = @_;
Subroutine complete: not called CC=6 SCAR=37.4
66  
67 0 ▶ if ($text =~ m{^(\w+(\.\w+)*)/}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ m[^(\w+(\.\w+)*)/]) 0 0 0
68 0 my $prefix = $1;
69 0 ▶ if (my $ns = RT->namespaces->{$prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ns = "Lingy::Lang::RT"->namespaces->{$prefix}) 0 0 0
70 0 return map "$prefix/$_", keys %$ns;
71 }
72 # if (defined (my $class = RT->classes->{$prefix})) {
73 # return map "$prefix/$_", $class->_method_names;
74 # }
75 0 return;
76 }
77  
78 0 my $space = RT->env->space;
79 my @names =
80 0 grep {not /^ /} (
81 keys(%$space),
82 0 keys(%{RT->namespaces}),
83 0 keys(%{RT->ns_refers->{$space->NAME}}),
84 map {
85 0 my $name = $_;
86 0 $name =~ s/::/./g;
87 0 $name =~ s/^Lingy\.Lang\./lingy.lang./;
88 0 my $long = $name;
89 0 $name =~ s/.*\.//;
90 0 ($long, $name);
91 0 } @{RT->class_names},
92 );
93  
94 grep /^\Q$text/,
95 map {
96 0 ▶ /^-\w/ ? () :
Branch: 2 branches
BranchTrueFalseTotal
/^-\w/ ? : 0 0 0
$text eq '' && /^(\w+\.)/ ? : 0 0 0
Condition0%0/3
$text eq "" and /^(\w+\.)/
!ll&&!rl&&r
000
MC/DC0%0/2
$text eq "" and /^(\w+\.)/
$text eq "" /^(\w+\.)/
Truth table0%0/3
A and B
A= $text eq ""B= /^(\w+\.)/
ABresult
0X0
100
111
97 ($text eq '' and /^(\w+\.)/) ? $1 :
98 $_
99 } (
100 @names,
101 Lingy::Eval->special_symbols,
102 );
103 }
104  
105 $tty->ReadHistory($history_file);
106  
107 END {
108 $tty->WriteHistory($history_file)
109 34 ▶ unless $ENV{LINGY_TEST};
Subroutine END: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"LINGY_TEST"} 34 0 34
110 }
111  
112 1;
« lib/Lingy/Lang/HashMap.pm ↑ Summary lib/Lingy/Lang/Character.pm »