DBIx-QuickORM

 view release on metacpan or  search on metacpan

lib/DBIx/QuickORM/Row.pm  view on Meta::CPAN

            $st       = $row_data->{+STORED};
        }

        return $self->$meth($st, $field);
    }

    return undef;
}

sub _fields {
    my $self = shift;
    my $meth = shift;

    my %out;
    for my $hr (@_) {
        next unless $hr;

        for my $field (keys %$hr) {
            # An exists check, not //=, so a pending undef (staged NULL) is
            # not masked by a defined stored value.
            next if exists $out{$field};
            $out{$field} = $self->$meth($hr, $field);
        }
    }

    return \%out;
}

sub _inflated_field {
    my $self = shift;
    my ($from, $field) = @_;

    croak "This row does not have a '$field' field" unless $self->has_field($field);

    return undef unless $from;
    return undef unless exists $from->{$field};

    my $val = $from->{$field};

    return $val if ref($val);    # Inflated already

    if (my $type = $self->source->field_type($field)) {
        return $from->{$field} = $type->qorm_inflate($self->conflate_args($field, $val));
    }

    return $from->{$field};
}

sub _raw_field {
    my $self = shift;
    my ($from, $field) = @_;

    croak "This row does not have a '$field' field" unless $self->has_field($field);

    return undef unless $from;
    return undef unless exists $from->{$field};
    my $val = $from->{$field};

    # A staged SQL literal (\'NOW()' or [\'expr ?', @binds]) is not table data;
    # it must pass through untouched. Deflating it would corrupt the literal.
    # This is deliberately narrow: a decoded JSON hashref/arrayref is data and
    # must still be deflated back to its stored form, so only literal shapes
    # pass through here.
    return $val if literal_write_value($val);

    return $val->qorm_deflate($self->conflate_args($field, $val))
        if blessed($val) && $val->can('qorm_deflate');

    if (my $type = $self->source->field_type($field)) {
        return $type->qorm_deflate($self->conflate_args($field, $val));
    }

    return $val;
}

#####################
# }}} Field methods #
#####################

1;

__END__

=head1 SOURCE

The source code repository for DBIx::QuickORM can be found at
L<https://github.com/exodist/DBIx-QuickORM>.

=head1 MAINTAINERS

=over 4

=item Chad Granum E<lt>exodist7@gmail.comE<gt>

=back

=head1 AUTHORS

=over 4

=item Chad Granum E<lt>exodist7@gmail.comE<gt>

=back

=head1 COPYRIGHT

Copyright Chad Granum E<lt>exodist7@gmail.comE<gt>.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

See L<https://dev.perl.org/licenses/>

=cut



( run in 1.078 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )