Add a basic TypeError class, which returns the same message as before
Sam Vilain [Wed, 17 Mar 2010 06:44:22 +0000 (19:44 +1300)]
Use the old overloaded object string to pass around what we can assume in
most places is a string.

lib/MooseX/Types/Structured/TypeError.pm [new file with mode: 0644]

diff --git a/lib/MooseX/Types/Structured/TypeError.pm b/lib/MooseX/Types/Structured/TypeError.pm
new file mode 100644 (file)
index 0000000..f3b38dc
--- /dev/null
@@ -0,0 +1,27 @@
+
+package MooseX::Types::Structured::TypeError;
+
+use Moose;
+
+has 'constraint' =>
+       is => "ro",
+       ;
+
+has 'index' =>
+       is => "ro",
+       ;
+
+has 'value' =>
+       is => "ro",
+       predicate => "has_value",
+       ;
+
+use overload '""'     => sub { shift->message }, # stringify
+             fallback => 1;
+
+sub message {
+    my $self = shift;
+    $self->constraint->get_message($self->has_value ? $self->value : 'NULL');
+}
+
+1;