.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" 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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 >0, 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 .\" ======================================================================== .\" .IX Title "Moose::Meta::Attribute::Native::Trait::Hash 3pm" .TH Moose::Meta::Attribute::Native::Trait::Hash 3pm 2024-01-21 "perl v5.38.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 Moose::Meta::Attribute::Native::Trait::Hash \- Helper trait for HashRef attributes .SH VERSION .IX Header "VERSION" version 2.2207 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& package Stuff; \& use Moose; \& \& has \*(Aqoptions\*(Aq => ( \& traits => [\*(AqHash\*(Aq], \& is => \*(Aqro\*(Aq, \& isa => \*(AqHashRef[Str]\*(Aq, \& default => sub { {} }, \& handles => { \& set_option => \*(Aqset\*(Aq, \& get_option => \*(Aqget\*(Aq, \& has_no_options => \*(Aqis_empty\*(Aq, \& num_options => \*(Aqcount\*(Aq, \& delete_option => \*(Aqdelete\*(Aq, \& option_pairs => \*(Aqkv\*(Aq, \& }, \& ); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This trait provides native delegation methods for hash references. .SH "PROVIDED METHODS" .IX Header "PROVIDED METHODS" .ie n .SS "get($key, $key2, $key3...)" .el .SS "get($key, \f(CW$key2\fP, \f(CW$key3\fP...)" .IX Subsection "get($key, $key2, $key3...)" Returns values from the hash. .PP In list context it returns a list of values in the hash for the given keys. In scalar context it returns the value for the last key specified. .PP This method requires at least one argument. .ie n .SS "set($key => $value, $key2 => $value2...)" .el .SS "set($key => \f(CW$value\fP, \f(CW$key2\fP => \f(CW$value2\fP...)" .IX Subsection "set($key => $value, $key2 => $value2...)" Sets the elements in the hash to the given values. It returns the new values set for each key, in the same order as the keys passed to the method. .PP This method requires at least two arguments, and expects an even number of arguments. .ie n .SS "delete($key, $key2, $key3...)" .el .SS "delete($key, \f(CW$key2\fP, \f(CW$key3\fP...)" .IX Subsection "delete($key, $key2, $key3...)" Removes the elements with the given keys. .PP In list context it returns a list of values in the hash for the deleted keys. In scalar context it returns the value for the last key specified. .SS keys .IX Subsection "keys" Returns the list of keys in the hash. .PP This method does not accept any arguments. .SS exists($key) .IX Subsection "exists($key)" Returns true if the given key is present in the hash. .PP This method requires a single argument. .SS defined($key) .IX Subsection "defined($key)" Returns true if the value of a given key is defined. .PP This method requires a single argument. .SS values .IX Subsection "values" Returns the list of values in the hash. .PP This method does not accept any arguments. .SS kv .IX Subsection "kv" Returns the key/value pairs in the hash as an array of array references. .PP .Vb 3 \& for my $pair ( $object\->option_pairs ) { \& print "$pair\->[0] = $pair\->[1]\en"; \& } .Ve .PP This method does not accept any arguments. .SS elements .IX Subsection "elements" In list context, this returns the key/value pairs in the hash. .PP In scalar context, this returns the count of keys plus values. In other words, it's the same as keys times two. .PP This method does not accept any arguments. .SS clear .IX Subsection "clear" Resets the hash to an empty value, like \f(CW\*(C`%hash = ()\*(C'\fR. .PP This method does not accept any arguments. .SS count .IX Subsection "count" Returns the number of elements in the hash. Also useful to check for a nonempty hash, because \f(CW\*(C`count\*(C'\fR returns a true (nonzero) value if there is something in the hash: \&\f(CW\*(C`has_options => \*(Aqcount\*(Aq\*(C'\fR. .PP This method does not accept any arguments. .SS is_empty .IX Subsection "is_empty" If the hash is populated, returns false. Otherwise, returns true. .PP This method does not accept any arguments. .SS accessor($key) .IX Subsection "accessor($key)" .ie n .SS "accessor($key, $value)" .el .SS "accessor($key, \f(CW$value\fP)" .IX Subsection "accessor($key, $value)" If passed one argument, returns the value of the specified key. If passed two arguments, sets the value of the specified key. .PP When called as a setter, this method returns the value that was set. .SS shallow_clone .IX Subsection "shallow_clone" This method returns a shallow clone of the hash reference. The return value is a reference to a new hash with the same keys and values. It is \fIshallow\fR because any values that were references in the original will be the \fIsame\fR references in the clone. .ie n .SS "Why no ""each""?" .el .SS "Why no \f(CWeach\fP?" .IX Subsection "Why no each?" We have deliberately omitted a method for \f(CW\*(C`each\*(C'\fR, due to its stateful interaction with the hash iterator. Using \f(CW\*(C`keys\*(C'\fR or \f(CW\*(C`kv\*(C'\fR is much safer. .SS Moose::Meta::Attribute\->meta .IX Subsection "Moose::Meta::Attribute->meta" This will return a Class::MOP::Class instance for this class. .PP It should also be noted that Class::MOP will actually bootstrap this module by installing a number of attribute meta-objects into its metaclass. .SH BUGS .IX Header "BUGS" See "BUGS" in Moose for details on reporting bugs. .SH AUTHORS .IX Header "AUTHORS" .IP \(bu 4 Stevan Little .IP \(bu 4 Dave Rolsky .IP \(bu 4 Jesse Luehrs .IP \(bu 4 Shawn M Moore .IP \(bu 4 יובל קוג'מן (Yuval Kogman) .IP \(bu 4 Karen Etheridge .IP \(bu 4 Florian Ragwitz .IP \(bu 4 Hans Dieter Pearcey .IP \(bu 4 Chris Prather .IP \(bu 4 Matt S Trout .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2006 by Infinity Interactive, Inc. .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.