| 1 | package Perl6::Take; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | our $VERSION = '0.04'; | |||||||||
| 9 | |||||||||||
| 10 | 3 | our @GATHER; | |||||||||
| 11 | |||||||||||
| 12 | 15 | ▶ | sub gather (&) { | ||||||||
|
Subroutine
gather: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 13 | # We used to push and pop ourselves, but local's easier for cleanup | ||||||||||
| 14 | # purposes, and since the gather stack only contains references to the | ||||||||||
| 15 | # takelists, copying it isn't expensive. Unless you have like a couple | ||||||||||
| 16 | # thousand nested gathers, in which case you're beyond my help. | ||||||||||
| 17 | 15 | local @GATHER = (@GATHER, []); | |||||||||
| 18 | |||||||||||
| 19 | # Here needs to come some trick to see the code didn't explicitly say | ||||||||||
| 20 | # "return". But that's presumed impossible in pure Perl 5. | ||||||||||
| 21 | 15 | shift->(); | |||||||||
| 22 | |||||||||||
| 23 | 14 | return @{ $GATHER[-1] }; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 24 | ▶ | sub take (@) { | ||||||||
|
Subroutine
take: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 27 | 24 | ▶ | Carp::croak("take with no gather") unless @GATHER; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 23 | ▶ | Carp::confess("internal error: gather cell not a listref") unless | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | ref $GATHER[-1] eq 'ARRAY'; | ||||||||||
| 30 | 23 | ▶ | Carp::croak('take with no args, did you mean "take $_"?') unless @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | 22 | push @{ $GATHER[-1] }, @_; | |||||||||
| 33 | 22 | return @_; # for possible en passant assignment | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 2 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 2 | my $caller = caller; | |||||||||
| 38 | 3 | ▶ | no strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 2 | *{"$caller\::gather"} = \&gather; | |||||||||
| 40 | 2 | *{"$caller\::take"} = \&take; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 3 | 1; | |||||||||
| 44 | |||||||||||
| 45 | __END__ | ||||||||||