};
}
+sub elements : method {
+ my ($attr, $reader, $writer) = @_;
+ return sub {
+ my $h = $reader->($_[0]);
+ map {
+ $_, $h->{$_}
+ } CORE::keys %{$h}
+ };
+}
+
sub count : method {
my ($attr, $reader, $writer) = @_;
return sub { scalar CORE::keys %{$reader->($_[0])} };
=item B<kv>
-Returns the key, value pairs in the hash
+Returns the key, value pairs in the hash as array references
+
+=item B<elements>
+
+Returns the key, value pairs in the hash as a flattened list
=back
use strict;
use warnings;
-use Test::More tests => 48;
+use Test::More tests => 50;
use Test::Exception;
BEGIN {
'exists' => 'has_option',
'defined' => 'is_defined',
'accessor' => 'option_accessor',
+ 'kv' => 'key_value',
+ 'elements' => 'options_elements',
},
curries => {
'accessor' => {
'defined' => 'is_defined',
'exists' => 'has_option',
'accessor' => 'option_accessor',
+ 'kv' => 'key_value',
+ 'elements' => 'options_elements',
}, '... got the right provides mapping');
is($options->type_constraint->type_parameter, 'Str', '... got the right container type');
+
+$stuff->set_option( oink => "blah", xxy => "flop" );
+my @key_value = $stuff->key_value;
+is_deeply(
+ \@key_value,
+ [ [ 'xxy', 'flop' ], [ 'quantity', 4 ], [ 'oink', 'blah' ] ],
+ '... got the right key value pairs'
+);
+
+my %options_elements = $stuff->options_elements;
+is_deeply(
+ \%options_elements,
+ {
+ 'oink' => 'blah',
+ 'quantity' => 4,
+ 'xxy' => 'flop'
+ },
+ '... got the right hash elements'
+);