Skip Menu |
 

This queue is for tickets about the io-page CPAN distribution.

Report information
The Basics
Id: 97696
Status: new
Priority: 0/
Queue: io-page

People
Owner: Nobody in particular
Requestors: fraserbn [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)

Attachments
0001-Use-IPC-Cmd-to-find-a-pager.patch
0002-Don-t-leave-a-pager-open-after-make-test.patch



Subject: [PATCH] Android support, test.pl niceness
Download (untitled) / with headers
text/plain 187b
Patch 1 makes the module use IPC::Cmd::can_run to find a pager, which is needed for Android and Windows. Patch 2 stops 'make test' from leaving an open pager, which was all kinds of suck.
Subject: 0001-Use-IPC-Cmd-to-find-a-pager.patch
From 38ef4d7472f8d6af7a7374632b0b1c8a5036691a Mon Sep 17 00:00:00 2001 From: Brian Fraser <fraserbn@gmail.com> Date: Sat, 2 Aug 2014 11:32:48 +0200 Subject: [PATCH 1/2] Use IPC::Cmd to find a pager. With this, the module should now work on systems where more or less are in nonstandard locations, like in Windows or Android. --- Makefile.PL | 3 +++ Page.pm | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 657be20..213f408 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,4 +4,7 @@ use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'IO::Page', 'VERSION_FROM' => 'Page.pm', # finds $VERSION + 'PREREQ_PM' => { + 'IPC::Cmd' => 0, + }, ); diff --git a/Page.pm b/Page.pm index e745e18..ed0abd6 100644 --- a/Page.pm +++ b/Page.pm @@ -3,6 +3,8 @@ package IO::Page; use strict; use vars qw( $VERSION ); +use IPC::Cmd qw(can_run); + $VERSION = '0.02'; local( *PAGER, *STDOLD, ) ; @@ -15,9 +17,8 @@ BEGIN { # other fallbacks could be `which less`, `which more`, etc TRY: foreach $try ( $ENV{PAGER}, - '/usr/local/bin/less', - '/usr/bin/less', - '/usr/bin/more', + grep defined, + map can_run($_), qw(less more) ) { eval { chomp $try } ; if ( -x $try ) { -- 1.7.12.4 (Apple Git-37)
Subject: 0002-Don-t-leave-a-pager-open-after-make-test.patch
From 41ecb07419f10d1587fee8b33b5fd7caad8d22df Mon Sep 17 00:00:00 2001 From: Brian Fraser <fraserbn@gmail.com> Date: Sat, 2 Aug 2014 11:34:10 +0200 Subject: [PATCH 2/2] Don't leave a pager open after 'make test' Previously, make test would've left a pager open with just the test results for the module. Now the test file checks that the module can be loaded, and indirectly, that a pager can be opened, then closes the pager and outputs an ok 1. --- Page.pm | 8 +++++--- test.pl | 12 +++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Page.pm b/Page.pm index ed0abd6..eace87c 100644 --- a/Page.pm +++ b/Page.pm @@ -1,7 +1,7 @@ package IO::Page; use strict; -use vars qw( $VERSION ); +use vars qw( $VERSION $pager_pid); use IPC::Cmd qw(can_run); @@ -29,7 +29,7 @@ BEGIN { die "Couldn't find a pager!\n" unless -x $pager ; - open PAGER, "| $pager" + $pager_pid = open PAGER, "| $pager" or die "Can't pipe to $pager: $!" ; open STDOLD, ">&STDOUT" or die "Can't save STDOUT: $!" ; @@ -38,7 +38,7 @@ BEGIN { } } -END { +sub end { if ( fileno STDOLD ) { open STDOUT, ">&STDOLD" or die "Can't restore STDOUT: $!" ; @@ -46,6 +46,8 @@ END { close PAGER ; } +END {end()} + # module loaded OK! 1 ; diff --git a/test.pl b/test.pl index c97e2ed..f811c79 100644 --- a/test.pl +++ b/test.pl @@ -6,11 +6,17 @@ # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) -BEGIN { $| = 1; print "1..2\n"; } -END {print "not ok 1\n" unless $loaded;} +BEGIN { $| = 1; print "1..1\n"; } +END { + my $res = $loaded ? 'ok' : 'not ok'; + print "$res 1\n"; +} use IO::Page; $loaded = 1; -print "ok 1\n"; +# Kill the pager so that the test results go to STDOUT +kill KILL => $IO::Page::pager_pid; +# ..actually restore STDOUT +IO::Page::end(); ######################### End of black magic. -- 1.7.12.4 (Apple Git-37)


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.