/usr/share/perl5/autobox/List/Util.pm is in libautobox-list-util-perl 20090629-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | package autobox::List::Util;
use warnings;
use strict;
use base 'autobox';
sub import {
my $class = shift;
$class->SUPER::import(ARRAY => 'autobox::List::Util::_private');
}
package autobox::List::Util::_private;
use strict;
use warnings;
use Module::Load;
sub first {
load List::Util;
my ($self, $coderef) = @_;
return List::Util::first { $coderef->() } @$self
}
sub max {
load List::Util;
my $self = shift;
return List::Util::max @$self
}
sub maxstr {
load List::Util;
my $self = shift;
return List::Util::maxstr @$self
}
sub min {
load List::Util;
my $self = shift;
return List::Util::min @$self
}
sub minstr {
load List::Util;
my $self = shift;
return List::Util::minstr @$self
}
sub reduce {
load List::Util;
my ($self, $coderef) = @_;
return List::Util::reduce {
#FIXME: this needs to know the package we are exporting to
local ($main::a, $main::b) = ($a, $b);
$coderef->();
} @$self
}
sub shuffle {
load List::Util;
my $self = shift;
return List::Util::shuffle @$self if wantarray;
return [ List::Util::shuffle @$self ];
}
sub sum {
load List::Util;
my $self = shift;
return List::Util::sum @$self
}
package autobox::List::Util;
=head1 NAME
autobox::List::Util - bring the List::Util functions to autobox
=head1 VERSION
Version 20090629
=cut
our $VERSION = '20090629';
=head1 SYNOPSIS
C<autobox::List::Util> brings all of the functions from List::Util
to arrays as methods.
use autobox::List::Util;
my @array = qw/ foo bar baz /;
print @array->first(sub { /ar/ }), "\n"; # "bar"
print [5, 6, 3, 4]->max, "\n"; # 6
print @array->maxstr, "\n"; # baz
print [5, 6, 3, 4]->min, "\n"; # 3
print @array->minstr, "\n"; # foo
print [1 .. 10]->shuffle, "\n"; #1 to 10 randomly shuffled
print [1 .. 10]->sum, "\n"; # 55
print [1 .. 10]->reduce( sub { $a + $b } ), "\n"; # 55
=head1 METHODS
=head2 first(coderef)
This method behaves nearly the same as the first function from List::Util,
but it takes a coderef not a block because methods can't use prototypes.
=head2 reduce(coderef)
This method behaves nearly the same as the reduce function from List::Util,
but it takes a coderef not a block for the same reason. It also has a bug
(see L<BUGS>)
=head2 shuffle
If called in scalar context it returns a reference to an array instead
of a list. This allows shuffle to be chained with other calls.
=head2 max, maxstr, min, minstr, sum
These methods behave exactly the same as their List::Util counterparts.
=head1 AUTHOR
Chas. J. Owens IV, C<< <chas.owens at gmail.com> >>
=head1 BUGS
The reduce method works with $main::a and $main::b, not your current
package's $a and $b, so you need to say
print @array->reduce( sub { $main::a + $main::b } ), "\n";
if you are not in the main package. Reduce uses $_, so it doesn't
suffer from this problem.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc autobox::List::Util
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=autobox-List-Util>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/autobox-List-Util>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/autobox-List-Util>
=item * Search CPAN
L<http://search.cpan.org/dist/autobox-List-Util/>
=back
=head1 ACKNOWLEDGEMENTS
=head1 COPYRIGHT & LICENSE
Copyright 2009 Chas. J. Owens IV, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
1; # End of autobox::List::Util
|