From 6dfeb6ef1a6fddf04c32b2c5b6d9fe3bcfae9855 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 13 Jun 2011 14:47:49 -0500 Subject: [PATCH] add _new flag to Crud objects This flag allows you to know when an object has been newly-created, so you can check in the BUILD sub and perform appropriate actions. --- lib/WebGUI/Crud.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/WebGUI/Crud.pm b/lib/WebGUI/Crud.pm index 539136100..823db5fcd 100644 --- a/lib/WebGUI/Crud.pm +++ b/lib/WebGUI/Crud.pm @@ -54,6 +54,12 @@ has _dirty => ( default => 0, ); +# True if the object was created by this instance +has _new => ( + is => 'ro', + default => 0, +); + sub _now { my $self = shift; return WebGUI::DateTime->new($self->session)->toDatabase; @@ -103,6 +109,7 @@ around BUILDARGS => sub { $data->{sequenceNumber} = $sequenceNumber; $data->{$tableKey} = $data->{id} || $session->id->generate; $data->{_dirty} = 1; + $data->{_new} = 1; return $class->$orig($data); }