line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::UTOPIA::Utils; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
191949
|
use 5.006; |
|
2
|
|
|
|
|
9
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
293
|
|
6
|
2
|
|
|
2
|
|
12
|
use Exporter qw( import ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
101
|
|
7
|
2
|
|
|
2
|
|
11
|
use vars qw( $a $b ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
364
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Acme::UTOPIA::Utils |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.02 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Utilities for transforming and aggregating lists. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Acme::UTOPIA::Utils qw( fold ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $params = fold { $a . '&' . $b } @fields; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 EXPORT |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
fold |
32
|
|
|
|
|
|
|
sum |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our @EXPORT_OK = qw( fold sum ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 fold( BLOCK, LIST ) |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Fold a list through repeated application of the supplied |
43
|
|
|
|
|
|
|
block/subroutine. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub fold (&@) { |
48
|
5
|
|
|
5
|
1
|
18
|
my $accumulator = \&{shift @_}; |
|
5
|
|
|
|
|
11
|
|
49
|
|
|
|
|
|
|
|
50
|
5
|
|
|
|
|
8
|
return do { |
51
|
2
|
|
|
2
|
|
13
|
no strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
308
|
|
52
|
|
|
|
|
|
|
|
53
|
5
|
|
|
|
|
7
|
my ( $a, $b ); |
54
|
5
|
|
|
|
|
12
|
my $caller = caller; |
55
|
5
|
|
|
|
|
6
|
local *{$caller . '::a'} = \$a; |
|
5
|
|
|
|
|
19
|
|
56
|
5
|
|
|
|
|
8
|
local *{$caller . '::b'} = \$b; |
|
5
|
|
|
|
|
14
|
|
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
7
|
$a = shift; |
59
|
5
|
|
|
|
|
10
|
foreach my $next ( @_ ) { |
60
|
9
|
|
|
|
|
33
|
$b = $next; |
61
|
9
|
|
|
|
|
21
|
$a = $accumulator->(); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$a |
65
|
5
|
|
|
|
|
48
|
}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 sum( LIST ) |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Sum the supplied list of numerics. Non-numeric |
71
|
|
|
|
|
|
|
values will be ignored. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub sum { |
76
|
2
|
|
|
2
|
|
14
|
no warnings 'numeric'; # Non-numeric values are ignored |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
202
|
|
77
|
0
|
|
|
0
|
1
|
|
fold { $a * $b } 0.0, @_ |
|
0
|
|
|
0
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 AUTHOR |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Robert Durie, C<< >> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 BUGS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
87
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
88
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SUPPORT |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
perldoc Acme::UTOPIA::Utils |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
You can also look for information at: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over 4 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * CPAN Ratings |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * Search CPAN |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Copyright 2015 Robert Durie. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
131
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
132
|
|
|
|
|
|
|
copy of the full license at: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
137
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
138
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
139
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
142
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
143
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
146
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
149
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
150
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
151
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
152
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
153
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
154
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
155
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
158
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
159
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
160
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
161
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
162
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
163
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
164
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; # End of Acme::UTOPIA::Utils |