Class::Maker::Types::Array - a sophisticated but slow array class
use Class::Maker::Types::Array; Class::Maker::Types::Array->new( array => [1..100] ); # standard $a->shift; $a->push( qw/ 1 2 3 4 / ); $a->pop; $a->unshift( qw/ 5 6 7 / ); $a->reset; $a->join( ', ' ); # extended $a->count; $a->get; $a->set( 1..100 ); my $clone = $a->clone; $a->copy_from( $b ); $a->pick( 4 ); $a->warp( 2, 3, 1, 0 ); # place elements in this new order of indices $a->union( 100..500 ); $a->intersection( 50..100 ); $a->diff( 50..100 ); $a->rand; $a->sort; $a->totext; $a->sum; $a->unique; $a->permute; print "same" if $a->eq( $other ); # if array of objects $a->get_where( method1 => 'myvalue' ); $a->get_where_sref( $sref, .. ); $a->get_where_regexp( method1 => $regexp1, .. ); $a->get_where_elementselector( Class::Maker::Types::Array::ElementSelector->new( .. ) ); $a->stats; $a->scale_unit; $a->keys( [qw( alpha beta gamma )] ); my ($key, $value) = $a->pair(0); my $href=$a->as_hash; my $c = $a->div( 2 ); my $d = $a->div_by_array( qw(1 2 3) ); my $e = $a->div_by_array( $d ); $a->scale_unit; # scales values to < 1.0
This an object-oriented array class, which uses a method-oriented interface.
Mostly they have the similar syntax as the native perl functions (use "perldoc -f"). If not they are documented below, otherwise a simple example is given.
sub at : method sub _preinit : method sub push : method sub pop : method sub shift : method sub unshift : method sub count : method sub reset : method sub get : method sub members : method sub pick : method sub every : method sub join : method sub sort : method sub warp : method sub _fisher_yates_shuffle sub rand : method sub _algebra sub union : method sub intersection : method sub diff : method sub _calc sub eq : method sub ne : method sub totext : method sub sum : method sub unique : method sub permute : method sub stats : method sub pair : method sub div : method sub div_by_array : method sub div_by_array_obj : method
Returns the element at position $i.
Returns the number of elements (same as @arry in scalar context).
Resets the array to an empty array.
Returns the backend array.
Returns every 'step' (default: 2) element.
Copies the elements in the new sequence as indicated by indices.
Returns the union of two arrays (Array object is returned).
Returns the intersection of the two arrays (Array object is returned).
Returns the diff of the two arrays (Array object is returned).
Call method_name of all set array and filters the ones that match to $value.
method_name
$value
Note: All these get_where... methods return an array of the resulting objects. Empty when nothing found.
get_where...
Filters the array and returns the ones where the sref returns true. The sref get
$_[0] : the Class::Maker::Types::Array object $_[1] : the set object member
so a prototypical sref would look like
my $sref = sub { my $array_obj = shift; my $obj = shift; return 1 if $obj->method_name eq ...; }
Filters the array which return a value that matches the regexps. To call methods with arbitrary args, give an array reference as key where the first element is the method name.
Returns a hashref with following keys and values determined by the array members.
{ count => 5, max => "0.217529585558676", mean => "0.109738802941511", min => undef, sample_range => "0.217529585558676", standard_deviation => "0.103038948420036", sum => "0.548694014707553", variance => "0.0106170248915069", }
[Note] The module Statistics::Tests::Wilcoxon is used to generate these calculations and with any update of it, the available models may increase. Refer to its documentation and locate the stats_all() method for detailed information.
This method can be used to set array key names. Once set can be accessed as an array ref. See pair method below.
$a->keys( qw(alpha beta gamme) ); printf "key=%s, value=%s", $a->keys->[0], $a->at(0);
Returns a ( key => value ) pair. The key may be only valid if keys was set before.
$a->keys( qw(alpha beta gamme) ); my ( $key, $value ) = $a->pair( 0 );
None by default.
Because most methods return Array objects itself, the can be easily further treated with Array methods. Here a rather useless, but informative example.
use Class::Maker::Types::Array;
my $a = Class::Maker::Types::Array->new( array => [1..70] ); my $b = Class::Maker::Types::Array->new( array => [50..100] ); $a->intersection( $b )->pick( 4 )->join( ', ' );
Murat Uenalan, muenalan@cpan.org
perl, perlfunc, perlvar
To install Class::Maker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Maker
CPAN shell
perl -MCPAN -e shell install Class::Maker
For more information on module installation, please visit the detailed CPAN module installation guide.