Array-Group-4.2/0000755000000000000000000000000012571217112012224 5ustar rootrootArray-Group-4.2/Changes0000755000076500000240000000020112571216270011737 0ustar Revision history for Perl extension Array::Reform. 4.2 - Maintainer release, please see earlier version for previous change log Array-Group-4.2/README0000755000076500000240000000064612571216371011343 0ustar Array::Group ============ This module converts an array into array of arrayrefs of uniform size N. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install COPYRIGHT AND LICENCE Please report any bugs/suggestions to Mike Accardo This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Array-Group-4.2/MANIFEST0000755000000000000000000000034312275375025013371 0ustar rootrootChanges lib/Array/Group.pm Makefile.PL MANIFEST README t/test.t META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Array-Group-4.2/Makefile.PL0000755000076500000240000000352312275375230012433 0ustar use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile1( LICENSE => 'perl', MIN_PERL_VERSION => '5.006', META_MERGE => { resources => { #repository => 'URL to repository here', }, }, TEST_REQUIRES => { 'Test::More'=> 0, }, 'NAME' => 'Array::Group', 'VERSION_FROM' => 'lib/Array/Group.pm', # finds $VERSION ); sub WriteMakefile1 { #Compatibility code for old versions of EU::MM. Written by Alexandr Ciornii, version 0.23. Added by eumm-upgrade. my %params=@_; my $eumm_version=$ExtUtils::MakeMaker::VERSION; $eumm_version=eval $eumm_version; die "EXTRA_META is deprecated" if exists $params{EXTRA_META}; die "License not specified" if not exists $params{LICENSE}; if ($params{AUTHOR} and ref($params{AUTHOR}) eq 'ARRAY' and $eumm_version < 6.5705) { $params{META_ADD}->{author}=$params{AUTHOR}; $params{AUTHOR}=join(', ',@{$params{AUTHOR}}); } if ($params{TEST_REQUIRES} and $eumm_version < 6.64) { $params{BUILD_REQUIRES}={ %{$params{BUILD_REQUIRES} || {}} , %{$params{TEST_REQUIRES}} }; delete $params{TEST_REQUIRES}; } if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) { #EUMM 6.5502 has problems with BUILD_REQUIRES $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} }; delete $params{BUILD_REQUIRES}; } delete $params{CONFIGURE_REQUIRES} if $eumm_version < 6.52; delete $params{MIN_PERL_VERSION} if $eumm_version < 6.48; delete $params{META_MERGE} if $eumm_version < 6.46; delete $params{META_ADD} if $eumm_version < 6.46; delete $params{LICENSE} if $eumm_version < 6.31; WriteMakefile(%params); } Array-Group-4.2/t/0000755000000000000000000000000012571217112012467 5ustar rootrootArray-Group-4.2/t/test.t0000755000076500000240000000243612275423150012065 0ustar # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 9; #BEGIN { plan }; use Array::Group qw( :all ); ok(1); # If we made it this far, we're ok. diag("Array::Group::VERSION $Array::Group::VERSION"); ######################### # Insert your test code below, the Test module is use()ed here so read # its man page ( perldoc Test ) for help writing this test script. our (@orig, $size, @new, $new); @orig = ( 1 .. 16 ); $size = 8; @new = ngroup( $size, \@orig ); ok( scalar @new == 2 ); # check class methods work @new = Array::Group->ngroup( $size, \@orig ); ok( scalar @new == 2 ); # check calling with an array rather than an arrayref works #@new = ngroup( $size, @orig ); #ok( scalar @new == 2 ); $size = 4; $new = ngroup( $size, \@orig ); ok( scalar @$new == 4 ); $size = 5; @new = dissect( $size, \@orig ); ok( scalar @new == 5 ); @orig = ( 1 .. 5 ); $size = 2; @new = ngroup( $size, \@orig ); ok( $new[0][1] == 2 && $new[2][0] == 5 ); @new = dissect( $size, \@orig ); ok( $new[1][0] == 2 && $new[0][1] == 3 ); $size = 3; @new = dissect( $size, \@orig ); is( $new[0][1], 4 ); is( $new[2][0], 3 ); Array-Group-4.2/lib/0000755000000000000000000000000012571217112012772 5ustar rootrootArray-Group-4.2/lib/Array/0000755000000000000000000000000012571217112014050 5ustar rootrootArray-Group-4.2/lib/Array/Group.pm0000755000076500000240000001033512571216722013735 0ustar package Array::Group; use 5.006; use strict; use Carp; require Exporter; our @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use Array::Group ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( ngroup dissect ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw(); our $VERSION = '4.2'; # Preloaded methods go here. sub ngroup { my ($size, $r_list) = &_validate_params; my @list = @{$r_list}; my @lol; push @lol, [splice @list, 0, $size] while @list; return wantarray ? @lol : \@lol; } sub dissect { my ($size, $r_list) = &_validate_params; my @lol; my ($i, $j) = (0, 0); foreach (@$r_list) { $lol[$i]->[$j] = $_; $i = 0, $j++ unless (++$i % $size); } return wantarray ? @lol : \@lol; } # Internal parameter validation function sub _validate_params { # Check we've been called with at least one argument Carp::confess( "Called with no arguments" ) if $#_ == -1; # First param might be a class (if invoked as a class method). Discard it if so. shift if $_[0] =~ /^[a-zA-Z0-9]+ (?: :: [a-zA-Z0-9]+ )$/x; # Check we have at least 2 arguments remaining Carp::confess( "Called with insufficient arguments" ) if( $#_ < 1 ); # Next argument is size. check it is a valid positive integer. my $size = shift; if( $size !~ /^\+?\d+$/ ) { Carp::confess( "Size '$size' is not a valid positive integer" ); } elsif( $size == 0 ) { Carp::confess( "'$size' is an invalid array size" ); } # If only one argument remains, check to see if it is an arrayref, otherwise, reate a reference to it my $r_list; # if( ($#_ == 0) && # (ref($_[0]) eq 'ARRAY') ) { $r_list = $_[0]; # } else { # $r_list = \@_; # } return $size, $r_list; } # Autoload methods go after =cut, and are processed by the autosplit program. 1; __END__ # Below is the stub of documentation for your module. You better edit it! =head1 NAME Array::Group - Convert an array into array of arrayrefs of uniform size N. =head1 SYNOPSIS use Array::Group qw( :all ); @sample = ( 1 .. 10 ); $rowsize = 3; ngroup $rowsize => \@sample ; # yields ( [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10 ] ); dissect $rowsize => \@sample ; # yields ( [ 1, 5, 9 ], [ 2, 6, 10 ], [ 3, 7 ], [ 4, 8 ] ); =head1 DESCRIPTION The C method reformats a list into a list of arrayrefs. It is often used for formatting data into HTML tables, amongst other things. C returns a list of lists where the first element of each sublist will be one of the first elements of the source list, and the last element will be one of the last. This behaviour is much more useful when the input list is sorted. The key difference between the two methods is that C takes elements from the start of the list provided and pushes them onto each of the subarrays sequentially, rather than simply dividing the list into discrete chunks. Both methods can be called as either functions or class methods (to ensure compatibility with previous releases), and the array to be reformed can be passed as a reference. =head1 SEE ALSO =over 4 =item * L =back =head1 AUTHOR Currently maintained by Mike Accardo, Original author Terrence Monroe Brannon. =head2 CONTRIBUTORS I would like to thank Alexandr Ciornii for his help in upgrading this distribution's format. He took me from using a F file to using the F directory and removed some old crufty things that were not needed. He also upgraded the Makefile.PL. =head1 COPYRIGHT Copyright (c) 2015 Mike Accardo Copyright (c) 1999-2014 Terrence Brannon This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Array-Group-4.2/META.json0000644000000000000000000000155712571217112013655 0ustar rootroot{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.150001", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Array-Group", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0", "Test::More" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "perl" : "5.006" } } }, "release_status" : "stable", "resources" : {}, "version" : "4.2" } Array-Group-4.2/META.yml0000644000000000000000000000073412571217112013501 0ustar rootroot--- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: '0' Test::More: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.150001' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Array-Group no_index: directory: - t - inc requires: perl: '5.006' resources: {} version: '4.2'