| 1 | 56 | ▶ | 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 | 56 | ▶ | use Lingy::Common; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 56 | ▶ | BEGIN { $ENV{PERL_RL} = 'Gnu' } | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 56 | ▶ | use Term::ReadLine; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 56 | my $home = $ENV{HOME}; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub history_file { | ||||||||||||||||||||||||||||||
|
Subroutine
history_file: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 12 | 0 | my $history_file = "$ENV{PWD}/.lingy_history"; | |||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | $history_file = "$home/.lingy_history" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 14 | unless -w $history_file; | ||||||||||||||||||||||||||||||||
| 15 | 0 | return $history_file; | |||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 56 | my $tty; | |||||||||||||||||||||||||||||||
| 19 | 56 | my $tested = 0; | |||||||||||||||||||||||||||||||
| 20 | 56 | my @input; | |||||||||||||||||||||||||||||||
| 21 | 56 | my $prev_input = ''; | |||||||||||||||||||||||||||||||
| 22 | 56 | my $sep = "\x01"; | |||||||||||||||||||||||||||||||
| 23 | 56 | my $readline_class; | |||||||||||||||||||||||||||||||
| 24 | 56 | my $multi = 0; | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub multi_start {} | ||||||||||||||||||||||||||||||
|
Subroutine
multi_start: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub multi_stop {} | ||||||||||||||||||||||||||||||
|
Subroutine
multi_stop: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 56 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 30 | 56 | my ($class) = @_; | |||||||||||||||||||||||||||||||
| 31 | 56 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub setup { | ||||||||||||||||||||||||||||||
|
Subroutine
setup: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 35 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 0 | local @ENV{qw(HOME EDITOR)}; | |||||||||||||||||||||||||||||||
| 38 | 0 | local $^W; | |||||||||||||||||||||||||||||||
| 39 | 0 | undef $tty; | |||||||||||||||||||||||||||||||
| 40 | 0 | $tty = Term::ReadLine->new('Lingy'); | |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | die "Please install Term::ReadLine::Gnu from CPAN\n" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | if $tty->ReadLine ne 'Term::ReadLine::Gnu'; | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 0 | $tty->ReadHistory($self->history_file); | |||||||||||||||||||||||||||||||
| 46 | $tty->SetHistory( | ||||||||||||||||||||||||||||||||
| 47 | map { | ||||||||||||||||||||||||||||||||
| 48 | 0 | s/$sep/\n/g; $prev_input = $_; | |||||||||||||||||||||||||||||||
| 49 | } $tty->GetHistory | ||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||
| 51 | 0 | $tty->MinLine(undef); | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $SIG{TSTP} = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 57 | 0 | warn "\nCTL-Z disabled in this REPL\n"; | |||||||||||||||||||||||||||||||
| 58 | 56 | }; | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub input { | ||||||||||||||||||||||||||||||
|
Subroutine
input: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return unless @input; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 0 | my $input = join "\n", @input; | |||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($input =~ s/\ +\z//) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | 0 | $input =~ s/\n/ /g; | |||||||||||||||||||||||||||||||
| 65 | 0 | $input =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($input =~ /\S/ and $input ne $prev_input) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$input =~ /\S/ and $input ne $prev_input
MC/DC0%0/2
$input =~ /\S/ and $input ne $prev_input
$input =~ /\S/
$input ne $prev_input
Truth table0%0/3
A and B
A= $input =~ /\S/B= $input ne $prev_input
| |||||||||||||||||||||||||||||||||
| 68 | 0 | $tty->addhistory($input); | |||||||||||||||||||||||||||||||
| 69 | 0 | $prev_input = $input; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | 0 | return $input; | |||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub readline { | ||||||||||||||||||||||||||||||
|
Subroutine
readline: not called CC=11 SCAR=47.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if (my $test_input = $ENV{LINGY_TEST_INPUT}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | return if $tested++; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | 0 | return $test_input; | |||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 0 | my ($self, $continue) = @_; | |||||||||||||||||||||||||||||||
| 81 | 0 | $readline_class = ref($self); | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $prompt = RT->current_ns_name or die; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($continue) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 56 | ▶ | no warnings 'numeric'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 86 | 0 | $prompt = (' ' x (length($prompt) - 2)) . '#_'; | |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||||||
| 89 | 0 | @input = (); | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | 0 | $prompt .= '=> '; | |||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 0 | $tty->ornaments(0); | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | local $SIG{INT} = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 96 | 0 | print("\n"); | |||||||||||||||||||||||||||||||
| 97 | 0 | $tty->replace_line('', 0); | |||||||||||||||||||||||||||||||
| 98 | 0 | $tty->on_new_line; | |||||||||||||||||||||||||||||||
| 99 | 0 | $tty->redisplay; | |||||||||||||||||||||||||||||||
| 100 | 0 | }; | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 0 | $tty->parse_and_bind($_) for ( | |||||||||||||||||||||||||||||||
| 103 | 'set blink-matching-paren on', | ||||||||||||||||||||||||||||||||
| 104 | 'set show-all-if-ambiguous on', | ||||||||||||||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | 0 | $tty->Attribs->{completion_query_items} = 1000; | |||||||||||||||||||||||||||||||
| 108 | 0 | $tty->Attribs->{completion_function} = \&complete; | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | my $line = $tty->readline($prompt); | |||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return unless defined $line; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | $line =~ s/\s+\z// unless $line =~ /\ +\z/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 113 | 0 | push @input, $line; | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($self->multi_start($line)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | 0 | $prompt = (' ' x (length($prompt) - 5)) . '#_=> '; | |||||||||||||||||||||||||||||||
| 117 | 0 | while (1) { | |||||||||||||||||||||||||||||||
| 118 | 0 | my $more = $tty->readline($prompt); | |||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return unless defined $more; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 120 | 0 | push @input, $more; | |||||||||||||||||||||||||||||||
| 121 | 0 | $line .= "\n$more"; | |||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | last if $self->multi_stop($more); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | 0 | return $line; | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub complete { | ||||||||||||||||||||||||||||||
|
Subroutine
complete: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 130 | 0 | my ($text, $line, $start) = @_; | |||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($text =~ m{^(\w+(\.\w+)*)/}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | 0 | my $prefix = $1; | |||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if (my $ns = RT->namespaces->{$prefix}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 135 | 0 | return map "$prefix/$_", keys %$ns; | |||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||
| 137 | 0 | return; | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 0 | my $space = RT->env->{space}; | |||||||||||||||||||||||||||||||
| 141 | my @names = | ||||||||||||||||||||||||||||||||
| 142 | 0 | grep {not /^ /} ( | |||||||||||||||||||||||||||||||
| 143 | keys(%$space), | ||||||||||||||||||||||||||||||||
| 144 | 0 | keys(%{RT->namespaces}), | |||||||||||||||||||||||||||||||
| 145 | map { | ||||||||||||||||||||||||||||||||
| 146 | 0 | my $name = $_; | |||||||||||||||||||||||||||||||
| 147 | 0 | $name =~ s/^Lingy::/lingy.lang./; | |||||||||||||||||||||||||||||||
| 148 | 0 | $name =~ s/::/./g; | |||||||||||||||||||||||||||||||
| 149 | 0 | my $long = $name; | |||||||||||||||||||||||||||||||
| 150 | 0 | $name =~ s/.*\.//; | |||||||||||||||||||||||||||||||
| 151 | 0 | ($long, $name); | |||||||||||||||||||||||||||||||
| 152 | 0 | } @{RT->class_names}, | |||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | grep /^\Q$text/, | ||||||||||||||||||||||||||||||||
| 156 | map { | ||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | /^-\w/ ? () : | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$text eq "" and /^(\w+\.)/
MC/DC0%0/2
$text eq "" and /^(\w+\.)/
$text eq ""
/^(\w+\.)/
Truth table0%0/3
A and B
A= $text eq ""B= /^(\w+\.)/
| |||||||||||||||||||||||||||||||||
| 158 | ($text eq '' and /^(\w+\.)/) ? $1 : | ||||||||||||||||||||||||||||||||
| 159 | $_ | ||||||||||||||||||||||||||||||||
| 160 | } ( | ||||||||||||||||||||||||||||||||
| 161 | @names, | ||||||||||||||||||||||||||||||||
| 162 | Lingy::Evaluator->special_symbols, | ||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 56 | ▶ | END { | ||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=3 SCAR=19.8
| |||||||||||||||||||||||||||||||||
| 167 | 56 | ▶ | if ($readline_class) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 168 | 0 | $tty->SetHistory(map { s/\n/$sep/g; $_ } $tty->GetHistory); | |||||||||||||||||||||||||||||||
| 169 | $tty->WriteHistory($readline_class->history_file) | ||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | unless $ENV{LINGY_TEST}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | 56 | 1; | |||||||||||||||||||||||||||||||