r51895 - in /branches/upstream/libautobox-list-util-perl: ./ current/ current/lib/ current/lib/autobox/ current/lib/autobox/List/ current/t/

jeremiah-guest at users.alioth.debian.org jeremiah-guest at users.alioth.debian.org
Sat Jan 30 21:09:38 UTC 2010


Author: jeremiah-guest
Date: Sat Jan 30 21:09:16 2010
New Revision: 51895

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=51895
Log:
[svn-inject] Installing original source of libautobox-list-util-perl

Added:
    branches/upstream/libautobox-list-util-perl/
    branches/upstream/libautobox-list-util-perl/current/
    branches/upstream/libautobox-list-util-perl/current/Build.PL
    branches/upstream/libautobox-list-util-perl/current/Changes
    branches/upstream/libautobox-list-util-perl/current/MANIFEST
    branches/upstream/libautobox-list-util-perl/current/MANIFEST.SKIP
    branches/upstream/libautobox-list-util-perl/current/META.yml
    branches/upstream/libautobox-list-util-perl/current/Makefile.PL
    branches/upstream/libautobox-list-util-perl/current/README
    branches/upstream/libautobox-list-util-perl/current/lib/
    branches/upstream/libautobox-list-util-perl/current/lib/autobox/
    branches/upstream/libautobox-list-util-perl/current/lib/autobox/List/
    branches/upstream/libautobox-list-util-perl/current/lib/autobox/List/Util.pm
    branches/upstream/libautobox-list-util-perl/current/t/
    branches/upstream/libautobox-list-util-perl/current/t/00-load.t
    branches/upstream/libautobox-list-util-perl/current/t/first.t   (with props)
    branches/upstream/libautobox-list-util-perl/current/t/max.t   (with props)
    branches/upstream/libautobox-list-util-perl/current/t/maxstr.t   (with props)
    branches/upstream/libautobox-list-util-perl/current/t/min.t   (with props)
    branches/upstream/libautobox-list-util-perl/current/t/minstr.t   (with props)
    branches/upstream/libautobox-list-util-perl/current/t/reduce.t   (with props)
    branches/upstream/libautobox-list-util-perl/current/t/shuffle.t   (with props)
    branches/upstream/libautobox-list-util-perl/current/t/sum.t   (with props)

Added: branches/upstream/libautobox-list-util-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/Build.PL?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/Build.PL (added)
+++ branches/upstream/libautobox-list-util-perl/current/Build.PL Sat Jan 30 21:09:16 2010
@@ -1,0 +1,20 @@
+use strict;
+use warnings;
+use Module::Build;
+
+my $builder = Module::Build->new(
+    module_name         => 'autobox::List::Util',
+    license             => 'perl',
+    dist_author         => 'Chas. J. Owens IV <chas.owens at gmail.com>',
+    dist_version_from   => 'lib/autobox/List/Util.pm',
+    build_requires => {
+        'Test::More'   => 0,
+	'Module::Load' => 0,
+	'List::Util'   => 0,
+	'autobox'      => 0,
+    },
+    add_to_cleanup      => [ 'autobox-List-Util-*' ],
+    create_makefile_pl => 'traditional',
+);
+
+$builder->create_build_script();

Added: branches/upstream/libautobox-list-util-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/Changes?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/Changes (added)
+++ branches/upstream/libautobox-list-util-perl/current/Changes Sat Jan 30 21:09:16 2010
@@ -1,0 +1,5 @@
+Revision history for autobox-List-Util
+
+20090429    20090430/0338
+        First cut
+

Added: branches/upstream/libautobox-list-util-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/MANIFEST?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/MANIFEST (added)
+++ branches/upstream/libautobox-list-util-perl/current/MANIFEST Sat Jan 30 21:09:16 2010
@@ -1,0 +1,17 @@
+Build.PL
+Changes
+lib/autobox/List/Util.pm
+MANIFEST
+MANIFEST.SKIP
+README
+t/00-load.t
+t/first.t
+t/max.t
+t/maxstr.t
+t/min.t
+t/minstr.t
+t/reduce.t
+t/shuffle.t
+t/sum.t
+Makefile.PL
+META.yml

