1 package MooseX::AttributeHelpers::MethodProvider::ImmutableHash;
5 our $AUTHORITY = 'cpan:STEVAN';
8 my ($attr, $reader, $writer) = @_;
9 return sub { CORE::exists $reader->($_[0])->{$_[1]} };
13 my ($attr, $reader, $writer) = @_;
15 my ($self, @keys) = @_;
16 @{ $reader->($self) }{@keys}
21 my ($attr, $reader, $writer) = @_;
22 return sub { CORE::keys %{$reader->($_[0])} };
26 my ($attr, $reader, $writer) = @_;
27 return sub { CORE::values %{$reader->($_[0])} };
31 my ($attr, $reader, $writer) = @_;
33 my $h = $reader->($_[0]);
41 my ($attr, $reader, $writer) = @_;
42 return sub { scalar CORE::keys %{$reader->($_[0])} };
45 # Deprecated. The author was thinking backwardsly when this was written.
47 my ($attr, $reader, $writer) = @_;
48 return sub { scalar CORE::keys %{$reader->($_[0])} ? 1 : 0 };
51 sub is_empty : method {
52 my ($attr, $reader, $writer) = @_;
53 return sub { CORE::keys %{$reader->($_[0])} == 0 };
56 sub has_items : method {
57 my ($attr, $reader, $writer) = @_;
58 return sub { CORE::keys %{$reader->($_[0])} > 0 };
69 MooseX::AttributeHelpers::MethodProvider::ImmutableHash
73 This is a role which provides the method generators for
74 L<MooseX::AttributeHelpers::Collection::ImmutableHash>.
76 =head1 PROVIDED METHODS
82 Returns the number of items in the hash.
86 DEPRECATED. This was a misleading name for what it does (returns a boolean
87 indicating whether the hash is NOT empty), but we're keeping it for backwards
88 compatibility. Do not use it in new code. Use is_empty or has_items instead,
89 depending on what you meant.
93 Returns a boolean which is true if and only if the hash has no items in it.
97 Returns a boolean which is true if and only if the hash has at least one item.
105 Gets the values specified by @keys from the hash.
117 Returns a list of arrayrefs, each of which is a key => value pair mapping.
123 All complex software has bugs lurking in it, and this module is no
124 exception. If you find a bug please either email me, or add the bug
129 Stevan Little E<lt>stevan@iinteractive.comE<gt>
131 =head1 COPYRIGHT AND LICENSE
133 Copyright 2007-2008 by Infinity Interactive, Inc.
135 L<http://www.iinteractive.com>
137 This library is free software; you can redistribute it and/or modify
138 it under the same terms as Perl itself.