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

Re: Appropriate last words

Thread Previous | Thread Next
From:
Richard Hainsworth
Date:
October 25, 2018 15:20
Subject:
Re: Appropriate last words
Message ID:
0f11fd16-5b45-fdad-725f-362a14605de3@gmail.com
I'm trying to understand this. Would someone provide a bit more explanation?

On 25/10/2018 10:47, Brian Duggan wrote:
> On Sunday, October 21, Richard Hainsworth wrote:
>> so .. either I use your suggestion of 'exit note $message' which I find
>> elegant, but so far difficult to test.
> You could always wrap things, e.g. something like --
>
> my ( $exit-args, $note-args );

The wrap documentation states:

Wraps (i.e. in-place modifies) the routine. That means a call to this 
routine first calls |&wrapper|, which then can (but doesn't have to) 
call the original routine with the |callsame|, |callwith|, |nextsame| 
and |nextwith| dispatchers. The return value from the routine is also 
the return value from the wrapper.

>
> &exit.wrap: -> $status { $exit-args = $status; fail }
Is the call to 'fail' replicating the original action of &exit?
> &note.wrap: -> |c { $note-args = c; callsame; }
Does this mean that the next routine in a chain (in this case `exit note 
... `), so in fact `exit`, is called?
>
> $*ERR.^find_method('print').wrap: -> |c { True; }
This wrap I am not so clear about. Why is `^find_method('print') needed?
>
> sub run {
>    exit note 'bye';
> }
>
> use Test;
> try run;
> is $note-args, 'bye', 'output correct';
> is $exit-args.Int, 1, 'exit status is 1';
> done-testing;
>

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