Permalink
Browse files

Throw exception if you add arrayref after hashref.

  • Loading branch information...
1 parent ab53c07 commit e96bd9294c2ebe530d3840cb5509e73ed3a8e04c @pozorvlak pozorvlak committed Mar 16, 2012
Showing with 29 additions and 0 deletions.
  1. +3 −0 dist.ini
  2. +2 −0 lib/Chart/Clicker.pm
  3. +24 −0 t/add-data.t
View
@@ -7,3 +7,6 @@ copyright_holder= Cold Hard Code, LLC
[Prereqs]
Graphics::Primitive::Driver::Cairo = 0
+
+[Prereqs / TestRequires]
+Test::Fatal = 0
View
@@ -734,6 +734,8 @@ sub add_data {
my ($self, $name, $data) = @_;
if(ref($data) eq 'ARRAY') {
+ croak "Can't add arrayref data after adding hashrefs"
+ if ref($self->_data->{$name}) eq 'HASH';
$self->_data->{$name} = [] unless defined($self->_data->{$name});
push(@{ $self->_data->{$name}}, @{ $data });
} elsif(ref($data) eq 'HASH') {
View
@@ -1,5 +1,6 @@
use strict;
use Test::More;
+use Test::Fatal;
use Chart::Clicker;
my @values = (42, 25, 86, 23, 2, 19, 103, 12, 54, 9);
@@ -104,4 +105,27 @@ my @keys = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
ok(defined($cc->rendered_data), 'rendered');
}
+
+{
+ my $cc = Chart::Clicker->new;
+
+ my $hashref = {
+ 1 => 42,
+ 2 => 25,
+ 3 => 86,
+ 4 => 23,
+ 5 => 2,
+ };
+ my @vals = (19, 103, 12, 54, 9);
+
+ like(
+ exception {
+ $cc->add_data('Sales', $hashref);
+ $cc->add_data('Sales', \@vals);
+ },
+ qr/Can't add arrayref data after adding hashrefs/,
+ "Exception thrown if arrayref data added after hashref data",
+ );
+}
+
done_testing;

0 comments on commit e96bd92

Please sign in to comment.