if ($attrs) {
$new->throw_exception("attrs must be a hashref")
unless ref($attrs) eq 'HASH';
- while (my ($k, $v) = each %$attrs) {
+ foreach my $k (keys %$attrs) {
$new->throw_exception("No such column $k on $class")
unless $class->has_column($k);
- $new->store_column($k => $v);
+ $new->store_column($k => $attrs->{$k});
}
}
return $new;
sub set_columns {
my ($self,$data) = @_;
- while (my ($col,$val) = each %$data) {
- $self->set_column($col,$val);
+ foreach my $col (keys %$data) {
+ $self->set_column($col,$data->{$col});
}
return $self;
}
if $self->result_source->column_info($col)->{is_auto_increment};
}
my $new = bless { _column_data => $col_data }, ref $self;
+ $new->result_source($self->result_source);
$new->set_columns($changes);
$new->insert;
foreach my $rel ($self->result_source->relationships) {
=head2 is_changed
- my @changed_col_names = $obj->is_changed
+ my @changed_col_names = $obj->is_changed();
+ if ($obj->is_changed()) { ... }
=cut
return keys %{shift->{_dirty_columns} || {}};
}
+=head2 is_column_changed
+
+ if ($obj->is_column_changed('col')) { ... }
+
+=cut
+
+sub is_column_changed {
+ my( $self, $col ) = @_;
+ return exists $self->{_dirty_columns}->{$col};
+}
+
=head2 result_source
Accessor to the ResultSource this object was created from