Docs tentatively finished.
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / MethodProvider / Collection / Hash.pm
CommitLineData
1b45ecc4 1package MooseX::AttributeHelpers::MethodProvider::Collection::Hash;
2use MooseX::AttributeHelpers::MethodProvider;
3use MooseX::AttributeHelpers::MethodProvider::Util qw(type_check);
4use MooseX::AttributeHelpers::MethodProvider::Collection::ImmutableHash;
5
6our $VERSION = '0.04';
7our $AUTHORITY = 'cpan:STEVAN';
8
9add_method_provider 'Collection::Hash' => (
10 type => 'HashRef',
11 consumes => { 'Collection::ImmutableHash' => ':all' },
12 provides => {
13 set => sub {
14 my ($attr, $reader, $writer) = @_;
15 type_check(
16 $attr,
17 sub { my ($self, %pairs) = @_; return (values %pairs) },
18 sub {
19 my ($self, @pairs) = @_;
20 my $hash = $reader->($self);
21 while (@pairs) {
22 my $key = shift(@pairs);
23 my $value = shift(@pairs);
24 $hash->{$key} = $value;
25 }
26 },
27 );
28 },
29
30 clear => sub {
31 my ($attr, $reader, $writer) = @_;
32 return sub { %{$reader->($_[0])} = () };
33 },
34
35 delete => sub {
36 my ($attr, $reader, $writer) = @_;
37 return sub {
38 my $hashref = $reader->(shift);
39 CORE::delete @{$hashref}{@_};
40 };
41 },
42 },
43);
44
451;
46
47__END__
48
49=pod
50
51=head1 NAME
52
53MooseX::AttributeHelpers::MethodProvider::Hash
54
55=head1 DESCRIPTION
56
1d458eb8 57This module provides the method factories for
58L<MooseX::AttributeHelpers::Collection::Hash>. It also consumes
59L<MooseX::AttributeHelpers::MethodProvider::Collection::ImmutableHash>, and
60thus provides all its methods as well.
1b45ecc4 61
62=head1 PROVIDED METHODS
63
64=over 4
65
66=item B<count>
67
68Returns the number of items in the hash.
69
70=item B<delete(@keys)>
71
72Deletes the specified keys from the hash.
73
74=item B<clear>
75
76Deletes all keys from the hash.
77
78=item B<set>
79
80Sets the specified keys to the specified values. You can specify several of
81these at once, in key => value order.
82
83=back
84
85=head1 BUGS
86
87All complex software has bugs lurking in it, and this module is no
88exception. If you find a bug please either email me, or add the bug
89to cpan-RT.
90
91=head1 AUTHOR
92
93Stevan Little E<lt>stevan@iinteractive.comE<gt>
94
95=head1 COPYRIGHT AND LICENSE
96
97Copyright 2007-2008 by Infinity Interactive, Inc.
98
99L<http://www.iinteractive.com>
100
101This library is free software; you can redistribute it and/or modify
102it under the same terms as Perl itself.
103
104=cut
105