Permalink
Browse files

Throw exception on adding a scalar after a hashref.

  • Loading branch information...
1 parent 22097b1 commit afbaaa350229c4bb7007d57f370d5d1099374e96 @pozorvlak pozorvlak committed Mar 16, 2012
Showing with 24 additions and 0 deletions.
  1. +2 −0 lib/Chart/Clicker.pm
  2. +22 −0 t/add-data.t
View
@@ -752,6 +752,8 @@ sub add_data {
$self->_data->{$name}{$key} = $data->{$key};
}
} else {
+ croak "Can't add scalar data after adding hashrefs"
+ if ref($self->_data->{$name}) eq 'HASH';
$self->_data->{$name} = [] unless defined($self->_data->{$name});
push(@{ $self->_data->{$name}}, $data);
}
View
@@ -128,4 +128,26 @@ my @keys = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
);
}
+{
+ my $cc = Chart::Clicker->new;
+
+ my $hashref = {
+ 1 => 42,
+ 2 => 25,
+ 3 => 86,
+ 4 => 23,
+ 5 => 2,
+ };
+ my $val = 19;
+
+ like(
+ exception {
+ $cc->add_data('Sales', $hashref);
+ $cc->add_data('Sales', $val);
+ },
+ qr/Can't add scalar data after adding hashrefs/,
+ "Exception thrown if scalar data added after hashref data",
+ );
+}
+
done_testing;

0 comments on commit afbaaa3

Please sign in to comment.