blib/lib/Zoidberg/Fish/ReadLine.pm

filter: Statementstmt 15.7% 20 / 127 Branchbran 1.7% 1 / 56 Conditioncond 3.3% 1 / 30 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 20.8% 5 / 24 Podpod 28.5% 2 / 7 totaltotal 10.9% 29 / 264 CC 38 SCAR 44.0
CC
38
Cov
10%
init
272.0
select
42.0
__ANON__
20.0
CRAP 81.7
« blib/lib/Zoidberg/Utils/Output.pm ↑ Summary blib/lib/Zoidberg/Fish.pm »
1 package Zoidberg::Fish::ReadLine;
2  
3 1 our $VERSION = '0.981';
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw/$AUTOLOAD $PS1 $PS2/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Zoidberg::Fish;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 use Zoidberg::Utils
9 1 ▶ qw/:error message debug/; # T:RL:Zoid also has output()
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our @ISA = qw/Zoidberg::Fish/;
12  
13 1 ▶eval 'use Env::PS1 qw/$PS1 $PS2 $RPS1/; 1'
Subroutine BEGIN: called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
eval "use Env::PS1 qw/\$PS1 \$PS2 \$RPS1/; 1" or eval "use Env qw/\$PS1 \$PS2 \$RPS1/; 1" or our($PS1, $PS2, $RPS1) = ("zoid-$Zoidberg::VERSION> ", "> ", undef) 1 0 1
Condition33%1/3
eval "use Env::PS1 qw/\$PS1 \$PS2 \$RPS1/; 1" or eval "use Env qw/\$PS1 \$PS2 \$RPS1/; 1"
l!l&&r!l&&!r
100
MC/DC0%0/2
eval "use Env::PS1 qw/\$PS1 \$PS2 \$RPS1/; 1" or eval "use Env qw/\$PS1 \$PS2 \$RPS1/; 1"
eval "use Env::PS1 qw/\$PS1 \$PS2 \$RPS1/; 1" eval "use Env qw/\$PS1 \$PS2 \$RPS1/; 1"
Truth table33%1/3
A or B
A= eval "use Env::PS1 qw/\$PS1 \$PS2 \$RPS1/; 1"B= eval "use Env qw/\$PS1 \$PS2 \$RPS1/; 1"
ABresult
1X1
011
000
14 or eval 'use Env qw/$PS1 $PS2 $RPS1/; 1'
15 or ( our ($PS1, $PS2, $RPS1) = ("zoid-$Zoidberg::VERSION> ", "> ", undef) );
16  
17 0 ▶sub init {
Subroutine init: not called CC=16 SCAR=56.1
Pod documented
18 0 my $self = shift;
19  
20 # let's see what we have available
21 0 ▶ unless ($ENV{PERL_RL} and $ENV{PERL_RL} !~ /zoid/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"PERL_RL"} and not $ENV{"PERL_RL"} =~ /zoid/i) 0 0 0
Condition0%0/3
$ENV{"PERL_RL"} and not $ENV{"PERL_RL"} =~ /zoid/i
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"PERL_RL"} and not $ENV{"PERL_RL"} =~ /zoid/i
$ENV{"PERL_RL"} not $ENV{"PERL_RL"} =~ /zoid/i
Truth table0%0/3
A and not(B)
A= $ENV{"PERL_RL"}B= not $ENV{"PERL_RL"} =~ /zoid/i
ABresult
0X0
100
111
22 0 eval 'require Term::ReadLine::Zoid';
23 0 ▶ unless ($@) { # load RL zoid
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
24 0 ▶ $ENV{PERL_RL} = 'Zoid' unless defined $ENV{PERL_RL};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"PERL_RL"} 0 0 0
25 0 $ENV{PERL_RL} =~ /^(\S+)/;
26 0 push @ISA, 'Term::ReadLine::'.$1; # could be a subclass of T:RL:Zoid
27 0 $self->_init('zoid');
28 0 @$self{'rl', 'rl_z'} = ($self, 1);
29 0 $$self{config}{PS2} = \$PS2;
30 0 $$self{config}{RPS1} = \$RPS1;
31 # FIXME support RL:Z shell() option
32 # FIXME what if config/PS1 was allready set to a string ?
33 }
34 else {
35 0 debug $@;
36 }
37 }
38  
39 0 ▶ unless ($$self{rl_z}) { # load other RL
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'rl_z'}) { } 0 0 0
40 0 eval 'require Term::ReadLine';
41 0 ▶ error 'No ReadLine available' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
42 0 $$self{rl} = Term::ReadLine->new('zoid');
43 0 $$self{rl_z} = 0;
44 0 message 'Using '.$$self{rl}->ReadLine(). " for input\n"
45 . 'we suggest you use Term::ReadLine::Zoid'; # officially nag-ware now :)
46 0 ▶ if ($$self{rl}->can('GetHistory')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'rl'}->can('GetHistory')) { } 0 0 0
47 0 ▶ *GetHistory = sub { # define more intelligent GetHistory
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 my @hist = $$self{rl}->GetHistory;
49 0 Zoidberg::Utils::output(\@hist);
50 }
51 0 }
52 0 ▶ else { *GetHistory = sub { return wantarray ? () : [] } }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
53 0 ▶ if ($$self{rl}->can('SetHistory')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'rl'}->can('SetHistory')) { } 0 0 0
elsif (my($s) = grep({$self->{'rl'}->can($_);} 'addhistory', 'AddHistory')) { } 0 0 0
54 0 ▶ *SetHistory = sub { # define more intelligent SetHistory
Subroutine __ANON__: not called CC=3 SCAR=24.8
55 0 my ($self, @hist) = @_;
56 0 ▶ @hist = @{$hist[0]} if @hist == 1 and ref $hist[0];
Branch: 1 branch
BranchTrueFalseTotal
if @hist == 1 and ref $hist[0] 0 0 0
Condition0%0/3
@hist == 1 and ref $hist[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@hist == 1 and ref $hist[0]
@hist == 1 ref $hist[0]
Truth table0%0/3
A and B
A= @hist == 1B= ref $hist[0]
ABresult
0X0
100
111
57 0 $$self{rl}->SetHistory(@hist);
58 }
59 0 }
60 0 elsif (my ($s) = grep {$$self{rl}->can($_)} qw/addhistory AddHistory/) {
61 0 ▶ *SetHistory = sub { # define more intelligent SetHistory
Subroutine __ANON__: not called CC=4 SCAR=30.0
62 0 my ($self, @hist) = @_;
63 0 ▶ @hist = @{$hist[0]} if @hist == 1 and ref $hist[0];
Branch: 1 branch
BranchTrueFalseTotal
if @hist == 1 and ref $hist[0] 0 0 0
Condition0%0/3
@hist == 1 and ref $hist[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@hist == 1 and ref $hist[0]
@hist == 1 ref $hist[0]
Truth table0%0/3
A and B
A= @hist == 1B= ref $hist[0]
ABresult
0X0
100
111
64 0 $$self{rl}->$s($_) for @hist;
65 }
66 0 }
67 else {
68 0 ▶ *SetHistory = sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 $$self{no_real_hist}++;
70 }
71  
72 0 ▶ if (my ($s) = grep {$$self{rl}->can($_)} qw/addhistory AddHistory/) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($s) = grep({$self->{'rl'}->can($_);} 'addhistory', 'AddHistory')) { } 0 0 0
73 0 ▶ *AddHistory = sub { $$self{rl}->$s(@_) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
74 0 }
75 0 ▶ else { *AddHistory = sub {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 }
77 0 ▶ else { *GetHistory = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 my $self = shift;
79 0 my $ref = $self->SUPER::GetHistory(@_); # force scalar context
80 0 Zoidberg::Utils::output($ref);
81 0 };
82 }
83
84 ## hook history
85 0 ▶ unless ($$self{no_real_hist}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"no_real_hist"}) 0 0 0
86 0 $self->SetHistory( $$self{shell}->builtin(qw/history --read/) );
87 0 $self->add_events('prompt', 'history_reset');
88 0 $$self{rl}->Attribs->{autohistory} = 0;
89 }
90  
91 ## completion
92 0 ▶ my $compl = $$self{rl_z} ? 'complete' : 'completion_function' ;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'rl_z'} ? : 0 0 0
93 0 ▶ $$self{rl}->Attribs->{completion_function} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 0 return $$self{shell}->builtin($compl, @_);
95 0 };
96  
97 ## Env::PS1
98 0 ▶ $Env::PS1::map{m} ||= sub { $$self{settings}{mode} || '-' };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$self->{"settings"}{"mode"} or "-" 0 0 0
Condition0%0/3
$Env::PS1::map{"m"} ||= sub { $self->{"settings"}{"mode"} or "-"; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$Env::PS1::map{"m"} ||= sub { $self->{"settings"}{"mode"} or "-"; }
$Env::PS1::map{"m"} sub { $self->{"settings"}{"mode"} or "-"; }
Truth table0%0/3
A ||= B
A= $Env::PS1::map{"m"}B= sub { $self->{"settings"}{"mode"} or "-"; }
ABresult
1X1
011
000
99 0 ▶ $Env::PS1::map{j} ||= sub { scalar @{$$self{shell}{jobs}} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$Env::PS1::map{"j"} ||= sub { scalar @{$self->{"shell"}{"jobs"};}; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$Env::PS1::map{"j"} ||= sub { scalar @{$self->{"shell"}{"jobs"};}; }
$Env::PS1::map{"j"} sub { scalar @{$self->{"shell"}{"jobs"};}; }
Truth table0%0/3
A ||= B
A= $Env::PS1::map{"j"}B= sub { scalar @{$self->{"shell"}{"jobs"};}; }
ABresult
1X1
011
000
100 0 ▶ $Env::PS1::map{v} ||= $Zoidberg::VERSION;
Condition0%0/3
$Env::PS1::map{"v"} ||= $Zoidberg::VERSION
l!l&&r!l&&!r
000
MC/DC0%0/2
$Env::PS1::map{"v"} ||= $Zoidberg::VERSION
$Env::PS1::map{"v"} $Zoidberg::VERSION
Truth table0%0/3
A ||= B
A= $Env::PS1::map{"v"}B= $Zoidberg::VERSION
ABresult
1X1
011
000
101 }
102  
103 0 ▶sub wrap_rl {
Subroutine wrap_rl: not called CC=4 SCAR=30.0
Pod undocumented
104 0 my ($self, $prompt, $preput, $cont) = @_;
105 0 ▶ $prompt ||= $$self{rl_z} ? \$PS1 : $PS1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'rl_z'} ? : 0 0 0
Condition0%0/3
$prompt ||= $self->{"rl_z"} ? \$Zoidberg::Fish::ReadLine::PS1 : $Zoidberg::Fish::ReadLine::PS1
l!l&&r!l&&!r
000
MC/DC0%0/2
$prompt ||= $self->{"rl_z"} ? \$Zoidberg::Fish::ReadLine::PS1 : $Zoidberg::Fish::ReadLine::PS1
$prompt $self->{"rl_z"} ? \$Zoidberg::Fish::ReadLine::PS1 : $Zoidberg::Fish::ReadLine::PS1
Truth table0%0/3
A ||= B
A= $promptB= $self->{"rl_z"} ? \$Zoidberg::Fish::ReadLine::PS1 : $Zoidberg::Fish::ReadLine::PS1
ABresult
1X1
011
000
106 0 my $line;
107 {
108 0 ▶ local $SIG{TSTP} = 'DEFAULT' unless $$self{shell}{settings}{login};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"shell"}{"settings"}{"login"} 0 0 0
109 0 $line = $$self{rl}->readline($prompt, $preput);
110 }
111 0 $$self{last_line} = $line;
112 0 Zoidberg::Utils::output($line);
113 }
114  
115 0 ▶sub wrap_rl_more {
Subroutine wrap_rl_more: not called CC=4 SCAR=30.0
Pod undocumented
116 0 my ($self, $prompt, $preput) = @_;
117 0 my $line;
118 0 ▶ if ($$self{rl_z}) { $line = $self->continue() }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'rl_z'}) { } 0 0 0
119 else {
120 0 ▶ $prompt ||= $$self{rl_z} ? \$PS2 : $PS2;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'rl_z'} ? : 0 0 0
Condition0%0/3
$prompt ||= $self->{"rl_z"} ? \$Zoidberg::Fish::ReadLine::PS2 : $Zoidberg::Fish::ReadLine::PS2
l!l&&r!l&&!r
000
MC/DC0%0/2
$prompt ||= $self->{"rl_z"} ? \$Zoidberg::Fish::ReadLine::PS2 : $Zoidberg::Fish::ReadLine::PS2
$prompt $self->{"rl_z"} ? \$Zoidberg::Fish::ReadLine::PS2 : $Zoidberg::Fish::ReadLine::PS2
Truth table0%0/3
A ||= B
A= $promptB= $self->{"rl_z"} ? \$Zoidberg::Fish::ReadLine::PS2 : $Zoidberg::Fish::ReadLine::PS2
ABresult
1X1
011
000
121 0 $line = $$self{last_line} . $self->wrap_rl($prompt, $preput)
122 }
123 0 $$self{last_line} = $line;
124 0 Zoidberg::Utils::output($line);
125 }
126  
127 0 ▶sub prompt { # log on prompt event
Subroutine prompt: not called CC=1 SCAR=6.9
Pod undocumented
128 0 my $self = shift;
129 0 $self->AddHistory( $$self{shell}{previous_cmd} );
130 }
131  
132 0 ▶sub beat {
Subroutine beat: not called CC=2 SCAR=17.9
Pod undocumented
133 0 ▶ $_[0]{shell}->reap_jobs() if $_[0]{settings}{notify};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"settings"}{"notify"} 0 0 0
134 0 $_[0]->broadcast('beat');
135 }
136  
137 0 ▶sub select {
Subroutine select: not called CC=6 SCAR=37.4
Pod documented
138 0 my ($self, @items) = @_;
139 0 ▶ @items = @{$items[0]} if ref $items[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $items[0] 0 0 0
140 0 my $len = length scalar @items;
141 Zoidberg::Utils::message(
142 0 [map { sprintf("%${len}u) ", $_ + 1) . $items[$_] } 0 .. $#items] );
143 0 SELECT_ASK:
144 my $re = $self->ask('#? ');
145 0 ▶ return undef unless $re;
Branch: 1 branch
BranchTrueFalseTotal
unless $re 0 0 0
146 0 ▶ unless ($re =~ /^\d+([,\s]+\d+)*$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($re =~ /^\d+([,\s]+\d+)*$/) 0 0 0
147 0 complain 'Invalid input: '.$re;
148 0 goto SELECT_ASK;
149 }
150 0 my @re = map $items[$_-1], split /\D+/, $re;
151 0 ▶ if (@re > 1 and ! wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (@re > 1 and not wantarray) 0 0 0
Condition0%0/3
@re > 1 and not wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
@re > 1 and not wantarray
@re > 1 not wantarray
Truth table0%0/3
A and not(B)
A= @re > 1B= not wantarray
ABresult
0X0
100
111
152 0 complain 'Please select just one item';
153 0 goto SELECT_ASK;
154 }
155 0 Zoidberg::Utils::output( @re );
156 }
157  
158 0 ▶sub history_reset { # event exported by Log
Subroutine history_reset: not called CC=2 SCAR=17.9
Pod undocumented
159 0 my $self = shift;
160 0 ▶ unless ($$self{no_real_hist}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"no_real_hist"}) 0 0 0
161 0 $self->SetHistory( $$self{shell}->builtin(qw/history --read/) );
162 }
163 }
164  
165 1 our $ERROR_CALLER;
166  
167 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
168 0 my $self = shift;
169 0 $AUTOLOAD =~ s/^.*:://;
170 0 ▶ return if $AUTOLOAD eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $Zoidberg::Fish::ReadLine::AUTOLOAD eq "DESTROY" 0 0 0
171 0 ▶ if ( $$self{rl}->can( $AUTOLOAD ) ) { $$self{rl}->$AUTOLOAD(@_) }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'rl'}->can($Zoidberg::Fish::ReadLine::AUTOLOAD)) { } 0 0 0
172 else {
173 0 local $ERROR_CALLER = 1;
174 0 error "No such method Zoidberg::Fish::ReadLine::$AUTOLOAD()";
175 }
176 }
177  
178 1 1;
179  
180 __END__
« blib/lib/Zoidberg/Utils/Output.pm ↑ Summary blib/lib/Zoidberg/Fish.pm »