Skip Menu |

This queue is for tickets about the IO-Pager CPAN distribution.

Report information
The Basics
Id: 78270
Status: resolved
Worked: 3 hours (180 min)
Priority: 0/
Queue: IO-Pager

People
Owner: Nobody in particular
Requestors: dwheeler [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 0.03
  • 0.04
  • 0.05
  • 0.06
  • 0.16
  • 0.20
  • 0.24
Fixed in: 0.30



Subject: Add `say` Support
Date: Mon, 9 Jul 2012 13:01:43 +0200
To: bug-io-pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
Useful module, thank you. Here's a version that adds a `say` method, but only on Perl 5.10 or higher. Best, David
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Mon, 9 Jul 2012 13:08:09 +0200
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
And now I have actually attached the patch. David

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Tue, 10 Jul 2012 16:46:19 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
Hi David, Do you want to check/test the latest commit to https://github.com/fangly/io-pager? A slightly different approach, but if it works for you I'll upload it to CPAN. (I still might need to tweak the test a bit / check older perls) -Jerrad
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Wed, 11 Jul 2012 00:26:16 +0200
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Jul 10, 2012, at 10:46 PM, belg4mit@pthbb.org via RT wrote: Show quoted text
> Do you want to check/test the latest commit to https://github.com/fangly/io-pager? > A slightly different approach, but if it works for you I'll upload it to CPAN. > (I still might need to tweak the test a bit / check older perls)
Works well enough for me. You don't need SAY() because Perl will use PRINT when you call `say` on a tied file handle. But it doesn't harm anything to have it there. On a side note, I am using it in a Moose-based project, but found that I couldn't just make an attribute be `isa => 'IO::Pager`, because, when the app is piped, IO::Pager does not return a pager object, but just the file handle. I think it's a bid odd for open/new to return a non-object value, and it required me to do a bit of futzing to get type validation to work properly, as you can see here: https://github.com/theory/sqitch/blob/master/lib/App/Sqitch.pm#L177 Any chance you could have it return perhaps an IO::Pager subclass that just prints directly to the file handle in that base, rather than return the file handle from new/open? Thanks, David
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Wed, 11 Jul 2012 00:34:46 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
Show quoted text
>On a side note, I am using it in a Moose-based project, but found that I couldn't >just make an attribute be `isa => 'IO::Pager`, because, when the app is piped, >IO::Pager does not return a pager object, but just the file handle. I think it's >a bid odd for open/
It does return an object, the object is of the subclass type instantiated. For instance, the tests are replete with isa_ok IO::Pager::Buffered, etc. Oh, you mean when it's piped... I don't think it should return/implement a sub-class actually, since it wouldn't be one. I could see it maybe returning an IO::String object for non-interactive, but you'd still have to or your test.
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Wed, 11 Jul 2012 11:01:43 +0200
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Jul 11, 2012, at 6:34 AM, belg4mit@pthbb.org via RT wrote: Show quoted text
> Oh, you mean when it's piped...
Yes. Show quoted text
> I don't think it should return/implement a sub-class > actually, since it wouldn't be one. I could see it maybe returning an IO::String > object for non-interactive, but you'd still have to or your test.
It makes no sense to me that an object constructor would return something other than an instance of the object. I can live with it, and I know why you've done it, but I think it makes for an unexpected API. If the object returned isa IO::Handle or something, that would make more sense. The constructor then would be a factory constructor. As long as the object returned always derived from some base class. JMHO. Best, David
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Wed, 11 Jul 2012 20:53:39 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
I've not yet figured out the best way to implement a test for it, nor documented it, but the latest commit falls back to IO::Handle IFF C<new> was used to invoke IO::Pager, thus preserving transparent procedural programming if using C<open> and adding transparent OO programming. Feel free to kick the tires
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Wed, 11 Jul 2012 23:24:59 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
Documentation and tests added, let me know how it goes?
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Thu, 12 Jul 2012 12:39:10 +0200
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Jul 12, 2012, at 2:53 AM, belg4mit@pthbb.org via RT wrote: Show quoted text
> I've not yet figured out the best way to implement a test for it, > nor documented it, but the latest commit falls back to IO::Handle > IFF C<new> was used to invoke IO::Pager, thus preserving transparent > procedural programming if using C<open> and adding transparent > OO programming. > > Feel free to kick the tires
There are two problems with this. The first is that the passed file handle is ignored. You can fix that with this patch: diff --git a/lib/IO/Pager/Buffered.pm b/lib/IO/Pager/Buffered.pm index 9cc2360..29347e5 100644 --- a/lib/IO/Pager/Buffered.pm +++ b/lib/IO/Pager/Buffered.pm @@ -16,7 +16,8 @@ sub new(;$) { # [FH] return $_[1] if defined($_[2]) && $_[2] eq 'procedural'; #...fall back to IO::Handle for transparent OO programming - eval "require IO::Handle" && return new IO::Handle; + eval "require IO::Handle" or die $@; + return IO::Handle->new_from_fd(fileno($_[1]), 'w'); } $!=$@, return 0 if $@ =~ 'pipe'; diff --git a/lib/IO/Pager/Unbuffered.pm b/lib/IO/Pager/Unbuffered.pm index 67e06a7..7d043fa 100644 --- a/lib/IO/Pager/Unbuffered.pm +++ b/lib/IO/Pager/Unbuffered.pm @@ -16,7 +16,8 @@ sub new(;$) { # [FH], procedural return $_[1] if defined($_[2]) && $_[2] eq 'procedural'; #...fall back to IO::Handle for transparent OO programming - eval "require IO::Handle" && return new IO::Handle; + eval "require IO::Handle" or die $@; + return IO::Handle->new_from_fd(fileno($_[1]), 'w'); } $!=$@, return 0 if $@ =~ 'pipe'; The second problem is that IO::Handle and IO::Pager do not share a common base class, as far as I can tell. While returning an object is nice, if it does not derive from some class that IO::Pager also derives from, the promise of new() is still somewhat broken, IMHO. I am not sure what one can do about this, though, since Tie::Handle doesn't derive from IO::Handle, either. :-( David
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Thu, 12 Jul 2012 10:46:39 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
Show quoted text
>the passed file handle is ignored. You can fix that with this patch:
Yeah, I knew that when writing it, but overlooked that method; having expected them to simpy allow new to accept a parameter rather that require a different instantiation method. Also did not give it much thought and figured it did not matter since one uses the returned value, but it's an easy enough fix, thanks. Show quoted text
>The second problem is that IO::Handle and IO::Pager do not share a >common base class, as far as I can tell.
SUPER :-P But does it matter? That might make for nice isa testing, but at least now you can do $fh->print whether or not it's to a TTY. Show quoted text
>the promise of new() is still somewhat broken, IMHO
Convention I daresay, but it is documented, maybe just needs a bit more expansion. Sometimes you have to break from conventions to provide the desired functionality. Having IO::Pager also inherit from IO::Handle loads unnecessary code for procedural users, and while it satisfies the "not always in the same tree" niggle, it will add in a whole slough of problems with introduced methods.
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Thu, 12 Jul 2012 17:04:57 +0200
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Jul 12, 2012, at 4:46 PM, belg4mit@pthbb.org via RT wrote: Show quoted text
>> The second problem is that IO::Handle and IO::Pager do not share a >> common base class, as far as I can tell.
> SUPER :-P > > But does it matter? That might make for nice isa testing, > but at least now you can do $fh->print whether or not it's to a TTY.
It means I have to keep some sort of `where` statement in the Moose type definition, something like this: isa => type('IO::Pager' => where { eval { $_->isa('IO::Pager') || $_->isa('IO::Handle') } }), Though I could probably use Moose::Meta::TypeConstraint::DuckType, instead: isa => duck_type([qw(say print printf)]), So I can live with that. Show quoted text
>> the promise of new() is still somewhat broken, IMHO
> Convention I daresay, but it is documented, maybe just needs a bit more > expansion. Sometimes you have to break from conventions to provide the > desired functionality.
It just seems weird to me. I wouldn't expect `DateTime->new` to return a Date::Object object, you know? Show quoted text
> Having IO::Pager also inherit from IO::Handle loads unnecessary code > for procedural users, and while it satisfies the "not always in the same tree" > niggle, it will add in a whole slough of problems with introduced methods.
Yeah. The only "correct" thing to do would probably be to add another subclass, IO::Pager::Unpaged or something, that inherits from IO::Pager and either provides the TIED implementation to print to the real file handle, or else also inherits from IO::Handle. HTH, David
Subject: Re: [rt.cpan.org #78270] AutoReply: Add `say` Support
Date: Thu, 12 Jul 2012 11:33:02 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
I'm slightly annoyed by the lying of something named Pager::Unpaged, but more so by all of the code that would be required in something that should effectively be a stub if one could bypass the parent and use the grandparen'ts methods. I suppose the class could lie, call itself IO::Pager, and inehrit from Tie::Handle directly... Will have to think about this.
On 2012-07-12 11:33:10, belg4mit@pthbb.org wrote: Show quoted text
> Will have to think about this.
*BUMP*. Had a chance to give it some thought? —Theory
On 2012-08-01 10:52:13, DWHEELER wrote: Show quoted text
> Had a chance to give it some thought?
I just ran into another issue with this: the two interfaces behave differently under -CAS. This is the option to get Perl to process @ARGV as UTF-8, but also to set the default values for system file handles (STDOUT, STDERR, STDIN) to UTF-8. See http://stackoverflow.com/a/6163129/79202 for details. Anyway, I am using -CAS and creating a pager object like so: #!/usr/bin/perl -w -CAS use 5.10.1; use utf8; use IO::Pager; my $pager = IO::Pager->new(\*STDOUT); $pager->print('Bjørn', $/); If you paste this into a script and run it, the "ø" gets turned into garbage. If you pipe it to `cat`, it emits properly. This is because we just have the STDOUT glob when the app is piped, and - CAS is working on it. When it is not piped, and we have an IO::Pager object, -CAS is not applied to its underlying file handle, so it just doesn't work. This needs to be consistent: Either IO::Pager needs to somehow respect -CAS (no idea how; maybe it can still use the handle passed to it?), or else it needs to return always an object with an underlying file handle that does not respect -CAS. Actually, now that I think about it, this issue is not specific to -CAS, but to a file handle with a layer applied. I get the same results with this script: #!/usr/local/bin/perl -w use 5.10.1; use utf8; use IO::Pager; binmode *STDOUT, ':encoding(UTF-8)'; my $pager = IO::Pager->new(*STDOUT); $pager->print('Bjørn', $/); :-( Best, David
Subject: Re: [rt.cpan.org #78270] Add `say` Support
Date: Wed, 01 Aug 2012 20:16:08 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
26 letters should be enough for anyone X-P I'll add this to the list...
Subject: Re: [rt.cpan.org #78270] Add `say` Support
Date: Thu, 2 Aug 2012 17:22:47 +0200
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Aug 2, 2012, at 2:16 AM, belg4mit@pthbb.org via RT wrote: Show quoted text
> 26 letters should be enough for anyone X-P > > I'll add this to the list...
Thanks. You want me to change the title of this ticket, since the `say` issue was addressed quickly, but my aside about the interface has lead to most of the discussion? David
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Thu, 02 Aug 2012 12:32:36 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
Updated subject. Should be able to round up some tuits this weekend. I don't expect -CAS to be too hard, perlrun(1) documents ${^UNICODE} The bigger pain is an identical feature-set for non-paged output, without reimplimenting everything a second time. IO::Handle actually turns out to be largely useless for this purpose. I may just have to bite the bullet though, and do that. If I'm lucky I can just replace the init method in the non-paged class (IO::Pager::less = pagerless). On the other hand, as a result of tackling this I've refactored some of the code to not be *quite* so hairy, and the various new()s and open()s in the current code (not yet push'd) are more rational.
On 2012-08-02 12:32:45, belg4mit@pthbb.org wrote: Show quoted text
> Updated subject. Should be able to round up some tuits this weekend. > > I don't expect -CAS to be too hard, perlrun(1) documents ${^UNICODE}
I don't think -CAS is the issue so much as the IO layer applied to the file handle passed to you. Hence my example using binmode(). —Theory
Perhaps, but I'd argue that the order of operations in your example is "wrong" since there's a working binmode method that can be applied to the object. I can try to use PerlIO::get_layers($fh), but that would seem to preclude any sort of (incidental) support for stdio perls.
<strike>but that would seem to preclude any sort of (incidental) support for stdio perls.</strike>
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Thu, 2 Aug 2012 19:35:20 +0200
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Aug 2, 2012, at 7:23 PM, Jerrad Pierce via RT wrote: Show quoted text
> Perhaps, but I'd argue that the order of operations in > your example is "wrong" since there's a working binmode > method that can be applied to the object.
Oh, maybe. Seems weird, though, that if I passed a file handle that happened to already have been `binmode`d (not unusual for STDOUT; see utf8::all), and then have to do it again after getting the object back. David
Hello, Sorry for the delays. I'm not sure what the final ETA for this is, as real life has intervened somewhat, and I began some majorish restructuring at the same time as addressing the many issues brought up in #78270. However, I've pushed out some edits I was sitting to github, and you're welcome to make changes as needed. I can even give you commitbits to PAUSE if you'd like; fangly is the owner of the github repository <https://github.com/fangly/io-pager> The master branch has rudimentary fallback support to the original filehandle, and the pagerless branch is forked from that with the beginnings of support for full OO fallback. It looks like that class needs to either reimplement every method using the original filehandle, or inherit In summary, a recap of recent issues and their status: * Win32 testing issue (#75181), #8(&11) applied, #9 is skipped * Support say (#78270), fixed * The object is always an IO::Pager (sub)class, should be fixed * Use original filehandle if not paging, should be fixed * Clone original fielhandle layers to object, should be fixed * Full-fledged OO fallback, beginning of a implementation in branch I hope this helps
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Thu, 23 Aug 2012 10:43:27 -0700
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Aug 22, 2012, at 8:32 PM, Jerrad Pierce via RT wrote: Show quoted text
> * Win32 testing issue (#75181), #8(&11) applied, #9 is skipped
This is the main thing I want to see fixed in a new release. Once it works, Sqitch will be built as a PPM and available to all ActivePerl users, which would be very cool. Show quoted text
> * Support say (#78270), fixed > * The object is always an IO::Pager (sub)class, should be fixed > * Use original filehandle if not paging, should be fixed > * Clone original fielhandle layers to object, should be fixed > * Full-fledged OO fallback, beginning of a implementation in branch
Sounds like a release of what you have so far would be very useful in the short term, eh? Thanks, David
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Thu, 23 Aug 2012 19:07:36 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
Show quoted text
>Sounds like a release of what you have so far would be very useful in the short term, eh?
Sure. Mind pulling a copy and kicking the tires a bit? https://github.com/fangly/io-pager/zipball/master
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Thu, 23 Aug 2012 16:39:37 -0700
To: bug-IO-Pager [...] rt.cpan.org
From: David E. Wheeler <dwheeler [...] cpan.org>
On Aug 23, 2012, at 4:07 PM, belg4mit@pthbb.org via RT wrote: Show quoted text
> Sure. Mind pulling a copy and kicking the tires a bit? > https://github.com/fangly/io-pager/zipball/master
I updated my clone. Test 12 fails on OS X: PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/01-load.t ........................ ok t/02-which.t ....................... ok t/02-which_interactive.t ........... ok t/03-bald_interactive.t ............ ok t/04-buffered_interactive.t ........ ok t/05-binmode_interactive.t ......... ok t/06-scalar_interactive.t .......... ok t/07-oo_interactive.t .............. ok t/08-redirect.t .................... ok t/09-open.t ........................ ok t/10-close_interactive.t ........... ok t/11-redirect-oo.t ................. ok t/12-preservelayers_interactive.t .. print() on unopened filehandle GEN0 at /usr/local/lib/perl5/5.16.0/darwin-thread-multi-2level/IO/Handle.pm line 430. print() on unopened filehandle GEN0 at /usr/local/lib/perl5/5.16.0/darwin-thread-multi-2level/IO/Handle.pm line 430. close() on unopened filehandle GEN0 at /usr/local/lib/perl5/5.16.0/darwin-thread-multi-2level/IO/Handle.pm line 384. t/12-preservelayers_interactive.t .. Failed 1/1 subtests Test Summary Report ------------------- t/12-preservelayers_interactive.t (Wstat: 0 Tests: 0 Failed: 0) Parse errors: Bad plan. You planned 1 tests but ran 0. Files=13, Tests=21, 7 wallclock secs ( 0.07 usr 0.04 sys + 1.71 cusr 0.13 csys = 1.95 CPU) Result: FAIL Failed 1/13 test programs. 0/21 subtests failed. make: *** [test_dynamic] Error 255 BTW, you might want to ask Christian Walde (MITHALDU) to take it for a spin on Win32 via RT#75181. Best, David
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Thu, 23 Aug 2012 20:35:33 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
Thanks. Oops! I forgot to skip_interactive. Does it fail When you run `perl t.pl`? I thought I did suggest he test it out in my response yesterday?
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Thu, 23 Aug 2012 17:46:55 -0700
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Aug 23, 2012, at 5:35 PM, belg4mit@pthbb.org via RT wrote: Show quoted text
> Oops! I forgot to skip_interactive. Does it fail When you run `perl t.pl`? > > I thought I did suggest he test it out in my response yesterday?
Yes, I am prompted. If I hit Y it passes. If I hit n it fails. It should not prompt at all, of course. David
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Fri, 24 Aug 2012 07:51:55 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
Show quoted text
> It should not prompt at all, of course.
Well there are two test auites, automated (make test) and interactive (perl t.pl), I forgot to add the code to prevent that one from being executed in automated mode. That's been fixed.
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Mon, 27 Aug 2012 14:31:14 -0700
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
Great, seems to work for me, thanks! I will watch for your release. Best, David
Heya, Any chance of a release soon with the Windows fixes? Thanks! David
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Wed, 05 Sep 2012 16:14:42 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
Wtf? I just wrote last niht that they'd been uploaded to CPAN Did you remove yourself from the Window bug requestors? Here it is http://search.cpan.org/~jpgierce/IO-Pager-0.30/
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Wed, 5 Sep 2012 13:21:20 -0700
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Sep 5, 2012, at 1:14 PM, "belg4mit@pthbb.org via RT" <bug-IO-Pager@rt.cpan.org> wrote: Show quoted text
> Wtf? I just wrote last niht that they'd been uploaded to CPAN > Did you remove yourself from the Window bug requestors?
Oh, sorry, missed that. I don' think I was ever Cc'd on that ticket. Will bug the ActivePerl folks about it. Best, David
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Wed, 05 Sep 2012 16:28:26 -0400
To: bug-IO-Pager [...] rt.cpan.org
From: Jerrad Pierce <belg4mit [...] pthbb.org>
You mean to roll a new PPM?
Subject: Re: [rt.cpan.org #78270] Support C<say> => Unicode & non-paged robustness
Date: Wed, 5 Sep 2012 13:35:57 -0700
To: bug-IO-Pager [...] rt.cpan.org
From: "David E. Wheeler" <dwheeler [...] cpan.org>
On Sep 5, 2012, at 1:28 PM, "belg4mit@pthbb.org via RT" <bug-IO-Pager@rt.cpan.org> wrote: Show quoted text
> You mean to roll a new PPM?
Yes. The Sqitch build on ActivePerl fails because of the IO::Pager issues. They said they'd run them again once you released a fix. Keep an eye here if you like: http://code.activestate.com/ppm/IO-Pager/ It updates daily. Best, David