Added: branches/upstream/libautobox-list-util-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/MANIFEST.SKIP?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/MANIFEST.SKIP (added)
+++ branches/upstream/libautobox-list-util-perl/current/MANIFEST.SKIP Sat Jan 30 21:09:16 2010
@@ -1,0 +1,34 @@
+#!start included /usr/local/perl/5.10.0/lib/5.10.0/ExtUtils/MANIFEST.SKIP
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+\bSCCS\b
+,v$
+\B\.svn\b
+\B\.git\b
+\B\.gitignore\b
+\b_darcs\b
+ 
+# Avoid Makemaker generated and utility files.
+\bMANIFEST\.bak
+\bMakefile$
+\bblib/
+\bMakeMaker-\d
+\bpm_to_blib\.ts$
+\bpm_to_blib$
+\bblibdirs\.ts$ # 6.18 through 6.25 generated this
+ 
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build/
+ 
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+ 
+# Avoid Devel::Cover files.
+\bcover_db\b
+#!end included /usr/local/perl/5.10.0/lib/5.10.0/ExtUtils/MANIFEST.SKIP

Added: branches/upstream/libautobox-list-util-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/META.yml?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/META.yml (added)
+++ branches/upstream/libautobox-list-util-perl/current/META.yml Sat Jan 30 21:09:16 2010
@@ -1,0 +1,22 @@
+---
+name: autobox-List-Util
+version: 20090629
+author:
+  - 'Chas. J. Owens IV <chas.owens at gmail.com>'
+abstract: bring the List::Util functions to autobox
+license: perl
+resources:
+  license: http://dev.perl.org/licenses/
+build_requires:
+  List::Util: 0
+  Module::Load: 0
+  Test::More: 0
+  autobox: 0
+provides:
+  autobox::List::Util:
+    file: lib/autobox/List/Util.pm
+    version: 20090629
+generated_by: Module::Build version 0.33
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.4.html
+  version: 1.4

Added: branches/upstream/libautobox-list-util-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/Makefile.PL?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/Makefile.PL (added)
+++ branches/upstream/libautobox-list-util-perl/current/Makefile.PL Sat Jan 30 21:09:16 2010
@@ -1,0 +1,17 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.33
+use ExtUtils::MakeMaker;
+WriteMakefile
+(
+          'NAME' => 'autobox::List::Util',
+          'VERSION_FROM' => 'lib/autobox/List/Util.pm',
+          'PREREQ_PM' => {
+                           'List::Util' => 0,
+                           'Module::Load' => 0,
+                           'Test::More' => 0,
+                           'autobox' => 0
+                         },
+          'INSTALLDIRS' => 'site',
+          'EXE_FILES' => [],
+          'PL_FILES' => {}
+        )
+;

Added: branches/upstream/libautobox-list-util-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/README?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/README (added)
+++ branches/upstream/libautobox-list-util-perl/current/README Sat Jan 30 21:09:16 2010
@@ -1,0 +1,28 @@
+autobox-List-Util
+
+Make all of the functions in List::Util into methods that can be
+called on arrays and arrayrefs
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+	perl Build.PL
+	./Build
+	./Build test
+	./Build install
+
+SUPPORT AND DOCUMENTATION
+
+After installing, you can find documentation for this module with the
+perldoc command.
+
+    perldoc autobox::List::Util
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2009 Chas. J. Owens IV
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+

Added: branches/upstream/libautobox-list-util-perl/current/lib/autobox/List/Util.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/lib/autobox/List/Util.pm?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/lib/autobox/List/Util.pm (added)
+++ branches/upstream/libautobox-list-util-perl/current/lib/autobox/List/Util.pm Sat Jan 30 21:09:16 2010
@@ -1,0 +1,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

Added: branches/upstream/libautobox-list-util-perl/current/t/00-load.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/t/00-load.t?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/t/00-load.t (added)
+++ branches/upstream/libautobox-list-util-perl/current/t/00-load.t Sat Jan 30 21:09:16 2010
@@ -1,0 +1,8 @@
+use blib;
+use Test::More tests => 1;
+
+BEGIN {
+	use_ok( 'autobox::List::Util' );
+}
+
+diag( "Testing autobox::List::Util $autobox::List::Util::VERSION, Perl $], $^X" );

