1MouseX::NativeTraits::HUassehrReCfo(n3t)ributed Perl DocMuomuesnetXa:t:iNoantiveTraits::HashRef(3)
2
3
4

NAME

6       MouseX::NativeTraits::HashRef - Helper trait for HashRef attributes
7

SYNOPSIS

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

DESCRIPTION

28       This module provides a Hash attribute which provides a number of hash-
29       like operations.
30

PROVIDED METHODS

32       These methods are implemented in
33       MouseX::NativeTraits::MethodProvider::HashRef.
34
35       get($key, $key2, $key3...)
36           Returns values from the hash.
37
38           In list context return a list of values in the hash for the given
39           keys.  In scalar context returns the value for the last key
40           specified.
41
42       set($key => $value, $key2 => $value2...)
43           Sets the elements in the hash to the given values.
44
45       delete($key, $key2, $key3...)
46           Removes the elements with the given keys.
47
48       exists($key)
49           Returns true if the given key is present in the hash.
50
51       defined($key)
52           Returns true if the value of a given key is defined.
53
54       keys
55           Returns the list of keys in the hash.
56
57       sorted_keys
58           Returns the list of sorted keys in the hash.
59
60       values
61           Returns the list of values in the hash.
62
63       kv  Returns the key/value pairs in the hash as an array of array
64           references.
65
66             for my $pair ( $object->options->pairs ) {
67                 print "$pair->[0] = $pair->[1]\n";
68             }
69
70       elements
71           Returns the key/value pairs in the hash as a flattened list.
72
73       clear
74           Resets the hash to an empty value, like "%hash = ()".
75
76       count
77           Returns the number of elements in the hash. Also useful for not
78           empty: "has_options => 'count'".
79
80       is_empty
81           If the hash is populated, returns false. Otherwise, returns true.
82
83       accessor
84           If passed one argument, returns the value of the specified key. If
85           passed two arguments, sets the value of the specified key.
86

METHODS

88       meta
89       method_provider_class
90       helper_type
91

SEE ALSO

93       MouseX::NativeTraits
94
95
96
97perl v5.32.1                      2021-01-27  MouseX::NativeTraits::HashRef(3)
Impressum