File Coverage

blib/lib/Perl6/Take.pm
Criterion Covered Total %
statement 27 27 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 41 42 97.6


line stmt bran cond sub pod time code
1             package Perl6::Take;
2              
3 2     2   49979 use warnings;
  2         6  
  2         63  
4 2     2   11 use strict;
  2         4  
  2         69  
5              
6 2     2   17 use Carp;
  2         9  
  2         586  
7              
8             our $VERSION = '0.04';
9              
10             our @GATHER;
11              
12             sub gather (&) {
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     15 1 6575 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         42 shift->();
22              
23 14         23 return @{ $GATHER[-1] };
  14         58  
24             }
25              
26             sub take (@) {
27 24 100   24 1 827 Carp::croak("take with no gather") unless @GATHER;
28 23 50       60 Carp::confess("internal error: gather cell not a listref") unless
29             ref $GATHER[-1] eq 'ARRAY';
30 23 100       66 Carp::croak('take with no args, did you mean "take $_"?') unless @_;
31              
32 22         27 push @{ $GATHER[-1] }, @_;
  22         48  
33 22         46 return @_; # for possible en passant assignment
34             }
35              
36             sub import {
37 2     2   19 my $caller = caller;
38 2     2   12 no strict;
  2         3  
  2         184  
39 2         18 *{"$caller\::gather"} = \&gather;
  2         12  
40 2         5 *{"$caller\::take"} = \&take;
  2         2638  
41             }
42              
43             1;
44              
45             __END__