File Coverage

blib/lib/List/Gather.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 26 26 100.0


line stmt bran cond sub pod time code
1             package List::Gather; # git description: 0.12-22-gfb66ce5
2             # ABSTRACT: Construct lists procedurally without temporary variables
3              
4 7     7   148326 use strict;
  7         13  
  7         218  
5 7     7   34 use warnings;
  7         11  
  7         327  
6              
7             our $VERSION = '0.13';
8              
9 7     7   3629 use Devel::CallParser;
  7         20166  
  7         444  
10 7     7   48 use Devel::CallChecker;
  7         11  
  7         345  
11              
12 7     7   40 use XSLoader;
  7         10  
  7         861  
13              
14             XSLoader::load(
15             __PACKAGE__,
16             $VERSION,
17             );
18              
19             require B::Hooks::EndOfScope
20             unless _QPARSE_DIRECTLY();
21              
22             my @keywords;
23 7     7   299 BEGIN { @keywords = qw(gather take gathered) }
24              
25 7         90 use Sub::Exporter -setup => {
26             exports => [@keywords],
27             groups => { default => [@keywords] },
28 7     7   4073 };
  7         115424  
29              
30             #pod =head1 SYNOPSIS
31             #pod
32             #pod use List::Gather;
33             #pod
34             #pod my @list = gather {
35             #pod while (<$fh>) {
36             #pod next if /^\s*$/;
37             #pod next if /^\s*#/;
38             #pod last if /^(?:__END__|__DATA__)$/;
39             #pod take $_ if some_predicate($_);
40             #pod }
41             #pod
42             #pod take @defaults unless gathered;
43             #pod };
44             #pod
45             #pod =head1 DESCRIPTION
46             #pod
47             #pod This module provides a C keyword that allows lists to be constructed
48             #pod procedurally, without the need for a temporary variable.
49             #pod
50             #pod Within the block controlled by a C any call to C pushes that
51             #pod call's argument list to an implicitly created array.
52             #pod
53             #pod C returns the list of values taken during its block's execution.
54             #pod
55             #pod =head1 EXAMPLES
56             #pod
57             #pod my @interesting_child_nodes = gather for my $n (@nodes) {
58             #pod take $n->all_children
59             #pod if $n->is_interesting;
60             #pod };
61             #pod
62             #pod my @last_10_events = gather {
63             #pod while ($log->has_event) {
64             #pod take $log->next_event;
65             #pod }
66             #pod
67             #pod shift gathered while gathered > 10;
68             #pod };
69             #pod
70             #pod my @search_results = gather {
71             #pod $user_interface->register_status_callback(sub {
72             #pod sprintf "Searching... Found %d matches so far", scalar gathered;
73             #pod });
74             #pod
75             #pod wait_for_search_results(sub {
76             #pod my ($result) = @_;
77             #pod take $result;
78             #pod }, @search_terms);
79             #pod
80             #pod $user_interface->register_status_callback(sub {
81             #pod sprintf "Found a total of %d", scalar gathered;
82             #pod });
83             #pod };
84             #pod
85             #pod my @leaf_nodes = gather {
86             #pod $graph->visit_all_nodes_recursively(sub {
87             #pod my ($node) = @_;
88             #pod take $node if $node->is_leaf;
89             #pod }
90             #pod };
91             #pod
92             #pod =func gather
93             #pod
94             #pod gather { ... }
95             #pod gather({ ... })
96             #pod gather STMT
97             #pod
98             #pod Executes the block it has been provided with, collecting all arguments passed to
99             #pod C calls within it. After execution, the list of values collected is
100             #pod returned.
101             #pod
102             #pod Note that block C executes is equivalent to a C. It is neither
103             #pod a code nor a loop. Loop control keywords, such as C and C, as well
104             #pod as C will behave accordingly.
105             #pod
106             #pod Parens around the C block are optional.
107             #pod
108             #pod =func take
109             #pod
110             #pod take LIST
111             #pod
112             #pod Collects a C of values within the C block it has been compiled in.
113             #pod
114             #pod C returns all its arguments.
115             #pod
116             #pod C calls outside of the lexical scope of a C block are compile time
117             #pod errors. Calling C is only legal within the dynamic scope its associated
118             #pod C block.
119             #pod
120             #pod =func gathered
121             #pod
122             #pod gathered
123             #pod
124             #pod Returns the list of items collected so far during the execution of a C
125             #pod block.
126             #pod
127             #pod C calls outside of the lexical scope of a C block are compile
128             #pod time errors. Calling C outside of the dynamic scope of its associated
129             #pod C block is legal.
130             #pod
131             #pod =head1 SEE ALSO
132             #pod
133             #pod =for :list
134             #pod = L
135             #pod A non-lexical gather/take implementation that's otherwise very similar to this one
136             #pod = L
137             #pod An experimental implementation of a lazily evaluating gather/take
138             #pod = L
139             #pod A very simple gather/take implementation without lexical scoping
140             #pod = L
141             #pod Like L, but reliant on L
142             #pod = L
143             #pod A comprehensive suit list generation functions featuring a non-lexical gather/take
144             #pod
145             #pod =head1 ACKNOWLEDGEMENTS
146             #pod
147             #pod =for :list
148             #pod * Andrew Main (Zefram) Ezefram@fysh.orgE
149             #pod for providing his input in both the design and implementation of this module,
150             #pod and writing much of the infrastructure that made this module possible in the
151             #pod first place
152             #pod * Arthur Axel "fREW" Schmidt Efrioux+cpan@gmail.comE
153             #pod for his input on various aspects of this module as well as the many tests of his
154             #pod L module that this module shamelessly stole
155             #pod * Dave (autarch) Rolsky and Jesse (doy) Luehrs Edoy@tozt.netE
156             #pod for helping to improve both documentation and test coverage
157             #pod
158             #pod =cut
159              
160             1;
161              
162             __END__