die() if the user inadvertently tries to set the column list using
Jules Bean [Thu, 1 Dec 2005 20:04:37 +0000 (20:04 +0000)]
columns() as if it was add_columns().

lib/DBIx/Class/Table.pm
t/20setuperrors.t [new file with mode: 0644]

index 34e926e..2fa6f06 100644 (file)
@@ -217,7 +217,10 @@ sub column_info {
                                                                                 
 =cut                                                                            
 
-sub columns { return keys %{shift->_columns}; }
+sub columns {
+  die "columns() is a read-only accessor, did you mean add_columns()?" if (@_ > 1);
+  return keys %{shift->_columns};
+}
 
 1;
 
diff --git a/t/20setuperrors.t b/t/20setuperrors.t
new file mode 100644 (file)
index 0000000..f082e93
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use Test::More tests => 1;
+
+eval {
+  package BuggyTable;
+  use base 'DBIx::Class';
+
+  __PACKAGE__->load_components qw/Core/;
+  __PACKAGE__->columns qw/this doesnt work as expected/;
+};
+
+like($@,qr/^columns\(\) is a read-only/,
+     "columns() error when apparently misused");