| 1 | package PDL::Graphics::Prima::ReadLine; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = 0.17; # update with update-version.pl | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | my $is_setup = 0; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub is_happy_with { | ||||||||||||||||||||||||||||
| 11 | # Stop-gap until I figure out better readline support for Windows | ||||||||||||||||||||||||||||
| 12 | 0 | ▶ | return 0 if $^O =~ /Win/ or $^O =~ /cygwin/; | ||||||||||||||||||||||||||
|
Subroutine
is_happy_with: not called CC=4 SCAR=30.0
Pod
documented
Branch: 1 branch
Condition0%0/3
$^O =~ /Win/ or $^O =~ /cygwin/
MC/DC0%0/2
$^O =~ /Win/ or $^O =~ /cygwin/
$^O =~ /Win/
$^O =~ /cygwin/
Truth table0%0/3
A or B
A= $^O =~ /Win/B= $^O =~ /cygwin/
| |||||||||||||||||||||||||||||
| 13 | 0 | my ($class, $readline_obj) = @_; | |||||||||||||||||||||||||||
| 14 | 0 | ▶ | return eval{ $readline_obj->can('event_loop') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | and not $readline_obj->tkRunning }; | ||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub setup { | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my ($class, $readline_obj) = @_; | ||||||||||||||||||||||||||
|
Subroutine
setup: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | return if $is_setup; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # Make sure we have a readline object that knows how to work with the | ||||||||||||||||||||||||||||
| 24 | # event loop: | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if (not $class->is_happy_with($readline_obj)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | croak("PDL::Graphics::Prima::ReadLine expects a readline object") | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | unless eval { $readline_obj->isa('Term::ReadLine::Stub') }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | croak("PDL::Graphics::Prima::ReadLine expects a readline object that knows how to event_loop.\n" | |||||||||||||||||||||||||||
| 29 | . "This is provided in Term::ReadLine v1.09 or newer"); | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # We must call the import method for this to work, even though we don't need | ||||||||||||||||||||||||||||
| 33 | # need any functions imported. The reason is that Prima sets up the | ||||||||||||||||||||||||||||
| 34 | # application object during the import if it hasn't already been set up (by | ||||||||||||||||||||||||||||
| 35 | # a previous call to Prima::Application::import). | ||||||||||||||||||||||||||||
| 36 | 0 | require Prima::Application; | |||||||||||||||||||||||||||
| 37 | 0 | Prima::Application->import; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # This io watcher will (eventually) watch whatever the readline is | ||||||||||||||||||||||||||||
| 40 | # monitoring. That will be established later in the call to event_loop. | ||||||||||||||||||||||||||||
| 41 | # Die'ing is a simple way to exit the "go" method invoked during the | ||||||||||||||||||||||||||||
| 42 | # event loop | ||||||||||||||||||||||||||||
| 43 | my $prima_io_watcher = Prima::File->new( | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | onRead => sub { die 'user pressed a key' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 45 | 0 | ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | $readline_obj->event_loop( sub { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | local $@; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 49 | # Run the event loop. If a key is pressed, the io watcher's | ||||||||||||||||||||||||||||
| 50 | # callback will get called, throwing an exception. | ||||||||||||||||||||||||||||
| 51 | 0 | eval { $::application->go }; | |||||||||||||||||||||||||||
| 52 | # Rethrow the exception if it's not one that we threw | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | die unless $@ =~ /user pressed a key/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | }, | ||||||||||||||||||||||||||||
| 55 | sub { | ||||||||||||||||||||||||||||
| 56 | # Register the event loop, which means associating the io | ||||||||||||||||||||||||||||
| 57 | # watcher with the specific io handle the readline wants | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $fh = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | 0 | $prima_io_watcher->file($fh); | |||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||
| 61 | 0 | ); | |||||||||||||||||||||||||||
| 62 | 0 | $is_setup = 1; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Status method | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub is_setup { $is_setup } | ||||||||||||||||||||||||||
|
Subroutine
is_setup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | 1; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||