.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 "Data::Perl::Role::Collection::Hash 3pm" .TH Data::Perl::Role::Collection::Hash 3pm "2022-10-16" "perl v5.34.0" "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" Data::Perl::Role::Collection::Hash \- Wrapping class for Perl's built in hash structure. .SH "VERSION" .IX Header "VERSION" version 0.002011 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Data::Perl qw/hash/; \& \& my $hash = hash(a => 1, b => 2); \& \& $hash\->values; # (1, 2) \& \& $hash\->set(\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq); # (a => 1, b => 2, foo => \*(Aqbar\*(Aq) .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class provides a wrapper and methods for interacting with a hash. All methods that return a list do so via a Data::Perl::Collection::Array object. .SH "PROVIDED METHODS" .IX Header "PROVIDED METHODS" .IP "\fBnew($key, \f(CB$value\fB, ...)\fR" 4 .IX Item "new($key, $value, ...)" Given an optional list of keys/values, constructs a new Data::Perl::Collection::Hash object initialized with keys/values and returns it. .IP "\fBget($key, \f(CB$key2\fB, \f(CB$key3\fB...)\fR" 4 .IX Item "get($key, $key2, $key3...)" Returns a list of values in the hash for the given keys. .Sp This method requires at least one argument. .IP "\fBset($key => \f(CB$value\fB, \f(CB$key2\fB => \f(CB$value2\fB...)\fR" 4 .IX Item "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. .Sp This method requires at least two arguments, and expects an even number of arguments. .IP "\fBdelete($key, \f(CB$key2\fB, \f(CB$key3\fB...)\fR" 4 .IX Item "delete($key, $key2, $key3...)" Removes the elements with the given keys. .Sp Returns a list of values in the hash for the deleted keys. .IP "\fBkeys\fR" 4 .IX Item "keys" Returns the list of keys in the hash. .Sp This method does not accept any arguments. .IP "\fBexists($key)\fR" 4 .IX Item "exists($key)" Returns true if the given key is present in the hash. .Sp This method requires a single argument. .IP "\fBdefined($key)\fR" 4 .IX Item "defined($key)" Returns true if the value of a given key is defined. .Sp This method requires a single argument. .IP "\fBvalues\fR" 4 .IX Item "values" Returns the list of values in the hash. .Sp This method does not accept any arguments. .IP "\fBkv\fR" 4 .IX Item "kv" Returns the key/value pairs in the hash as an array of array references. .Sp .Vb 3 \& for my $pair ( $object\->option_pairs ) { \& print "$pair\->[0] = $pair\->[1]\en"; \& } .Ve .Sp This method does not accept any arguments. .IP "\fBelements/all\fR" 4 .IX Item "elements/all" Returns the key/value pairs in the hash as a flattened list.. .Sp This method does not accept any arguments. .IP "\fBclear\fR" 4 .IX Item "clear" Resets the hash to an empty value, like \f(CW\*(C`%hash = ()\*(C'\fR. .Sp This method does not accept any arguments. .IP "\fBcount\fR" 4 .IX Item "count" Returns the number of elements in the hash. Also useful for not empty: \&\f(CW\*(C`has_options => \*(Aqcount\*(Aq\*(C'\fR. .Sp This method does not accept any arguments. .IP "\fBis_empty\fR" 4 .IX Item "is_empty" If the hash is populated, returns false. Otherwise, returns true. .Sp This method does not accept any arguments. .IP "\fBaccessor($key)\fR" 4 .IX Item "accessor($key)" .PD 0 .IP "\fBaccessor($key, \f(CB$value\fB)\fR" 4 .IX Item "accessor($key, $value)" .PD If passed one argument, returns the value of the specified key. If passed two arguments, sets the value of the specified key. .Sp When called as a setter, this method returns the value that was set. .IP "\fBshallow_clone\fR" 4 .IX Item "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. .IP "\fB_array_class\fR" 4 .IX Item "_array_class" The name of the class which returned lists are instances of; i.e. \&\f(CW\*(C`Data::Perl::Collection::Array\*(C'\fR. .Sp Subclasses of this class can override this method. .PP Note that \f(CW\*(C`each\*(C'\fR is deliberately omitted, due to its stateful interaction with the hash iterator. \f(CW\*(C`keys\*(C'\fR or \f(CW\*(C`kv\*(C'\fR are much safer. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 Data::Perl .IP "\(bu" 4 MooX::HandlesVia .SH "AUTHOR" .IX Header "AUTHOR" Matthew Phillips .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2020 by Matthew Phillips . .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.