1Moose::Meta::Attribute:U:sNeartiCvoen:t:rTiMrboauoitstee:d:::HPMaeesrthla(:3D:)oActutmreinbtuattei:o:nNative::Trait::Hash(3)
2
3
4
6 Moose::Meta::Attribute::Native::Trait::Hash - Helper trait for HashRef
7 attributes
8
10 package Stuff;
11 use Moose;
12
13 has 'options' => (
14 traits => ['Hash'],
15 is => 'ro',
16 isa => 'HashRef[Str]',
17 default => sub { {} },
18 handles => {
19 set_option => 'set',
20 get_option => 'get',
21 has_no_options => 'is_empty',
22 num_options => 'count',
23 delete_option => 'delete',
24 pairs => 'kv',
25 },
26 );
27
29 This module provides a Hash attribute which provides a number of hash-
30 like operations.
31
33 These methods are implemented in
34 Moose::Meta::Attribute::Native::MethodProvider::Hash.
35
36 get($key, $key2, $key3...)
37 Returns values from the hash.
38
39 In list context return a list of values in the hash for the given
40 keys. In scalar context returns the value for the last key
41 specified.
42
43 set($key => $value, $key2 => $value2...)
44 Sets the elements in the hash to the given values.
45
46 delete($key, $key2, $key3...)
47 Removes the elements with the given keys.
48
49 keys
50 Returns the list of keys in the hash.
51
52 exists($key)
53 Returns true if the given key is present in the hash.
54
55 defined($key)
56 Returns true if the value of a given key is defined.
57
58 values
59 Returns the list of values in the hash.
60
61 kv Returns the key/value pairs in the hash as an array of array
62 references.
63
64 for my $pair ( $object->options->pairs ) {
65 print "$pair->[0] = $pair->[1]\n";
66 }
67
68 elements
69 Returns the key/value pairs in the hash as a flattened list..
70
71 clear
72 Resets the hash to an empty value, like "%hash = ()".
73
74 count
75 Returns the number of elements in the hash. Also useful for not
76 empty: "has_options => 'count'".
77
78 is_empty
79 If the hash is populated, returns false. Otherwise, returns true.
80
81 accessor
82 If passed one argument, returns the value of the specified key. If
83 passed two arguments, sets the value of the specified key.
84
86 meta
87 method_provider
88 has_method_provider
89
91 See "BUGS" in Moose for details on reporting bugs.
92
94 Stevan Little <stevan@iinteractive.com>
95
97 Copyright 2007-2009 by Infinity Interactive, Inc.
98
99 <http://www.iinteractive.com>
100
101 This library is free software; you can redistribute it and/or modify it
102 under the same terms as Perl itself.
103
104
105
106perl v5.12.2 Mo2o0s1e0:-:0M8e-t2a8::Attribute::Native::Trait::Hash(3)