sub exists : method {
my ( $attr, $reader, $writer ) = @_;
- return sub { CORE::exists $reader->( $_[0] )->{ $_[1] } ? 1 : 0 };
+ return sub {
+ $attr->associated_class->throw_error('One argument expected') if @_ == 1;
+ CORE::exists $reader->( $_[0] )->{ $_[1] } ? 1 : 0
+ };
}
sub defined : method {
my ( $attr, $reader, $writer ) = @_;
- return sub { CORE::defined $reader->( $_[0] )->{ $_[1] } ? 1 : 0 };
+ return sub {
+ $attr->associated_class->throw_error('One argument expected') if @_ == 1;
+ CORE::defined $reader->( $_[0] )->{ $_[1] } ? 1 : 0
+ };
}
sub get : method {
}
else {
my ( $self, @keys ) = @_;
+ $attr->associated_class->throw_error('One or more arguments expected') unless @keys;
@{ $reader->($self) }{@keys};
}
};
my ( $attr, $reader, $writer ) = @_;
return sub {
my $hashref = $reader->(shift);
+ $attr->associated_class->throw_error('One or more arguments expected') unless @_;
CORE::delete @{$hashref}{@_};
};
}
use strict;
use warnings;
-use Test::More tests => 46;
+use Test::More tests => 50;
use Test::Exception;
use Test::Moose 'does_ok';
is_deeply( $stuff->options, {}, '... no options yet' );
ok( !$stuff->has_option('foo'), '... we have no foo option' );
+dies_ok {
+ $stuff->has_option;
+}
+'... could not determinne exists without a key';
lives_ok {
$stuff->set_option( foo => 'bar' );
'... set the option okay';
ok( $stuff->is_defined('foo'), '... foo is defined' );
+dies_ok {
+ $stuff->is_defined
+}
+'... could not determine defined without a key';
ok( !$stuff->has_no_options, '... we have options' );
is( $stuff->num_options, 1, '... we have 1 option(s)' );
}
'... deleted multiple option okay';
+dies_ok {
+ $stuff->delete_option;
+}
+'... deleted with no option fails ok';
+
is( $stuff->num_options, 1, '... we have 1 option(s)' );
is_deeply( $stuff->options, { foo => 'bar' }, '... got more options now' );
}
'... bad constructor params';
+dies_ok {
+ $stuff->get_option;
+}
+'... could not get an element without a key';
+
## test the meta
my $options = $stuff->meta->get_attribute('options');