Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Moose::Meta::Attribute::Native::Trait::Array.3pm
CommitLineData
3fea05b9 1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Moose::Meta::Attribute::Native::Trait::Array 3"
132.TH Moose::Meta::Attribute::Native::Trait::Array 3 "2009-11-19" "perl v5.8.7" "User Contributed Perl Documentation"
133.SH "NAME"
134Moose::Meta::Attribute::Native::Trait::Array \- Helper trait for ArrayRef attributes
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 2
138\& package Stuff;
139\& use Moose;
140.Ve
141.PP
142.Vb 19
143\& has 'options' => (
144\& traits => ['Array'],
145\& is => 'ro',
146\& isa => 'ArrayRef[Str]',
147\& default => sub { [] },
148\& handles => {
149\& all_options => 'elements',
150\& add_option => 'push',
151\& map_options => 'map',
152\& filter_options => 'grep',
153\& find_option => 'first',
154\& get_option => 'get',
155\& join_options => 'join',
156\& count_options => 'count',
157\& has_options => 'count',
158\& has_no_options => 'is_empty',
159\& sorted_options => 'sort',
160\& },
161\& );
162.Ve
163.PP
164.Vb 2
165\& no Moose;
166\& 1;
167.Ve
168.SH "DESCRIPTION"
169.IX Header "DESCRIPTION"
170This module provides an Array attribute which provides a number of
171array operations.
172.SH "PROVIDED METHODS"
173.IX Header "PROVIDED METHODS"
174These methods are implemented in
175Moose::Meta::Attribute::Native::MethodProvider::Array.
176.IP "\fBcount\fR" 4
177.IX Item "count"
178Returns the number of elements in the array.
179.Sp
180.Vb 2
181\& $stuff = Stuff\->new;
182\& $stuff\->options(["foo", "bar", "baz", "boo"]);
183.Ve
184.Sp
185.Vb 2
186\& my $count = $stuff\->count_options;
187\& print "$count\en"; # prints 4
188.Ve
189.IP "\fBis_empty\fR" 4
190.IX Item "is_empty"
191Returns a boolean value that is true when the array has no elements.
192.Sp
193.Vb 1
194\& $stuff\->has_no_options ? die "No options!\en" : print "Good boy.\en";
195.Ve
196.IP "\fBelements\fR" 4
197.IX Item "elements"
198Returns all of the elements of the array.
199.Sp
200.Vb 2
201\& my @option = $stuff\->all_options;
202\& print "@options\en"; # prints "foo bar baz boo"
203.Ve
204.IP "\fBget($index)\fR" 4
205.IX Item "get($index)"
206Returns an element of the array by its index. You can also use negative index
207numbers, just as with Perl's core array handling.
208.Sp
209.Vb 2
210\& my $option = $stuff\->get_option(1);
211\& print "$option\en"; # prints "bar"
212.Ve
213.IP "\fBpop\fR" 4
214.IX Item "pop"
215.PD 0
216.ie n .IP "\fBpush($value1, \fB$value2\fB, value3 ...)\fR" 4
217.el .IP "\fBpush($value1, \f(CB$value2\fB, value3 ...)\fR" 4
218.IX Item "push($value1, $value2, value3 ...)"
219.IP "\fBshift\fR" 4
220.IX Item "shift"
221.ie n .IP "\fBunshift($value1, \fB$value2\fB, value3 ...)\fR" 4
222.el .IP "\fBunshift($value1, \f(CB$value2\fB, value3 ...)\fR" 4
223.IX Item "unshift($value1, $value2, value3 ...)"
224.ie n .IP "\fBsplice($offset, \fB$length\fB, \f(BI@values\fB)\fR" 4
225.el .IP "\fBsplice($offset, \f(CB$length\fB, \f(CB@values\fB)\fR" 4
226.IX Item "splice($offset, $length, @values)"
227.PD
228These methods are all equivalent to the Perl core functions of the same name.
229.IP "\fBfirst( sub { ... } )\fR" 4
230.IX Item "first( sub { ... } )"
231This method returns the first item matching item in the array, just like
232List::Util's \f(CW\*(C`first\*(C'\fR function. The matching is done with a subroutine
233reference you pass to this method. The reference will be called against each
234element in the array until one matches or all elements have been checked.
235.Sp
236.Vb 2
237\& my $found = $stuff\->find_option( sub { /^b/ } );
238\& print "$found\en"; # prints "bar"
239.Ve
240.IP "\fBgrep( sub { ... } )\fR" 4
241.IX Item "grep( sub { ... } )"
242This method returns every element matching a given criteria, just like Perl's
243core \f(CW\*(C`grep\*(C'\fR function. This method requires a subroutine which implements the
244matching logic.
245.Sp
246.Vb 2
247\& my @found = $stuff\->filter_options( sub { /^b/ } );
248\& print "@found\en"; # prints "bar baz boo"
249.Ve
250.IP "\fBmap( sub { ... } )\fR" 4
251.IX Item "map( sub { ... } )"
252This method transforms every element in the array and returns a new array,
253just like Perl's core \f(CW\*(C`map\*(C'\fR function. This method requires a subroutine which
254implements the transformation.
255.Sp
256.Vb 2
257\& my @mod_options = $stuff\->map_options( sub { $_ . "\-tag" } );
258\& print "@mod_options\en"; # prints "foo\-tag bar\-tag baz\-tag boo\-tag"
259.Ve
260.IP "\fBreduce( sub { ... } )\fR" 4
261.IX Item "reduce( sub { ... } )"
262This method condenses an array into a single value, by passing a function the
263value so far and the next value in the array, just like List::Util's
264\&\f(CW\*(C`reduce\*(C'\fR function. The reducing is done with a subroutine reference you pass
265to this method.
266.Sp
267.Vb 2
268\& my $found = $stuff\->reduce_options( sub { $_[0] . $_[1] } );
269\& print "$found\en"; # prints "foobarbazboo"
270.Ve
271.IP "\fBsort( sub { ... } )\fR" 4
272.IX Item "sort( sub { ... } )"
273Returns a the array in sorted order.
274.Sp
275You can provide an optional subroutine reference to sort with (as you can with
276Perl's core \f(CW\*(C`sort\*(C'\fR function). However, instead of using \f(CW$a\fR and \f(CW$b\fR, you
277will need to use \f(CW$_[0]\fR and \f(CW$_[1]\fR instead.
278.Sp
279.Vb 2
280\& # ascending ASCIIbetical
281\& my @sorted = $stuff\->sort_options();
282.Ve
283.Sp
284.Vb 3
285\& # Descending alphabetical order
286\& my @sorted_options = $stuff\->sort_options( sub { lc $_[1] cmp lc $_[0] } );
287\& print "@sorted_options\en"; # prints "foo boo baz bar"
288.Ve
289.IP "\fBsort_in_place\fR" 4
290.IX Item "sort_in_place"
291Sorts the array \fIin place\fR, modifying the value of the attribute.
292.Sp
293You can provide an optional subroutine reference to sort with (as you can with
294Perl's core \f(CW\*(C`sort\*(C'\fR function). However, instead of using \f(CW$a\fR and \f(CW$b\fR, you
295will need to use \f(CW$_[0]\fR and \f(CW$_[1]\fR instead.
296.IP "\fBshuffle\fR" 4
297.IX Item "shuffle"
298Returns the array, with indices in random order, like \f(CW\*(C`shuffle\*(C'\fR from
299List::Util.
300.IP "\fBuniq\fR" 4
301.IX Item "uniq"
302Returns the array, with all duplicate elements removed, like \f(CW\*(C`uniq\*(C'\fR from
303List::MoreUtils.
304.IP "\fBjoin($str)\fR" 4
305.IX Item "join($str)"
306Joins every element of the array using the separator given as argument, just
307like Perl's core \f(CW\*(C`join\*(C'\fR function.
308.Sp
309.Vb 2
310\& my $joined = $stuff\->join_options( ':' );
311\& print "$joined\en"; # prints "foo:bar:baz:boo"
312.Ve
313.ie n .IP "\fBset($index, \fB$value\fB)\fR" 4
314.el .IP "\fBset($index, \f(CB$value\fB)\fR" 4
315.IX Item "set($index, $value)"
316Given an index and a value, sets the specified array element's value.
317.IP "\fBdelete($index)\fR" 4
318.IX Item "delete($index)"
319Removes the element at the given index from the array.
320.ie n .IP "\fBinsert($index, \fB$value\fB)\fR" 4
321.el .IP "\fBinsert($index, \f(CB$value\fB)\fR" 4
322.IX Item "insert($index, $value)"
323Inserts a new element into the array at the given index.
324.IP "\fBclear\fR" 4
325.IX Item "clear"
326Empties the entire array, like \f(CW\*(C`@array = ()\*(C'\fR.
327.IP "\fBaccessor\fR" 4
328.IX Item "accessor"
329This method provides a get/set accessor for the array, based on array indexes.
330If passed one argument, it returns the value at the specified index. If
331passed two arguments, it sets the value of the specified index.
332.ie n .IP "\fBnatatime($n, \fB$code\fB)\fR" 4
333.el .IP "\fBnatatime($n, \f(CB$code\fB)\fR" 4
334.IX Item "natatime($n, $code)"
335This method returns an iterator which, on each call, returns \f(CW$n\fR more items
336from the array, in order, like \f(CW\*(C`natatime\*(C'\fR from List::MoreUtils. A coderef
337can optionally be provided; it will be called on each group of \f(CW$n\fR elements
338in the array.
339.SH "METHODS"
340.IX Header "METHODS"
341.IP "\fBmeta\fR" 4
342.IX Item "meta"
343.PD 0
344.IP "\fBmethod_provider\fR" 4
345.IX Item "method_provider"
346.IP "\fBhas_method_provider\fR" 4
347.IX Item "has_method_provider"
348.PD
349.SH "BUGS"
350.IX Header "BUGS"
351All complex software has bugs lurking in it, and this module is no
352exception. If you find a bug please either email me, or add the bug
353to cpan\-RT.
354.SH "AUTHOR"
355.IX Header "AUTHOR"
356Stevan Little <stevan@iinteractive.com>
357.SH "COPYRIGHT AND LICENSE"
358.IX Header "COPYRIGHT AND LICENSE"
359Copyright 2007\-2009 by Infinity Interactive, Inc.
360.PP
361<http://www.iinteractive.com>
362.PP
363This library is free software; you can redistribute it and/or modify
364it under the same terms as Perl itself.