develooper Front page | perl.perl6.users | Postings from October 2018

Re: Appropriate last words

Thread Previous | Thread Next
From:
Brian Duggan
Date:
October 26, 2018 14:22
Subject:
Re: Appropriate last words
Message ID:
CAOqZAm2sQRtmAXJynWzOij_7YWYFswq69Ax-5eGLjr0nMgKAjA@mail.gmail.com
Oh, good point!

Yes, but works --

  my @lines;
  $*OUT = $*OUT but role { method print($str) { @lines.push($str) } };
  note "stderr is ok";
  use Test;
  say "hello";
  is @lines[0], "hello\n", 'stdout is wrapped'

stderr is ok
ok 1 - stdout is wrapped


On Thu, Oct 25, 2018 at 9:39 PM Brandon Allbery <allbery.b@gmail.com> wrote:

> I didn't phrase that quite right.
>
> pyanfar Z$ 6 'my @lines; $*OUT.^find_method("print").wrap: -> $self, $str
> { @lines.push($str) }; use Test; note "hello"; is @lines[0], "hello\n",
> "wrapped err too"'
> ok 1 - wrapped err too
>
> This wraps it for every IO::Handle, not just for the IO::Handle in $*OUT.
> You may need "but" for that?
>
> On Thu, Oct 25, 2018 at 9:34 PM Brian Duggan <bduggan2@gmail.com> wrote:
>
>> On Thursday, October 25, Brandon Allbery wrote:
>> > You can't actually wrap print that way, can you? Or rather, if that
>> works
>> > it wouldn't be specific to $*ERR.
>>
>> Um, you definitely can, and yes it's not specific to $*ERR, e.g.
>>
>>     my @lines;
>>     $*OUT.^find_method('print').wrap: -> $self, $str { @lines.push($str) }
>>
>>     use Test;
>>     say "hello";
>>     is @lines[0], "hello\n", 'said hello';
>>
>> produces
>>
>>     ok 1 - said hello
>>
>> Brian
>>
>
>
> --
> brandon s allbery kf8nh
> allbery.b@gmail.com
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About