Bulk/Util.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 100% 5 / 5 totaltotal 100% 59 / 59 CC 4 SCAR 3.0
CC
4
Cov
100%
bulk
2.0
cat
2.0
__ANON__
2.0
CRAP 1.4
« Bulk/DBI.pm ↑ Summary Bulk/FileHandle.pm »
1 package Data::Stream::Bulk::Util;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $Data::Stream::Bulk::Util::AUTHORITY = 'cpan:NUFFIN';
4 }
5 {
6 2 $Data::Stream::Bulk::Util::VERSION = '0.11';
7 }
8  
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 # ABSTRACT: Utility functions for L<Data::Stream::Bulk>
12  
13 2 ▶use Data::Stream::Bulk::Nil;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Data::Stream::Bulk::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
21 exports => [qw(nil bulk cat filter unique)],
22 2 };
23  
24 # use constant nil => Data::Stream::Bulk::Nil->new;
25 20 ▶sub nil () { Data::Stream::Bulk::Nil->new }
Subroutine nil: called CC=1 SCAR=0.0
Pod documented
26  
27 14 ▶sub bulk (@) { return @_ ? Data::Stream::Bulk::Array->new( array => [ @_ ] ) : nil }
Subroutine bulk: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 13 1 14
28  
29 4 ▶sub cat (@) { return @_ ? shift->cat(@_) : nil }
Subroutine cat: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 3 1 4
30  
31 1 ▶sub filter (&$) {
Subroutine filter: called CC=1 SCAR=0.0
Pod documented
32 1 my ( $filter, $stream ) = @_;
33 1 $stream->filter($filter);
34 }
35  
36 2 ▶sub unique ($) {
Subroutine unique: called CC=1 SCAR=0.0
Pod documented
37 2 my %seen;
38 2 ▶ shift->filter(sub { [ grep { !$seen{ref($_) ? refaddr($_) : $_}++ } @$_ ] }); # FIXME Hash::Util::FieldHash::Compat::id()?
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 5 7 12
39 }
40  
41 2 __PACKAGE__;
42  
43  
44  
45 =pod
46  
47 =head1 NAME
48  
49 Data::Stream::Bulk::Util - Utility functions for L<Data::Stream::Bulk>
50  
51 =head1 VERSION
52  
53 version 0.11
54  
55 =head1 SYNOPSIS
56  
57 use Data::Stream::Bulk::Util qw(array);
58  
59 use namespace::clean;
60  
61 # Wrap a list in L<Data::Stream::Bulk::Array>
62 return bulk(qw(foo bar gorch baz));
63  
64 # return an empty resultset
65 return nil();
66  
67 =head1 DESCRIPTION
68  
69 This module exports convenience functions for use with L<Data::Stream::Bulk>.
70  
71 =head1 EXPORTS
72  
73 L<Sub::Exporter> is used to create the C<import> routine, and all of its
74 aliasing/currying goodness is of course supported.
75  
76 =over 4
77  
78 =item nil
79  
80 Creates a new L<Data::Stream::Bulk::Nil> object.
81  
82 Takes no arguments.
83  
84 =item bulk @items
85  
86 Creates a new L<Data::Stream::Bulk::Array> wrapping C<@items>.
87  
88 =item cat @streams
89  
90 Concatenate several streams together.
91  
92 Returns C<nil> if no arguments are provided.
93  
94 =item filter { ... } $stream
95  
96 Calls C<filter> on $stream with the provided filter.
97  
98 =item unique $stream
99  
100 Filter the stream to remove duplicates.
101  
102 Note that memory use may potentially scale to O(k) where k is the number of
103 distinct items, because this is implemented in terms of a seen hash.
104  
105 In the future this will be optimized to be iterative for sorted streams.
106  
107 References are keyed by their refaddr (see L<Hash::Util::FieldHash/id>).
108  
109 =back
110  
111 =head1 AUTHOR
112  
113 Yuval Kogman <nothingmuch@woobling.org>
114  
115 =head1 COPYRIGHT AND LICENSE
116  
117 This software is copyright (c) 2012 by Yuval Kogman.
118  
119 This is free software; you can redistribute it and/or modify it under
120 the same terms as the Perl 5 programming language system itself.
121  
122 =cut
123  
124  
125 __END__
« Bulk/DBI.pm ↑ Summary Bulk/FileHandle.pm »