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.
This commit is contained in:
Doug Bell 2011-06-13 14:47:49 -05:00
parent 664e7686c6
commit 6dfeb6ef1a

View file

@ -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);
}