Added: branches/upstream/libautobox-list-util-perl/current/t/first.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/t/first.t?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/t/first.t (added)
+++ branches/upstream/libautobox-list-util-perl/current/t/first.t Sat Jan 30 21:09:16 2010
@@ -1,0 +1,82 @@
+use blib;
+use strict;
+use warnings;
+use autobox::List::Util;
+
+
+use Test::More tests => 13;
+
+my $v = [9,4,5,6]->first( sub { 8 == ($_ - 1) } );
+
+is($v, 9, 'one more than 8');
+
+$v = [1,2,3,4]->first( sub { 0 } );
+is($v, undef, 'none match');
+
+$v = []->first( sub { 0 } );
+is($v, undef, 'no args');
+
+$v = [[qw(a b c)], [qw(d e f)], [qw(g h i)]]->first(
+	sub { $_->[1] le "e" and "e" le $_->[2] }
+);
+is_deeply($v, [qw(d e f)], 'reference args');
+
+# Check that eval{} inside the block works correctly
+my $i = 0;
+$v = [0,1,2,3,4,5,5]->first( sub { eval { die }; ($i == 5, $i = $_)[0] } );
+is($v, 5, 'use of eval');
+
+$v = eval { [0,0,1]->first( sub { die if $_ } )  };
+is($v, undef, 'use of die');
+
+sub foobar { 
+	["not ","not ","not "]->first( sub { !defined(wantarray) || wantarray } )
+}
+
+($v) = foobar();
+is($v, undef, 'wantarray');
+
+# Can we leave the sub with 'return'?
+$v = [2,4,6,12]->first( sub {return ($_>6)} );
+is($v, 12, 'return');
+
+# ... even in a loop?
+$v = [2,4,6,12]->first( sub {while(1) {return ($_>6)} } );
+is($v, 12, 'return from loop');
+
+# Does it work from another package?
+{ 
+	package Foo;
+	use autobox::List::Util;
+	::is( [1..4,24]->first(sub{$_>4}), 24, 'other package');
+}
+
+# Can we undefine a first sub while it's running?
+sub self_immolate {undef &self_immolate; 1}
+eval { $v = [1,2]->first(\&self_immolate) };
+like($@, qr/^Can't undef active subroutine/, "undef active sub");
+
+# Redefining an active sub should not fail, but whether the
+# redefinition takes effect immediately depends on whether we're
+# running the Perl or XS implementation.
+
+{
+	local $SIG{__WARN__} = sub {}; #trap warnings;
+	sub self_updating { local $^W; *self_updating = sub{1} ;1}
+	eval { $v = [1,2]->first(\&self_updating) };
+	is($@, '', 'redefine self');
+}
+
+{ my $failed = 0;
+
+    sub rec { my $n = shift;
+        if (!defined($n)) {  # No arg means we're being called by first()
+            return 1; }
+        if ($n<5) { rec($n+1); }
+        else { $v = [1,2]->first(\&rec) }
+        $failed = 1 if !defined $n;
+    }
+
+    rec(1);
+    ok(!$failed, 'from active sub');
+}

Propchange: branches/upstream/libautobox-list-util-perl/current/t/first.t
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libautobox-list-util-perl/current/t/max.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/t/max.t?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/t/max.t (added)
+++ branches/upstream/libautobox-list-util-perl/current/t/max.t Sat Jan 30 21:09:16 2010
@@ -1,0 +1,21 @@
+use blib;
+use strict;
+use autobox::List::Util;
+
+use Test::More tests => 4;
+
+my $v;
+
+$v = [1]->max;
+is($v, 1, 'single arg');
+
+$v = [1,2]->max;
+is($v, 2, '2-arg ordered');
+
+$v = [2,1]->max;
+is($v, 2, '2-arg reverse ordered');
+
+my @a = map { rand() } 1 .. 20;
+my @b = sort { $a <=> $b } @a;
+$v = @a->max;
+is($v, $b[-1], '20-arg random order');

Propchange: branches/upstream/libautobox-list-util-perl/current/t/max.t
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libautobox-list-util-perl/current/t/maxstr.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/t/maxstr.t?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/t/maxstr.t (added)
+++ branches/upstream/libautobox-list-util-perl/current/t/maxstr.t Sat Jan 30 21:09:16 2010
@@ -1,0 +1,21 @@
+use blib;
+use strict;
+use autobox::List::Util;
+
+use Test::More tests => 4;
+
+my $v;
+
+$v = ['a']->maxstr;
+is($v, 'a', 'single arg');
+
+$v = ['a','b']->maxstr;
+is($v, 'b', '2-arg ordered');
+
+$v = ['B','A']->maxstr;
+is($v, 'B', '2-arg reverse ordered');
+
+my @a = map { pack("u", pack("C*",map { int(rand(256))} (0..int(rand(10) + 2)))) } 0 .. 20;
+my @b = sort { $a cmp $b } @a;
+$v = @a->maxstr;
+is($v, $b[-1], 'random ordered');

Propchange: branches/upstream/libautobox-list-util-perl/current/t/maxstr.t
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libautobox-list-util-perl/current/t/min.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/t/min.t?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/t/min.t (added)
+++ branches/upstream/libautobox-list-util-perl/current/t/min.t Sat Jan 30 21:09:16 2010
@@ -1,0 +1,21 @@
+use blib;
+use strict;
+use autobox::List::Util;
+
+use Test::More tests => 4;
+
+my $v;
+
+$v = [(9)]->min;
+is($v, 9, 'single arg');
+
+$v = [1,2]->min;
+is($v, 1, '2-arg ordered');
+
+$v = [(2,1)]->min;
+is($v, 1, '2-arg reverse ordered');
+
+my @a = map { rand() } 1 .. 20;
+my @b = sort { $a <=> $b } @a;
+$v = [(@a)]->min;
+is($v, $b[0], '20-arg random order');

Propchange: branches/upstream/libautobox-list-util-perl/current/t/min.t
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libautobox-list-util-perl/current/t/minstr.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/t/minstr.t?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/t/minstr.t (added)
+++ branches/upstream/libautobox-list-util-perl/current/t/minstr.t Sat Jan 30 21:09:16 2010
@@ -1,0 +1,21 @@
+use blib;
+use strict;
+use autobox::List::Util;
+
+use Test::More tests => 4;
+
+my $v;
+
+$v = [('a')]->minstr;
+is($v, 'a', 'single arg');
+
+$v = [('a','b')]->minstr;
+is($v, 'a', '2-arg ordered');
+
+$v = [('B','A')]->minstr;
+is($v, 'A', '2-arg reverse ordered');
+
+my @a = map { pack("u", pack("C*",map { int(rand(256))} (0..int(rand(10) + 2)))) } 0 .. 20;
+my @b = sort { $a cmp $b } @a;
+$v = [(@a)]->minstr;
+is($v, $b[0], 'random ordered');

Propchange: branches/upstream/libautobox-list-util-perl/current/t/minstr.t
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libautobox-list-util-perl/current/t/reduce.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/t/reduce.t?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/t/reduce.t (added)
+++ branches/upstream/libautobox-list-util-perl/current/t/reduce.t Sat Jan 30 21:09:16 2010
@@ -1,0 +1,105 @@
+use blib;
+use strict;
+use autobox::List::Util;
+use Test::More tests => 19;
+
+my $v = []->reduce(sub {});
+
+is( $v,	undef,	'no args');
+
+$v = [756,3,7,4]->reduce(sub { $a / $b });
+is( $v,	9,	'4-arg divide');
+
+$v = [6]->reduce( sub { $a / $b } );
+is( $v,	6,	'one arg');
+
+my @a = map { rand } 0 .. 20;
+$v = @a->reduce( sub { $a < $b ? $a : $b });
+is( $v,	@a->min,	'min');
+
+ at a = map { pack("C", int(rand(256))) } 0 .. 20;
+$v = @a->reduce( sub { $a . $b } );
+is( $v,	join("", at a),	'concat');
+
+sub add {
+  my($aa, $bb) = @_;
+  return $aa + $bb;
+}
+
+$v = [3, 2, 1]->reduce( sub { my $t="$a $b\n"; 0+add($a, $b) } );
+is( $v,	6,	'call sub');
+
+# Check that eval{} inside the block works correctly
+$v = [0,1,2,3,4]->reduce( sub { eval { die }; $a + $b } );
+is( $v,	10,	'use eval{}');
+
+$v = !defined eval { [0..4]->reduce( sub { die if $b > 2; $a + $b } ) };
+ok($v, 'die');
+
+sub foobar { [0..3]->reduce( sub { (defined(wantarray) && !wantarray) ? $a+1 : 0 } ) }
+($v) = foobar();
+is( $v,	3,	'scalar context');
+
+sub add2 { $a + $b }
+
+$v = [1,2,3]->reduce(\&add2);
+is( $v,	6,	'sub reference');
+
+$v = [3,4,5]->reduce(sub { add2() });
+is( $v, 12,	'call sub');
+
+
+$v = [1,2,3]->reduce( sub { eval "$a + $b" } );
+is( $v, 6, 'eval string');
+
+$a = 8; $b = 9;
+$v = [1,2,3]->reduce(sub { $a * $b });
+is( $a, 8, 'restore $a');
+is( $b, 9, 'restore $b');
+
+
+# Can we leave the sub with 'return'?
+$v = [2,4,6]->reduce( sub {return $a+$b} );
+is($v, 12, 'return');
+
+# ... even in a loop?
+$v = [2,4,6]->reduce(sub {while(1) {return $a+$b} });
+is($v, 12, 'return from loop');
+
+
+# Does it work from another package?
+# FIXME: this doesn't work
+#{ 
+#	package Foo;
+#	$a = $b;
+#	::is([1..4]->reduce( sub {$a*$b} ), 24, 'other package');
+#}
+
+
+# Can we undefine a reduce sub while it's running?
+sub self_immolate {undef &self_immolate; 1}
+eval { $v = [1,2]->reduce(\&self_immolate) };
+like($@, qr/^Can't undef active subroutine/, "undef active sub");
+
+# Redefining an active sub should not fail, but whether the
+# redefinition takes effect immediately depends on whether we're
+# running the Perl or XS implementation.
+
+sub self_updating { local $^W; *self_updating = sub{1} ;1 }
+eval { $v = [1,2]->reduce(\&self_updating) };
+is($@, '', 'redefine self');
+
+{ my $failed = 0;
+
+    sub rec { my $n = shift;
+        if (!defined($n)) {  # No arg means we're being called by reduce()
+            return 1; }
+        if ($n<5) { rec($n+1); }
+        else { $v = [1,2]->reduce(\&rec) }
+        $failed = 1 if !defined $n;
+    }
+
+    rec(1);
+    ok(!$failed, 'from active sub');
+}
+

Propchange: branches/upstream/libautobox-list-util-perl/current/t/reduce.t
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libautobox-list-util-perl/current/t/shuffle.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/t/shuffle.t?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/t/shuffle.t (added)
+++ branches/upstream/libautobox-list-util-perl/current/t/shuffle.t Sat Jan 30 21:09:16 2010
@@ -1,0 +1,41 @@
+use blib;
+use strict;
+use autobox::List::Util;
+use Test::More tests => 13;
+
+my @r;
+
+ at r = []->shuffle;
+ok( !@r,	'no args');
+
+ at r = [9]->shuffle;
+is( 0+ at r,	1,	'1 in 1 out');
+is( $r[0],	9,	'one arg');
+
+my @in = 1..100;
+ at r = @in->shuffle;
+is( 0+ at r,	0+ at in,	'arg count');
+
+isnt( "@r",	"@in",	'result different to args');
+
+my @s = sort { $a <=> $b } @r;
+is( "@in",	"@s",	'values');
+
+my $r;
+
+$r = []->shuffle;
+ok( !@$r,	'no args (ref)');
+
+$r = [9]->shuffle;
+is( 0+@$r,	1,	'1 in 1 out (ref)');
+is( $r->[0],	9,	'one arg (ref)');
+
+$r = @in->shuffle;
+is( 0+@$r,	0+ at in,	'arg count (ref)');
+
+isnt( "@$r",	"@in",	'result different to args (ref)');
+
+ at s = sort { $a <=> $b } @$r;
+is( "@in",	"@s",	'values (ref)');
+
+is @in->shuffle->first(sub { $_ == 5 }), 5, "can chain calls";

Propchange: branches/upstream/libautobox-list-util-perl/current/t/shuffle.t
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libautobox-list-util-perl/current/t/sum.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautobox-list-util-perl/current/t/sum.t?rev=51895&op=file
==============================================================================
--- branches/upstream/libautobox-list-util-perl/current/t/sum.t (added)
+++ branches/upstream/libautobox-list-util-perl/current/t/sum.t Sat Jan 30 21:09:16 2010
@@ -1,0 +1,26 @@
+use blib;
+use Test::More tests => 6;
+
+use strict;
+use autobox::List::Util;
+
+my $v = []->sum;
+is( $v,	undef,	'no args');
+
+$v = [(9)]->sum;
+is( $v, 9, 'one arg');
+
+$v = [(1,2,3,4)]->sum;
+is( $v, 10, '4 args');
+
+$v = [(-1)]->sum;
+is( $v, -1, 'one -1');
+
+my $x = -3;
+
+$v = [($x, 3)]->sum;
+is( $v, 0, 'variable arg');
+
+$v = [(-3.5,3)]->sum;
+is( $v, -0.5, 'real numbers');
+

Propchange: branches/upstream/libautobox-list-util-perl/current/t/sum.t
------------------------------------------------------------------------------
    svn:executable = 




More information about the Pkg-perl-cvs-commits mailing list