package Stuff;
use Moose;
use MooseX::AttributeHelpers;
-
+
has 'options' => (
metaclass => 'Collection::Hash',
is => 'ro',
default => sub { {} },
provides => {
'set' => 'set_option',
- 'get' => 'get_option',
+ 'get' => 'get_option',
'empty' => 'has_options',
'count' => 'num_options',
'delete' => 'delete_option',
}
);
-
+
=head1 DESCRIPTION
-This module provides a Hash attribute which provides a number of
+This module provides a Hash attribute which provides a number of
hash-like operations. See L<MooseX::AttributeHelpers::MethodProvider::Hash>
for more details.
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
+All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.
our $AUTHORITY = 'cpan:STEVAN';
sub exists : method {
- my ($attr, $reader, $writer) = @_;
+ my ($attr, $reader, $writer) = @_;
return sub { CORE::exists $reader->($_[0])->{$_[1]} ? 1 : 0 };
-}
+}
sub defined : method {
- my ($attr, $reader, $writer) = @_;
+ my ($attr, $reader, $writer) = @_;
return sub { CORE::defined $reader->($_[0])->{$_[1]} ? 1 : 0 };
-}
+}
sub get : method {
- my ($attr, $reader, $writer) = @_;
+ my ($attr, $reader, $writer) = @_;
return sub {
if ( @_ == 2 ) {
$reader->($_[0])->{$_[1]}
sub keys : method {
my ($attr, $reader, $writer) = @_;
- return sub { CORE::keys %{$reader->($_[0])} };
+ return sub { CORE::keys %{$reader->($_[0])} };
}
-
+
sub values : method {
my ($attr, $reader, $writer) = @_;
- return sub { CORE::values %{$reader->($_[0])} };
-}
+ return sub { CORE::values %{$reader->($_[0])} };
+}
sub kv : method {
my ($attr, $reader, $writer) = @_;
- return sub {
+ return sub {
my $h = $reader->($_[0]);
map {
[ $_, $h->{$_} ]
- } CORE::keys %{$h}
- };
+ } CORE::keys %{$h}
+ };
}
-
+
sub count : method {
my ($attr, $reader, $writer) = @_;
- return sub { scalar CORE::keys %{$reader->($_[0])} };
+ return sub { scalar CORE::keys %{$reader->($_[0])} };
}
sub empty : method {
my ($attr, $reader, $writer) = @_;
- return sub { scalar CORE::keys %{$reader->($_[0])} ? 1 : 0 };
+ return sub { scalar CORE::keys %{$reader->($_[0])} ? 1 : 0 };
}
1;
=head1 NAME
MooseX::AttributeHelpers::MethodProvider::ImmutableHash
-
+
=head1 DESCRIPTION
-This is a role which provides the method generators for
+This is a role which provides the method generators for
L<MooseX::AttributeHelpers::Collection::ImmutableHash>.
=head1 METHODS
=head1 BUGS
-All complex software has bugs lurking in it, and this module is no
+All complex software has bugs lurking in it, and this module is no
exception. If you find a bug please either email me, or add the bug
to cpan-RT.
use Test::Exception;
BEGIN {
- use_ok('MooseX::AttributeHelpers');
+ use_ok('MooseX::AttributeHelpers');
}
{
default => sub { {} },
provides => {
'set' => 'set_option',
- 'get' => 'get_option',
+ 'get' => 'get_option',
'empty' => 'has_options',
'count' => 'num_options',
'clear' => 'clear_options',
'delete' => 'delete_option',
'exists' => 'has_option',
- 'defined'=> 'is_defined'
+ 'defined'=> 'is_defined',
},
curries => {
'set' => {
isa_ok($options, 'MooseX::AttributeHelpers::Collection::Hash');
is_deeply($options->provides, {
- 'set' => 'set_option',
- 'get' => 'get_option',
- 'empty' => 'has_options',
- 'count' => 'num_options',
- 'clear' => 'clear_options',
- 'delete' => 'delete_option',
- 'defined'=> 'is_defined',
- 'exists' => 'has_option',
+ 'set' => 'set_option',
+ 'get' => 'get_option',
+ 'empty' => 'has_options',
+ 'count' => 'num_options',
+ 'clear' => 'clear_options',
+ 'delete' => 'delete_option',
+ 'defined' => 'is_defined',
+ 'exists' => 'has_option',
}, '... got the right provies mapping');
is($options->type_constraint->type_parameter, 'Str', '... got the right container type');