$class = ref $class if ref $class;
my $new = bless { _column_data => {} }, $class;
if ($attrs) {
- $new->throw_exception("attrs must be a hashref") unless ref($attrs) eq 'HASH';
+ $new->throw_exception("attrs must be a hashref")
+ unless ref($attrs) eq 'HASH';
while (my ($k, $v) = each %$attrs) {
- $new->throw_exception("No such column $k on $class") unless $class->has_column($k);
+ $new->throw_exception("No such column $k on $class")
+ unless $class->has_column($k);
$new->store_column($k => $v);
}
}
$obj->delete
-Deletes the object from the database. The object is still perfectly usable
-accessor-wise etc. but ->in_storage will now return 0 and the object must
-be re ->insert'ed before it can be ->update'ed
+Deletes the object from the database. The object is still perfectly usable,
+but ->in_storage() will now return 0 and the object must re inserted using
+->insert() before ->update() can be used on it.
=cut
$pre_source, @{$pre_rec}));
}
$new->related_resultset($pre)->set_cache(\@pre_objects);
- } else {
+ } elsif (defined $pre_val->[0]) {
my $fetched;
unless ($pre_source->primary_columns == grep { exists $pre_val->[0]{$_}
and !defined $pre_val->[0]{$_} } $pre_source->primary_columns)
return $new;
}
-=head2 insert_or_update
+=head2 update_or_insert
- $obj->insert_or_update
+ $obj->update_or_insert
Updates the object if it's already in the db, else inserts it.
=cut
-sub insert_or_update {
+*insert_or_update = \&update_or_insert;
+sub update_or_insert {
my $self = shift;
return ($self->in_storage ? $self->update : $self->insert);
}
=head2 register_column
-=head3 Arguments: ($column, $column_info)
+=over 4
+
+=item Arguments: ($column, $column_info)
+
+=back
Registers a column on the class. If the column_info has an 'accessor' key,
creates an accessor named after the value if defined; if there is no such