.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Data::Perl::Role::Collection::Array 3pm" .TH Data::Perl::Role::Collection::Array 3pm "2014-06-27" "perl v5.18.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Data::Perl::Role::Collection::Array \- Wrapping class for Perl's built in array structure. .SH "VERSION" .IX Header "VERSION" version 0.002009 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Data::Perl qw/array/; \& \& my $array = array(1, 2, 3); \& \& $array\->push(5); \& \& $array\->grep(sub { $_ > 2 })\->map(sub { $_ ** 2 })\->elements; # (3, 5); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class provides a wrapper and methods for interacting with an array. All methods that return a list do so via a Data::Perl::Collection::Array object. .SH "PROVIDED METHODS" .IX Header "PROVIDED METHODS" .ie n .IP "\fBnew($value, \fB$value\fB, ....)\fR" 4 .el .IP "\fBnew($value, \f(CB$value\fB, ....)\fR" 4 .IX Item "new($value, $value, ....)" Constructs a new Data::Perl::Collection::Array object initialized with passed in values, and returns it. .IP "\fBcount\fR" 4 .IX Item "count" Returns the number of elements in the array. .Sp .Vb 1 \& $stuff = Data::Perl::Collection::Array\->new(qw/foo bar baz boo/); \& \& print $stuff\->count; # prints 4 .Ve .Sp This method does not accept any arguments. .IP "\fBis_empty\fR" 4 .IX Item "is_empty" Returns a boolean value that is true when the array has no elements. .Sp .Vb 1 \& $stuff\->is_empty ? die "No options!\en" : print "Good boy.\en"; .Ve .Sp This method does not accept any arguments. .IP "\fBelements/all\fR" 4 .IX Item "elements/all" Returns all of the elements of the array as an array (not an array reference). .Sp .Vb 2 \& my @options = $stuff\->elements; \& print "@options\en"; # prints "foo bar baz boo" .Ve .Sp This method does not accept any arguments. .IP "\fBget($index)\fR" 4 .IX Item "get($index)" Returns an element of the array by its index. You can also use negative index numbers, just as with Perl's core array handling. .Sp .Vb 2 \& my $option = $stuff\->get(1); \& print "$option\en"; # prints "bar" .Ve .Sp If the specified element does not exist, this will return \f(CW\*(C`undef\*(C'\fR. .Sp This method accepts just one argument. .IP "\fBpop\fR" 4 .IX Item "pop" Just like Perl's builtin \f(CW\*(C`pop\*(C'\fR. .Sp This method does not accept any arguments. .ie n .IP "\fBpush($value1, \fB$value2\fB, value3 ...)\fR" 4 .el .IP "\fBpush($value1, \f(CB$value2\fB, value3 ...)\fR" 4 .IX Item "push($value1, $value2, value3 ...)" Just like Perl's builtin \f(CW\*(C`push\*(C'\fR. Returns the number of elements in the new array. .Sp This method accepts any number of arguments. .IP "\fBshift\fR" 4 .IX Item "shift" Just like Perl's builtin \f(CW\*(C`shift\*(C'\fR. .Sp This method does not accept any arguments. .ie n .IP "\fBunshift($value1, \fB$value2\fB, value3 ...)\fR" 4 .el .IP "\fBunshift($value1, \f(CB$value2\fB, value3 ...)\fR" 4 .IX Item "unshift($value1, $value2, value3 ...)" Just like Perl's builtin \f(CW\*(C`unshift\*(C'\fR. Returns the number of elements in the new array. .Sp This method accepts any number of arguments. .ie n .IP "\fBsplice($offset, \fB$length\fB, \f(BI@values\fB)\fR" 4 .el .IP "\fBsplice($offset, \f(CB$length\fB, \f(CB@values\fB)\fR" 4 .IX Item "splice($offset, $length, @values)" Just like Perl's builtin \f(CW\*(C`splice\*(C'\fR. In scalar context, this returns the last element removed, or \f(CW\*(C`undef\*(C'\fR if no elements were removed. In list context, this returns all the elements removed from the array, wrapped in a Collection::Array object. .Sp This method requires at least one argument. .IP "\fBfirst( sub { ... } )\fR" 4 .IX Item "first( sub { ... } )" This method returns the first matching item in the array, just like List::Util's \f(CW\*(C`first\*(C'\fR function. The matching is done with a subroutine reference you pass to this method. The subroutine will be called against each element in the array until one matches or all elements have been checked. .Sp .Vb 2 \& my $found = $stuff\->find_option( sub {/^b/} ); \& print "$found\en"; # prints "bar" .Ve .Sp This method requires a single argument. .IP "\fBfirst_index( sub { ... } )\fR" 4 .IX Item "first_index( sub { ... } )" This method returns the index of the first matching item in the array, just like List::MoreUtils's \f(CW\*(C`first_index\*(C'\fR function. The matching is done with a subroutine reference you pass to this method. The subroutine will be called against each element in the array until one matches or all elements have been checked. .Sp This method requires a single argument. .IP "\fBgrep( sub { ... } )\fR" 4 .IX Item "grep( sub { ... } )" This method returns every element matching a given criteria, just like Perl's core \f(CW\*(C`grep\*(C'\fR function. This method requires a subroutine which implements the matching logic. The returned list is provided as a Collection::Array object. .Sp .Vb 2 \& my @found = $stuff\->grep( sub {/^b/} ); \& print "@found\en"; # prints "bar baz boo" .Ve .Sp This method requires a single argument. .IP "\fBmap( sub { ... } )\fR" 4 .IX Item "map( sub { ... } )" This method transforms every element in the array and returns a new array, just like Perl's core \f(CW\*(C`map\*(C'\fR function. This method requires a subroutine which implements the transformation. The returned list is provided as a Collection::Array object. .Sp .Vb 2 \& my @mod_options = $stuff\->map( sub { $_ . "\-tag" } ); \& print "@mod_options\en"; # prints "foo\-tag bar\-tag baz\-tag boo\-tag" .Ve .Sp This method requires a single argument. .IP "\fBreduce( sub { ... } )\fR" 4 .IX Item "reduce( sub { ... } )" This method turns an array into a single value, by passing a function the value so far and the next value in the array, just like List::Util's \&\f(CW\*(C`reduce\*(C'\fR function. The reducing is done with a subroutine reference you pass to this method. .Sp .Vb 2 \& my $found = $stuff\->reduce( sub { $_[0] . $_[1] } ); \& print "$found\en"; # prints "foobarbazboo" .Ve .Sp This method requires a single argument. .IP "\fBsort\fR" 4 .IX Item "sort" .PD 0 .IP "\fBsort( sub { ... } )\fR" 4 .IX Item "sort( sub { ... } )" .PD Returns the elements of the array in sorted order. .Sp You can provide an optional subroutine reference to sort with (as you can with Perl's core \f(CW\*(C`sort\*(C'\fR function). However, instead of using \f(CW$a\fR and \f(CW$b\fR in this subroutine, you will need to use \f(CW$_[0]\fR and \f(CW$_[1]\fR. The returned list is provided as a Collection::Array object. .Sp .Vb 2 \& # ascending ASCIIbetical \& my @sorted = $stuff\->sort(); \& \& # Descending alphabetical order \& my @sorted_options = $stuff\->sort( sub { lc $_[1] cmp lc $_[0] } ); \& print "@sorted_options\en"; # prints "foo boo baz bar" .Ve .Sp This method accepts a single argument. .IP "\fBsort_in_place\fR" 4 .IX Item "sort_in_place" .PD 0 .IP "\fBsort_in_place( sub { ... } )\fR" 4 .IX Item "sort_in_place( sub { ... } )" .PD Sorts the array \fIin place\fR, modifying the value of the attribute. .Sp You can provide an optional subroutine reference to sort with (as you can with Perl's core \f(CW\*(C`sort\*(C'\fR function). However, instead of using \f(CW$a\fR and \f(CW$b\fR, you will need to use \f(CW$_[0]\fR and \f(CW$_[1]\fR instead. The returned list is provided as a Collection::Array object. .Sp This method accepts a single argument. .IP "\fBreverse\fR" 4 .IX Item "reverse" Returns the elements of the array in reversed order. The returned list is provided as a Collection::Array object. .Sp This method does not accept any arguments. .IP "\fBshuffle\fR" 4 .IX Item "shuffle" Returns the elements of the array in random order, like \f(CW\*(C`shuffle\*(C'\fR from List::Util. The returned list is provided as a Collection::Array object. .Sp This method does not accept any arguments. .IP "\fBuniq\fR" 4 .IX Item "uniq" Returns the array with all duplicate elements removed, like \f(CW\*(C`uniq\*(C'\fR from List::MoreUtils. The returned list is provided as a Collection::Array object. .Sp This method does not accept any arguments. .IP "\fBjoin($str)\fR" 4 .IX Item "join($str)" Joins every element of the array using the separator given as argument, just like Perl's core \f(CW\*(C`join\*(C'\fR function. .Sp .Vb 2 \& my $joined = $stuff\->join(\*(Aq:\*(Aq); \& print "$joined\en"; # prints "foo:bar:baz:boo" .Ve .Sp This method requires a single argument. .ie n .IP "\fBprint($handle, \fB$str\fB)\fR" 4 .el .IP "\fBprint($handle, \f(CB$str\fB)\fR" 4 .IX Item "print($handle, $str)" Prints the output of join($str) to \f(CW$handle\fR. \f(CW$handle\fR defaults to \s-1STDOUT,\s0 and join \f(CW$str\fR defaults to \fIjoin()\fR's default of ','. .Sp .Vb 1 \& $joined = $stuff\->print(*STDERR, \*(Aq;\*(Aq); # prints foo;bar;baz to STDERR .Ve .ie n .IP "\fBset($index, \fB$value\fB)\fR" 4 .el .IP "\fBset($index, \f(CB$value\fB)\fR" 4 .IX Item "set($index, $value)" Given an index and a value, sets the specified array element's value. .Sp This method returns the value at \f(CW$index\fR after the set. .Sp This method requires two arguments. .IP "\fBdelete($index)\fR" 4 .IX Item "delete($index)" Removes the element at the given index from the array. .Sp This method returns the deleted value, either as an array or scalar as dependent on splice context semantics. Note that if no value exists, it will .Sp return \f(CW\*(C`undef\*(C'\fR. .Sp This method requires one argument. .ie n .IP "\fBinsert($index, \fB$value\fB)\fR" 4 .el .IP "\fBinsert($index, \f(CB$value\fB)\fR" 4 .IX Item "insert($index, $value)" Inserts a new element into the array at the given index. .Sp This method returns the new value at \f(CW$index\fR, either as an array or scalar as dependent on splice context semantics. .Sp This method requires two arguments. .IP "\fBclear\fR" 4 .IX Item "clear" Empties the entire array, like \f(CW\*(C`@array = ()\*(C'\fR. .Sp This method does not define a return value. .Sp This method does not accept any arguments. .IP "\fBaccessor($index)\fR" 4 .IX Item "accessor($index)" .PD 0 .ie n .IP "\fBaccessor($index, \fB$value\fB)\fR" 4 .el .IP "\fBaccessor($index, \f(CB$value\fB)\fR" 4 .IX Item "accessor($index, $value)" .PD This method provides a get/set accessor for the array, based on array indexes. If passed one argument, it returns the value at the specified index. If passed two arguments, it sets the value of the specified index. .Sp When called as a setter, this method returns the new value at \f(CW$index\fR. .Sp This method accepts one or two arguments. .IP "\fBnatatime($n)\fR" 4 .IX Item "natatime($n)" .PD 0 .ie n .IP "\fBnatatime($n, \fB$code\fB)\fR" 4 .el .IP "\fBnatatime($n, \f(CB$code\fB)\fR" 4 .IX Item "natatime($n, $code)" .PD This method returns an iterator which, on each call, returns \f(CW$n\fR more items from the array, in order, like \f(CW\*(C`natatime\*(C'\fR from List::MoreUtils. A coderef can optionally be provided; it will be called on each group of \f(CW$n\fR elements in the array. .Sp This method accepts one or two arguments. .IP "\fBshallow_clone\fR" 4 .IX Item "shallow_clone" This method returns a shallow clone of the array reference. The return value is a reference to a new array with the same elements. It is \fIshallow\fR because any elements that were references in the original will be the \fIsame\fR references in the clone. .IP "\fBflatten\fR" 4 .IX Item "flatten" This method returns a list of elements in the array. This method is an alias to the \fIelements\fR method. .IP "\fBflatten_deep($level)\fR" 4 .IX Item "flatten_deep($level)" This method returns a flattened list of elements in the array. Will flatten arrays contained within the root array recursively \- depth is controlled by the optional \f(CW$level\fR parameter. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 Data::Perl .IP "\(bu" 4 MooX::HandlesVia .SH "AUTHOR" .IX Header "AUTHOR" Matthew Phillips .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2014 by Matthew Phillips . .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.