| Filename | /usr/local/perls/perl-5.26.1/lib/5.26.1/Term/ReadLine.pm |
| Statements | Executed 167 statements in 20.4s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 4 | 1 | 1 | 20.4s | 20.4s | Term::ReadLine::Tk::CORE:readline (opcode) |
| 3 | 1 | 1 | 5.06ms | 49.0ms | Term::ReadLine::TermCap::LoadTermCap |
| 4 | 1 | 1 | 277µs | 20.4s | Term::ReadLine::Tk::get_line |
| 4 | 1 | 1 | 223µs | 20.4s | Term::ReadLine::Stub::readline |
| 8 | 2 | 1 | 215µs | 279µs | Term::ReadLine::Stub::CORE:print (opcode) |
| 3 | 3 | 2 | 179µs | 49.3ms | Term::ReadLine::TermCap::ornaments |
| 3 | 3 | 1 | 86µs | 86µs | Term::ReadLine::Stub::CORE:open (opcode) |
| 1 | 1 | 1 | 75µs | 49.3ms | Term::ReadLine::Stub::new |
| 1 | 1 | 1 | 59µs | 77µs | CPAN::BEGIN@201 |
| 4 | 1 | 1 | 57µs | 57µs | Term::ReadLine::Tk::CORE:print (opcode) |
| 1 | 1 | 1 | 35µs | 79µs | Term::ReadLine::Stub::findConsole |
| 1 | 1 | 1 | 17µs | 17µs | Term::ReadLine::Stub::CORE:ftis (opcode) |
| 3 | 3 | 1 | 10µs | 10µs | Term::ReadLine::Stub::ReadLine |
| 2 | 2 | 1 | 9µs | 9µs | Term::ReadLine::Stub::CORE:select (opcode) |
| 1 | 1 | 1 | 2µs | 2µs | Term::ReadLine::Stub::Features |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Stub::Attribs |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Stub::IN |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Stub::MinLine |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Stub::OUT |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Stub::addhistory |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Stub::newTTY |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Tk::Tk_loop |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Tk::__ANON__[:426] |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Tk::__ANON__[:446] |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Tk::event_loop |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Tk::register_Tk |
| 0 | 0 | 0 | 0s | 0s | Term::ReadLine::Tk::tkRunning |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | =head1 NAME | ||||
| 2 | |||||
| 3 | Term::ReadLine - Perl interface to various C<readline> packages. | ||||
| 4 | If no real package is found, substitutes stubs instead of basic functions. | ||||
| 5 | |||||
| 6 | =head1 SYNOPSIS | ||||
| 7 | |||||
| 8 | use Term::ReadLine; | ||||
| 9 | my $term = Term::ReadLine->new('Simple Perl calc'); | ||||
| 10 | my $prompt = "Enter your arithmetic expression: "; | ||||
| 11 | my $OUT = $term->OUT || \*STDOUT; | ||||
| 12 | while ( defined ($_ = $term->readline($prompt)) ) { | ||||
| 13 | my $res = eval($_); | ||||
| 14 | warn $@ if $@; | ||||
| 15 | print $OUT $res, "\n" unless $@; | ||||
| 16 | $term->addhistory($_) if /\S/; | ||||
| 17 | } | ||||
| 18 | |||||
| 19 | =head1 DESCRIPTION | ||||
| 20 | |||||
| 21 | This package is just a front end to some other packages. It's a stub to | ||||
| 22 | set up a common interface to the various ReadLine implementations found on | ||||
| 23 | CPAN (under the C<Term::ReadLine::*> namespace). | ||||
| 24 | |||||
| 25 | =head1 Minimal set of supported functions | ||||
| 26 | |||||
| 27 | All the supported functions should be called as methods, i.e., either as | ||||
| 28 | |||||
| 29 | $term = Term::ReadLine->new('name'); | ||||
| 30 | |||||
| 31 | or as | ||||
| 32 | |||||
| 33 | $term->addhistory('row'); | ||||
| 34 | |||||
| 35 | where $term is a return value of Term::ReadLine-E<gt>new(). | ||||
| 36 | |||||
| 37 | =over 12 | ||||
| 38 | |||||
| 39 | =item C<ReadLine> | ||||
| 40 | |||||
| 41 | returns the actual package that executes the commands. Among possible | ||||
| 42 | values are C<Term::ReadLine::Gnu>, C<Term::ReadLine::Perl>, | ||||
| 43 | C<Term::ReadLine::Stub>. | ||||
| 44 | |||||
| 45 | =item C<new> | ||||
| 46 | |||||
| 47 | returns the handle for subsequent calls to following | ||||
| 48 | functions. Argument is the name of the application. Optionally can be | ||||
| 49 | followed by two arguments for C<IN> and C<OUT> filehandles. These | ||||
| 50 | arguments should be globs. | ||||
| 51 | |||||
| 52 | =item C<readline> | ||||
| 53 | |||||
| 54 | gets an input line, I<possibly> with actual C<readline> | ||||
| 55 | support. Trailing newline is removed. Returns C<undef> on C<EOF>. | ||||
| 56 | |||||
| 57 | =item C<addhistory> | ||||
| 58 | |||||
| 59 | adds the line to the history of input, from where it can be used if | ||||
| 60 | the actual C<readline> is present. | ||||
| 61 | |||||
| 62 | =item C<IN>, C<OUT> | ||||
| 63 | |||||
| 64 | return the filehandles for input and output or C<undef> if C<readline> | ||||
| 65 | input and output cannot be used for Perl. | ||||
| 66 | |||||
| 67 | =item C<MinLine> | ||||
| 68 | |||||
| 69 | If argument is specified, it is an advice on minimal size of line to | ||||
| 70 | be included into history. C<undef> means do not include anything into | ||||
| 71 | history. Returns the old value. | ||||
| 72 | |||||
| 73 | =item C<findConsole> | ||||
| 74 | |||||
| 75 | returns an array with two strings that give most appropriate names for | ||||
| 76 | files for input and output using conventions C<"E<lt>$in">, C<"E<gt>out">. | ||||
| 77 | |||||
| 78 | =item Attribs | ||||
| 79 | |||||
| 80 | returns a reference to a hash which describes internal configuration | ||||
| 81 | of the package. Names of keys in this hash conform to standard | ||||
| 82 | conventions with the leading C<rl_> stripped. | ||||
| 83 | |||||
| 84 | =item C<Features> | ||||
| 85 | |||||
| 86 | Returns a reference to a hash with keys being features present in | ||||
| 87 | current implementation. Several optional features are used in the | ||||
| 88 | minimal interface: C<appname> should be present if the first argument | ||||
| 89 | to C<new> is recognized, and C<minline> should be present if | ||||
| 90 | C<MinLine> method is not dummy. C<autohistory> should be present if | ||||
| 91 | lines are put into history automatically (maybe subject to | ||||
| 92 | C<MinLine>), and C<addhistory> if C<addhistory> method is not dummy. | ||||
| 93 | |||||
| 94 | If C<Features> method reports a feature C<attribs> as present, the | ||||
| 95 | method C<Attribs> is not dummy. | ||||
| 96 | |||||
| 97 | =back | ||||
| 98 | |||||
| 99 | =head1 Additional supported functions | ||||
| 100 | |||||
| 101 | Actually C<Term::ReadLine> can use some other package, that will | ||||
| 102 | support a richer set of commands. | ||||
| 103 | |||||
| 104 | All these commands are callable via method interface and have names | ||||
| 105 | which conform to standard conventions with the leading C<rl_> stripped. | ||||
| 106 | |||||
| 107 | The stub package included with the perl distribution allows some | ||||
| 108 | additional methods: | ||||
| 109 | |||||
| 110 | =over 12 | ||||
| 111 | |||||
| 112 | =item C<tkRunning> | ||||
| 113 | |||||
| 114 | makes Tk event loop run when waiting for user input (i.e., during | ||||
| 115 | C<readline> method). | ||||
| 116 | |||||
| 117 | =item C<event_loop> | ||||
| 118 | |||||
| 119 | Registers call-backs to wait for user input (i.e., during C<readline> | ||||
| 120 | method). This supersedes tkRunning. | ||||
| 121 | |||||
| 122 | The first call-back registered is the call back for waiting. It is | ||||
| 123 | expected that the callback will call the current event loop until | ||||
| 124 | there is something waiting to get on the input filehandle. The parameter | ||||
| 125 | passed in is the return value of the second call back. | ||||
| 126 | |||||
| 127 | The second call-back registered is the call back for registration. The | ||||
| 128 | input filehandle (often STDIN, but not necessarily) will be passed in. | ||||
| 129 | |||||
| 130 | For example, with AnyEvent: | ||||
| 131 | |||||
| 132 | $term->event_loop(sub { | ||||
| 133 | my $data = shift; | ||||
| 134 | $data->[1] = AE::cv(); | ||||
| 135 | $data->[1]->recv(); | ||||
| 136 | }, sub { | ||||
| 137 | my $fh = shift; | ||||
| 138 | my $data = []; | ||||
| 139 | $data->[0] = AE::io($fh, 0, sub { $data->[1]->send() }); | ||||
| 140 | $data; | ||||
| 141 | }); | ||||
| 142 | |||||
| 143 | The second call-back is optional if the call back is registered prior to | ||||
| 144 | the call to $term-E<gt>readline. | ||||
| 145 | |||||
| 146 | Deregistration is done in this case by calling event_loop with C<undef> | ||||
| 147 | as its parameter: | ||||
| 148 | |||||
| 149 | $term->event_loop(undef); | ||||
| 150 | |||||
| 151 | This will cause the data array ref to be removed, allowing normal garbage | ||||
| 152 | collection to clean it up. With AnyEvent, that will cause $data->[0] to | ||||
| 153 | be cleaned up, and AnyEvent will automatically cancel the watcher at that | ||||
| 154 | time. If another loop requires more than that to clean up a file watcher, | ||||
| 155 | that will be up to the caller to handle. | ||||
| 156 | |||||
| 157 | =item C<ornaments> | ||||
| 158 | |||||
| 159 | makes the command line stand out by using termcap data. The argument | ||||
| 160 | to C<ornaments> should be 0, 1, or a string of a form | ||||
| 161 | C<"aa,bb,cc,dd">. Four components of this string should be names of | ||||
| 162 | I<terminal capacities>, first two will be issued to make the prompt | ||||
| 163 | standout, last two to make the input line standout. | ||||
| 164 | |||||
| 165 | =item C<newTTY> | ||||
| 166 | |||||
| 167 | takes two arguments which are input filehandle and output filehandle. | ||||
| 168 | Switches to use these filehandles. | ||||
| 169 | |||||
| 170 | =back | ||||
| 171 | |||||
| 172 | One can check whether the currently loaded ReadLine package supports | ||||
| 173 | these methods by checking for corresponding C<Features>. | ||||
| 174 | |||||
| 175 | =head1 EXPORTS | ||||
| 176 | |||||
| 177 | None | ||||
| 178 | |||||
| 179 | =head1 ENVIRONMENT | ||||
| 180 | |||||
| 181 | The environment variable C<PERL_RL> governs which ReadLine clone is | ||||
| 182 | loaded. If the value is false, a dummy interface is used. If the value | ||||
| 183 | is true, it should be tail of the name of the package to use, such as | ||||
| 184 | C<Perl> or C<Gnu>. | ||||
| 185 | |||||
| 186 | As a special case, if the value of this variable is space-separated, | ||||
| 187 | the tail might be used to disable the ornaments by setting the tail to | ||||
| 188 | be C<o=0> or C<ornaments=0>. The head should be as described above, say | ||||
| 189 | |||||
| 190 | If the variable is not set, or if the head of space-separated list is | ||||
| 191 | empty, the best available package is loaded. | ||||
| 192 | |||||
| 193 | export "PERL_RL=Perl o=0" # Use Perl ReadLine sans ornaments | ||||
| 194 | export "PERL_RL= o=0" # Use best available ReadLine sans ornaments | ||||
| 195 | |||||
| 196 | (Note that processing of C<PERL_RL> for ornaments is in the discretion of the | ||||
| 197 | particular used C<Term::ReadLine::*> package). | ||||
| 198 | |||||
| 199 | =cut | ||||
| 200 | |||||
| 201 | 2 | 2.78ms | 2 | 95µs | # spent 77µs (59+18) within CPAN::BEGIN@201 which was called:
# once (59µs+18µs) by CPAN::shell at line 201 # spent 77µs making 1 call to CPAN::BEGIN@201
# spent 18µs making 1 call to strict::import |
| 202 | |||||
| 203 | package Term::ReadLine::Stub; | ||||
| 204 | 1 | 22µs | our @ISA = qw'Term::ReadLine::Tk Term::ReadLine::TermCap'; | ||
| 205 | |||||
| 206 | 1 | 0s | $DB::emacs = $DB::emacs; # To pacify -w | ||
| 207 | our @rl_term_set; | ||||
| 208 | 1 | 3µs | *rl_term_set = \@Term::ReadLine::TermCap::rl_term_set; | ||
| 209 | |||||
| 210 | sub PERL_UNICODE_STDIN () { 0x0001 } | ||||
| 211 | |||||
| 212 | 3 | 14µs | # spent 10µs within Term::ReadLine::Stub::ReadLine which was called 3 times, avg 3µs/call:
# once (5µs+0s) by CPAN::shell at line 310 of CPAN.pm
# once (4µs+0s) by CPAN::shell at line 276 of CPAN.pm
# once (1µs+0s) by CPAN::shell at line 312 of CPAN.pm | ||
| 213 | # spent 20.4s (223µs+20.4) within Term::ReadLine::Stub::readline which was called 4 times, avg 5.10s/call:
# 4 times (223µs+20.4s) by CPAN::shell at line 340 of CPAN.pm, avg 5.10s/call | ||||
| 214 | 4 | 7µs | my $self = shift; | ||
| 215 | 4 | 7µs | my ($in,$out,$str) = @$self; | ||
| 216 | 4 | 0s | my $prompt = shift; | ||
| 217 | 4 | 220µs | 8 | 311µs | print $out $rl_term_set[0], $prompt, $rl_term_set[1], $rl_term_set[2]; # spent 247µs making 4 calls to Term::ReadLine::Stub::CORE:print, avg 62µs/call
# spent 64µs making 4 calls to CPAN::Prompt::as_string, avg 16µs/call |
| 218 | 4 | 6µs | $self->register_Tk | ||
| 219 | if not $Term::ReadLine::registered and $Term::ReadLine::toloop; | ||||
| 220 | #$str = scalar <$in>; | ||||
| 221 | 4 | 55µs | 4 | 20.4s | $str = $self->get_line; # spent 20.4s making 4 calls to Term::ReadLine::Tk::get_line, avg 5.10s/call |
| 222 | 4 | 10µs | utf8::upgrade($str) | ||
| 223 | if (${^UNICODE} & PERL_UNICODE_STDIN || defined ${^ENCODING}) && | ||||
| 224 | utf8::valid($str); | ||||
| 225 | 4 | 60µs | 4 | 32µs | print $out $rl_term_set[3]; # spent 32µs making 4 calls to Term::ReadLine::Stub::CORE:print, avg 8µs/call |
| 226 | # bug in 5.000: chomping empty string creates length -1: | ||||
| 227 | 4 | 5µs | chomp $str if defined $str; | ||
| 228 | 4 | 32µs | $str; | ||
| 229 | } | ||||
| 230 | sub addhistory {} | ||||
| 231 | |||||
| 232 | # spent 79µs (35+44) within Term::ReadLine::Stub::findConsole which was called:
# once (35µs+44µs) by Term::ReadLine::Stub::new at line 267 | ||||
| 233 | 1 | 1µs | my $console; | ||
| 234 | my $consoleOUT; | ||||
| 235 | |||||
| 236 | 1 | 27µs | 1 | 17µs | if ($^O ne 'MSWin32' and -e "/dev/tty") { # spent 17µs making 1 call to Term::ReadLine::Stub::CORE:ftis |
| 237 | $console = "/dev/tty"; | ||||
| 238 | } elsif ($^O eq 'MSWin32' or $^O eq 'msys' or -e "con") { | ||||
| 239 | $console = 'CONIN$'; | ||||
| 240 | $consoleOUT = 'CONOUT$'; | ||||
| 241 | } elsif ($^O eq 'VMS') { | ||||
| 242 | $console = "sys\$command"; | ||||
| 243 | } elsif ($^O eq 'os2' && !$DB::emacs) { | ||||
| 244 | $console = "/dev/con"; | ||||
| 245 | } else { | ||||
| 246 | $console = undef; | ||||
| 247 | } | ||||
| 248 | |||||
| 249 | 1 | 0s | $consoleOUT = $console unless defined $consoleOUT; | ||
| 250 | 1 | 0s | $console = "&STDIN" unless defined $console; | ||
| 251 | 1 | 37µs | 1 | 27µs | if ($console eq "/dev/tty" && !open(my $fh, "<", $console)) { # spent 27µs making 1 call to Term::ReadLine::Stub::CORE:open |
| 252 | $console = "&STDIN"; | ||||
| 253 | undef($consoleOUT); | ||||
| 254 | } | ||||
| 255 | 1 | 1µs | if (!defined $consoleOUT) { | ||
| 256 | $consoleOUT = defined fileno(STDERR) && $^O ne 'MSWin32' ? "&STDERR" : "&STDOUT"; | ||||
| 257 | } | ||||
| 258 | 1 | 18µs | ($console,$consoleOUT); | ||
| 259 | } | ||||
| 260 | |||||
| 261 | # spent 49.3ms (75µs+49.3) within Term::ReadLine::Stub::new which was called:
# once (75µs+49.3ms) by CPAN::shell at line 274 of CPAN.pm | ||||
| 262 | 1 | 1µs | die "method new called with wrong number of arguments" | ||
| 263 | unless @_==2 or @_==4; | ||||
| 264 | #local (*FIN, *FOUT); | ||||
| 265 | 1 | 0s | my ($FIN, $FOUT, $ret); | ||
| 266 | 1 | 1µs | if (@_==2) { | ||
| 267 | 1 | 3µs | 1 | 79µs | my($console, $consoleOUT) = $_[0]->findConsole; # spent 79µs making 1 call to Term::ReadLine::Stub::findConsole |
| 268 | |||||
| 269 | |||||
| 270 | # the Windows CONIN$ needs GENERIC_WRITE mode to allow | ||||
| 271 | # a SetConsoleMode() if we end up using Term::ReadKey | ||||
| 272 | 1 | 20µs | 1 | 14µs | open FIN, (( $^O eq 'MSWin32' && $console eq 'CONIN$' ) ? '+<' : '<' ), $console; # spent 14µs making 1 call to Term::ReadLine::Stub::CORE:open |
| 273 | 1 | 51µs | 1 | 45µs | open FOUT,'>', $consoleOUT; # spent 45µs making 1 call to Term::ReadLine::Stub::CORE:open |
| 274 | |||||
| 275 | #OUT->autoflush(1); # Conflicts with debugger? | ||||
| 276 | 1 | 16µs | 1 | 7µs | my $sel = select(FOUT); # spent 7µs making 1 call to Term::ReadLine::Stub::CORE:select |
| 277 | 1 | 4µs | $| = 1; # for DB::OUT | ||
| 278 | 1 | 6µs | 1 | 2µs | select($sel); # spent 2µs making 1 call to Term::ReadLine::Stub::CORE:select |
| 279 | 1 | 3µs | $ret = bless [\*FIN, \*FOUT]; | ||
| 280 | } else { # Filehandles supplied | ||||
| 281 | $FIN = $_[2]; $FOUT = $_[3]; | ||||
| 282 | #OUT->autoflush(1); # Conflicts with debugger? | ||||
| 283 | my $sel = select($FOUT); | ||||
| 284 | $| = 1; # for DB::OUT | ||||
| 285 | select($sel); | ||||
| 286 | $ret = bless [$FIN, $FOUT]; | ||||
| 287 | } | ||||
| 288 | 1 | 7µs | 1 | 2µs | if ($ret->Features->{ornaments} # spent 2µs making 1 call to Term::ReadLine::Stub::Features |
| 289 | and not ($ENV{PERL_RL} and $ENV{PERL_RL} =~ /\bo\w*=0/)) { | ||||
| 290 | 1 | 0s | local $Term::ReadLine::termcap_nowarn = 1; | ||
| 291 | 1 | 9µs | 1 | 49.1ms | $ret->ornaments(1); # spent 49.1ms making 1 call to Term::ReadLine::TermCap::ornaments |
| 292 | } | ||||
| 293 | 1 | 9µs | return $ret; | ||
| 294 | } | ||||
| 295 | |||||
| 296 | sub newTTY { | ||||
| 297 | my ($self, $in, $out) = @_; | ||||
| 298 | $self->[0] = $in; | ||||
| 299 | $self->[1] = $out; | ||||
| 300 | my $sel = select($out); | ||||
| 301 | $| = 1; # for DB::OUT | ||||
| 302 | select($sel); | ||||
| 303 | } | ||||
| 304 | |||||
| 305 | sub IN { shift->[0] } | ||||
| 306 | sub OUT { shift->[1] } | ||||
| 307 | sub MinLine { undef } | ||||
| 308 | sub Attribs { {} } | ||||
| 309 | |||||
| 310 | 1 | 2µs | my %features = (tkRunning => 1, ornaments => 1, 'newTTY' => 1); | ||
| 311 | 1 | 8µs | # spent 2µs within Term::ReadLine::Stub::Features which was called:
# once (2µs+0s) by Term::ReadLine::Stub::new at line 288 | ||
| 312 | |||||
| 313 | #sub get_line { | ||||
| 314 | # my $self = shift; | ||||
| 315 | # my $in = $self->IN; | ||||
| 316 | # local ($/) = "\n"; | ||||
| 317 | # return scalar <$in>; | ||||
| 318 | #} | ||||
| 319 | |||||
| 320 | package Term::ReadLine; # So late to allow the above code be defined? | ||||
| 321 | |||||
| 322 | 1 | 0s | our $VERSION = '1.16'; | ||
| 323 | |||||
| 324 | 1 | 2µs | my ($which) = exists $ENV{PERL_RL} ? split /\s+/, $ENV{PERL_RL} : undef; | ||
| 325 | 1 | 6µs | if ($which) { | ||
| 326 | if ($which =~ /\bgnu\b/i){ | ||||
| 327 | eval "use Term::ReadLine::Gnu;"; | ||||
| 328 | } elsif ($which =~ /\bperl\b/i) { | ||||
| 329 | eval "use Term::ReadLine::Perl;"; | ||||
| 330 | } elsif ($which =~ /^(Stub|TermCap|Tk)$/) { | ||||
| 331 | # it is already in memory to avoid false exception as seen in: | ||||
| 332 | # PERL_RL=Stub perl -e'$SIG{__DIE__} = sub { print @_ }; require Term::ReadLine' | ||||
| 333 | } else { | ||||
| 334 | eval "use Term::ReadLine::$which;"; | ||||
| 335 | } | ||||
| 336 | } elsif (defined $which and $which ne '') { # Defined but false | ||||
| 337 | # Do nothing fancy | ||||
| 338 | } else { | ||||
| 339 | 1 | 52µs | eval "use Term::ReadLine::Gnu; 1" or eval "use Term::ReadLine::EditLine; 1" or eval "use Term::ReadLine::Perl; 1"; # spent 160µs executing statements in string eval # includes 66µs spent executing 1 call to 1 sub defined therein. # spent 77µs executing statements in string eval # includes 36µs spent executing 1 call to 1 sub defined therein. # spent 45µs executing statements in string eval # includes 37µs spent executing 1 call to 1 sub defined therein. | ||
| 340 | } | ||||
| 341 | |||||
| 342 | #require FileHandle; | ||||
| 343 | |||||
| 344 | # To make possible switch off RL in debugger: (Not needed, work done | ||||
| 345 | # in debugger). | ||||
| 346 | our @ISA; | ||||
| 347 | 1 | 2µs | if (defined &Term::ReadLine::Gnu::readline) { | ||
| 348 | @ISA = qw(Term::ReadLine::Gnu Term::ReadLine::Stub); | ||||
| 349 | } elsif (defined &Term::ReadLine::EditLine::readline) { | ||||
| 350 | @ISA = qw(Term::ReadLine::EditLine Term::ReadLine::Stub); | ||||
| 351 | } elsif (defined &Term::ReadLine::Perl::readline) { | ||||
| 352 | @ISA = qw(Term::ReadLine::Perl Term::ReadLine::Stub); | ||||
| 353 | } elsif (defined $which && defined &{"Term::ReadLine::$which\::readline"}) { | ||||
| 354 | @ISA = "Term::ReadLine::$which"; | ||||
| 355 | } else { | ||||
| 356 | 1 | 9µs | @ISA = qw(Term::ReadLine::Stub); | ||
| 357 | } | ||||
| 358 | |||||
| 359 | package Term::ReadLine::TermCap; | ||||
| 360 | |||||
| 361 | # Prompt-start, prompt-end, command-line-start, command-line-end | ||||
| 362 | # -- zero-width beautifies to emit around prompt and the command line. | ||||
| 363 | 1 | 1µs | our @rl_term_set = ("","","",""); | ||
| 364 | # string encoded: | ||||
| 365 | 1 | 0s | our $rl_term_set = ',,,'; | ||
| 366 | |||||
| 367 | our $terminal; | ||||
| 368 | # spent 49.0ms (5.06+43.9) within Term::ReadLine::TermCap::LoadTermCap which was called 3 times, avg 16.3ms/call:
# 3 times (5.06ms+43.9ms) by Term::ReadLine::TermCap::ornaments at line 382, avg 16.3ms/call | ||||
| 369 | 3 | 10µs | return if defined $terminal; | ||
| 370 | |||||
| 371 | 1 | 522µs | require Term::Cap; | ||
| 372 | 1 | 19µs | 1 | 43.7ms | $terminal = Tgetent Term::Cap ({OSPEED => 9600}); # Avoid warning. # spent 43.7ms making 1 call to Term::Cap::Tgetent |
| 373 | } | ||||
| 374 | |||||
| 375 | # spent 49.3ms (179µs+49.1) within Term::ReadLine::TermCap::ornaments which was called 3 times, avg 16.4ms/call:
# once (47µs+49.1ms) by Term::ReadLine::Stub::new at line 291
# once (92µs+23µs) by CPAN::shell at line 294 of CPAN.pm
# once (40µs+24µs) by CPAN::shell at line 454 of CPAN.pm | ||||
| 376 | 3 | 2µs | shift; | ||
| 377 | 3 | 2µs | return $rl_term_set unless @_; | ||
| 378 | 3 | 6µs | $rl_term_set = shift; | ||
| 379 | 3 | 2µs | $rl_term_set ||= ',,,'; | ||
| 380 | 3 | 3µs | $rl_term_set = 'us,ue,md,me' if $rl_term_set eq '1'; | ||
| 381 | 3 | 11µs | my @ts = split /,/, $rl_term_set, 4; | ||
| 382 | 6 | 6µs | 3 | 49.0ms | eval { LoadTermCap }; # spent 49.0ms making 3 calls to Term::ReadLine::TermCap::LoadTermCap, avg 16.3ms/call |
| 383 | 3 | 1µs | unless (defined $terminal) { | ||
| 384 | warn("Cannot find termcap: $@\n") unless $Term::ReadLine::termcap_nowarn; | ||||
| 385 | $rl_term_set = ',,,'; | ||||
| 386 | return; | ||||
| 387 | } | ||||
| 388 | 15 | 67µs | 12 | 112µs | @rl_term_set = map {$_ ? $terminal->Tputs($_,1) || '' : ''} @ts; # spent 112µs making 12 calls to Term::Cap::Tputs, avg 9µs/call |
| 389 | 3 | 34µs | return $rl_term_set; | ||
| 390 | } | ||||
| 391 | |||||
| 392 | |||||
| 393 | package Term::ReadLine::Tk; | ||||
| 394 | |||||
| 395 | # This package inserts a Tk->fileevent() before the diamond operator. | ||||
| 396 | # The Tk watcher dispatches Tk events until the filehandle returned by | ||||
| 397 | # the$term->IN() accessor becomes ready for reading. It's assumed | ||||
| 398 | # that the diamond operator will return a line of input immediately at | ||||
| 399 | # that point. | ||||
| 400 | |||||
| 401 | 1 | 0s | my ($giveup); | ||
| 402 | |||||
| 403 | # maybe in the future the Tk-specific aspects will be removed. | ||||
| 404 | sub Tk_loop{ | ||||
| 405 | if (ref $Term::ReadLine::toloop) | ||||
| 406 | { | ||||
| 407 | $Term::ReadLine::toloop->[0]->($Term::ReadLine::toloop->[2]); | ||||
| 408 | } | ||||
| 409 | else | ||||
| 410 | { | ||||
| 411 | Tk::DoOneEvent(0) until $giveup; | ||||
| 412 | $giveup = 0; | ||||
| 413 | } | ||||
| 414 | }; | ||||
| 415 | |||||
| 416 | sub register_Tk { | ||||
| 417 | my $self = shift; | ||||
| 418 | unless ($Term::ReadLine::registered++) | ||||
| 419 | { | ||||
| 420 | if (ref $Term::ReadLine::toloop) | ||||
| 421 | { | ||||
| 422 | $Term::ReadLine::toloop->[2] = $Term::ReadLine::toloop->[1]->($self->IN) if $Term::ReadLine::toloop->[1]; | ||||
| 423 | } | ||||
| 424 | else | ||||
| 425 | { | ||||
| 426 | Tk->fileevent($self->IN,'readable',sub { $giveup = 1}); | ||||
| 427 | } | ||||
| 428 | } | ||||
| 429 | }; | ||||
| 430 | |||||
| 431 | sub tkRunning { | ||||
| 432 | $Term::ReadLine::toloop = $_[1] if @_ > 1; | ||||
| 433 | $Term::ReadLine::toloop; | ||||
| 434 | } | ||||
| 435 | |||||
| 436 | sub event_loop { | ||||
| 437 | shift; | ||||
| 438 | |||||
| 439 | # T::RL::Gnu and T::RL::Perl check that this exists, if not, | ||||
| 440 | # it doesn't call the loop. Those modules will need to be | ||||
| 441 | # fixed before this can be removed. | ||||
| 442 | if (not defined &Tk::DoOneEvent) | ||||
| 443 | { | ||||
| 444 | *Tk::DoOneEvent = sub { | ||||
| 445 | die "what?"; # this shouldn't be called. | ||||
| 446 | } | ||||
| 447 | } | ||||
| 448 | |||||
| 449 | # store the callback in toloop, again so that other modules will | ||||
| 450 | # recognise it and call us for the loop. | ||||
| 451 | $Term::ReadLine::toloop = [ @_ ] if @_ > 0; # 0 because we shifted off $self. | ||||
| 452 | $Term::ReadLine::toloop; | ||||
| 453 | } | ||||
| 454 | |||||
| 455 | sub PERL_UNICODE_STDIN () { 0x0001 } | ||||
| 456 | |||||
| 457 | # spent 20.4s (277µs+20.4) within Term::ReadLine::Tk::get_line which was called 4 times, avg 5.10s/call:
# 4 times (277µs+20.4s) by Term::ReadLine::Stub::readline at line 221, avg 5.10s/call | ||||
| 458 | 4 | 12µs | my $self = shift; | ||
| 459 | 4 | 3µs | my ($in,$out,$str) = @$self; | ||
| 460 | |||||
| 461 | 4 | 2µs | if ($Term::ReadLine::toloop) { | ||
| 462 | $self->register_Tk if not $Term::ReadLine::registered; | ||||
| 463 | $self->Tk_loop; | ||||
| 464 | } | ||||
| 465 | |||||
| 466 | 4 | 25µs | local ($/) = "\n"; | ||
| 467 | 4 | 20.4s | 4 | 20.4s | $str = <$in>; # spent 20.4s making 4 calls to Term::ReadLine::Tk::CORE:readline, avg 5.10s/call |
| 468 | |||||
| 469 | 4 | 27µs | utf8::upgrade($str) | ||
| 470 | if (${^UNICODE} & PERL_UNICODE_STDIN || defined ${^ENCODING}) && | ||||
| 471 | utf8::valid($str); | ||||
| 472 | 4 | 105µs | 4 | 57µs | print $out $rl_term_set[3]; # spent 57µs making 4 calls to Term::ReadLine::Tk::CORE:print, avg 14µs/call |
| 473 | # bug in 5.000: chomping empty string creates length -1: | ||||
| 474 | 4 | 7µs | chomp $str if defined $str; | ||
| 475 | |||||
| 476 | 4 | 88µs | $str; | ||
| 477 | } | ||||
| 478 | |||||
| 479 | 1 | 29µs | 1; | ||
| 480 | |||||
# spent 17µs within Term::ReadLine::Stub::CORE:ftis which was called:
# once (17µs+0s) by Term::ReadLine::Stub::findConsole at line 236 | |||||
sub Term::ReadLine::Stub::CORE:open; # opcode | |||||
sub Term::ReadLine::Stub::CORE:print; # opcode | |||||
sub Term::ReadLine::Stub::CORE:select; # opcode | |||||
# spent 57µs within Term::ReadLine::Tk::CORE:print which was called 4 times, avg 14µs/call:
# 4 times (57µs+0s) by Term::ReadLine::Tk::get_line at line 472, avg 14µs/call | |||||
# spent 20.4s within Term::ReadLine::Tk::CORE:readline which was called 4 times, avg 5.10s/call:
# 4 times (20.4s+0s) by Term::ReadLine::Tk::get_line at line 467, avg 5.10s/call |