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