1Moose::Meta::Attribute:U:sNeartiCvoen:t:rTiMrboauoitstee:d:::HPMaeesrthla(:3D:)oActutmreinbtuattei:o:nNative::Trait::Hash(3)
2
3
4

NAME

6       Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef
7       attributes
8

VERSION

10       version 2.2013
11

SYNOPSIS

13         package Stuff;
14         use Moose;
15
16         has 'options' => (
17             traits    => ['Hash'],
18             is        => 'ro',
19             isa       => 'HashRef[Str]',
20             default   => sub { {} },
21             handles   => {
22                 set_option     => 'set',
23                 get_option     => 'get',
24                 has_no_options => 'is_empty',
25                 num_options    => 'count',
26                 delete_option  => 'delete',
27                 option_pairs   => 'kv',
28             },
29         );
30

DESCRIPTION

32       This trait provides native delegation methods for hash references.
33

PROVIDED METHODS

35   get($key, $key2, $key3...)
36       Returns values from the hash.
37
38       In list context it returns a list of values in the hash for the given
39       keys. In scalar context it returns the value for the last key
40       specified.
41
42       This method requires at least one argument.
43
44   set($key => $value, $key2 => $value2...)
45       Sets the elements in the hash to the given values. It returns the new
46       values set for each key, in the same order as the keys passed to the
47       method.
48
49       This method requires at least two arguments, and expects an even number
50       of arguments.
51
52   delete($key, $key2, $key3...)
53       Removes the elements with the given keys.
54
55       In list context it returns a list of values in the hash for the deleted
56       keys. In scalar context it returns the value for the last key
57       specified.
58
59   keys
60       Returns the list of keys in the hash.
61
62       This method does not accept any arguments.
63
64   exists($key)
65       Returns true if the given key is present in the hash.
66
67       This method requires a single argument.
68
69   defined($key)
70       Returns true if the value of a given key is defined.
71
72       This method requires a single argument.
73
74   values
75       Returns the list of values in the hash.
76
77       This method does not accept any arguments.
78
79   kv
80       Returns the key/value pairs in the hash as an array of array
81       references.
82
83         for my $pair ( $object->option_pairs ) {
84             print "$pair->[0] = $pair->[1]\n";
85         }
86
87       This method does not accept any arguments.
88
89   elements
90       In list context, this returns the key/value pairs in the hash.
91
92       In scalar context, this returns the count of keys plus values.  In
93       other words, it's the same as keys times two.
94
95       This method does not accept any arguments.
96
97   clear
98       Resets the hash to an empty value, like "%hash = ()".
99
100       This method does not accept any arguments.
101
102   count
103       Returns the number of elements in the hash. Also useful to check for a
104       nonempty hash, because "count" returns a true (nonzero) value if there
105       is something in the hash: "has_options => 'count'".
106
107       This method does not accept any arguments.
108
109   is_empty
110       If the hash is populated, returns false. Otherwise, returns true.
111
112       This method does not accept any arguments.
113
114   accessor($key)
115   accessor($key, $value)
116       If passed one argument, returns the value of the specified key. If
117       passed two arguments, sets the value of the specified key.
118
119       When called as a setter, this method returns the value that was set.
120
121   shallow_clone
122       This method returns a shallow clone of the hash reference.  The return
123       value is a reference to a new hash with the same keys and values.  It
124       is shallow because any values that were references in the original will
125       be the same references in the clone.
126
127   Why no "each"?
128       We have deliberately omitted a method for "each", due to its stateful
129       interaction with the hash iterator. Using "keys" or "kv" is much safer.
130
131   Moose::Meta::Attribute->meta
132       This will return a Class::MOP::Class instance for this class.
133
134       It should also be noted that Class::MOP will actually bootstrap this
135       module by installing a number of attribute meta-objects into its
136       metaclass.
137

BUGS

139       See "BUGS" in Moose for details on reporting bugs.
140

AUTHORS

142       ·   Stevan Little <stevan.little@iinteractive.com>
143
144       ·   Dave Rolsky <autarch@urth.org>
145
146       ·   Jesse Luehrs <doy@tozt.net>
147
148       ·   Shawn M Moore <code@sartak.org>
149
150       ·   יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
151
152       ·   Karen Etheridge <ether@cpan.org>
153
154       ·   Florian Ragwitz <rafl@debian.org>
155
156       ·   Hans Dieter Pearcey <hdp@weftsoar.net>
157
158       ·   Chris Prather <chris@prather.org>
159
160       ·   Matt S Trout <mst@shadowcat.co.uk>
161
163       This software is copyright (c) 2006 by Infinity Interactive, Inc.
164
165       This is free software; you can redistribute it and/or modify it under
166       the same terms as the Perl 5 programming language system itself.
167
168
169
170perl v5.32.0                    Mo2o0s2e0:-:0M7e-t2a8::Attribute::Native::Trait::Hash(3)
Impressum