DBIx-QuickORM
view release on metacpan or search on metacpan
always have access to the raw values, and asking for either the
'stored' or 'dirty' value will give the raw form.
You can also use inflated forms in the %where argument to select/find.
The rows are also smart enough to check if your inflated forms have
been mutated and consider the row dirty (in need of saving or
discarding) after the mutation. This is done by deflating the values to
compare to the stored form when checking for dirtyness.
If your inflated values are readonly, locked restricted hashes, or
objects that implement the 'qorm_immutible' method (and it returns
true). Then the row is smart enough to skip checking them for mutations
as they cannot be mutated.
Oh, also of note, inflated forms do not need to be blessed, nor do they
even need to be references. You could write a conflator that inflates
string to have "inflated: " prefixed to them, and no prefix when they
are raw/deflated. A conflator that encrypts/decrypts passively is also
possible, assuming the encrypted and decrypted forms are easily
distinguishable.
always have access to the raw values, and asking for either the 'stored' or
'dirty' value will give the raw form.
You can also use inflated forms in the %where argument to select/find.
The rows are also smart enough to check if your inflated forms have been
mutated and consider the row dirty (in need of saving or discarding) after the
mutation. This is done by deflating the values to compare to the stored form
when checking for dirtyness.
If your inflated values are readonly, locked restricted hashes, or objects that
implement the 'qorm\_immutible' method (and it returns true). Then the row is
smart enough to skip checking them for mutations as they cannot be mutated.
Oh, also of note, inflated forms do not need to be blessed, nor do they even
need to be references. You could write a conflator that inflates string to have
"inflated: " prefixed to them, and no prefix when they are raw/deflated. A
conflator that encrypts/decrypts passively is also possible, assuming the
encrypted and decrypted forms are easily distinguishable.
### UUID, UUID::Binary, UUID::Stringy
lib/DBIx/QuickORM.pm view on Meta::CPAN
always have access to the raw values, and asking for either the 'stored' or
'dirty' value will give the raw form.
You can also use inflated forms in the %where argument to select/find.
The rows are also smart enough to check if your inflated forms have been
mutated and consider the row dirty (in need of saving or discarding) after the
mutation. This is done by deflating the values to compare to the stored form
when checking for dirtyness.
If your inflated values are readonly, locked restricted hashes, or objects that
implement the 'qorm_immutible' method (and it returns true). Then the row is
smart enough to skip checking them for mutations as they cannot be mutated.
Oh, also of note, inflated forms do not need to be blessed, nor do they even
need to be references. You could write a conflator that inflates string to have
"inflated: " prefixed to them, and no prefix when they are raw/deflated. A
conflator that encrypts/decrypts passively is also possible, assuming the
encrypted and decrypted forms are easily distinguishable.
=head3 UUID, UUID::Binary, UUID::Stringy
lib/DBIx/QuickORM/Row.pm view on Meta::CPAN
package DBIx::QuickORM::Row;
use strict;
use warnings;
our $VERSION = '0.000004';
use Carp qw/croak confess carp longmess/;
use Scalar::Util qw/weaken blessed refaddr readonly reftype/;
use Hash::Util qw/hashref_locked/;
use DBIx::QuickORM::Util qw/parse_hash_arg mask unmask masked equ/;
BEGIN {
require DBIx::QuickORM::Transaction;
*FINALIZED = \&DBIx::QuickORM::Transaction::FINALIZED;
*PARENT = \&DBIx::QuickORM::Transaction::PARENT;
}
use DBIx::QuickORM::Util::HashBase qw{
lib/DBIx/QuickORM/Row.pm view on Meta::CPAN
for my $col (keys %$inf) {
next if $dirty && exists $dirty->{$col}; # We already know the column is dirty
next unless $stored; # Nothing to verify
my $val = $inf->{$col};
next if readonly($val);
my $ref = reftype($val) or next; # If it is not a reference it has probably not mutated
next if blessed($val) && $val->can('qorm_immutible') && $val->qorm_immutible;
if ($ref eq 'HASH') { next if hashref_locked($val) || readonly(%$val) }
elsif ($ref eq 'ARRAY') { next if readonly(@$val) }
elsif ($ref eq 'SCALAR') { next if readonly($$val) }
elsif ($ref eq 'CODE') { next if readonly(&$val) }
# *sigh* fine, check for mutation
my $def = $self->column_def($col) or die "Inflated column '$col' has no definition";
my $conf = $def->conflate or die "Inflated column '$col' has no conflator";
my $raw = $conf->qorm_deflate(column => $def, value => $val, type => $self->column_type($col));
t/unit/QuickORM/Conflator/UUID.t view on Meta::CPAN
use Test2::V0 -target => 'DBIx::QuickORM::Conflator::UUID';
use ok $CLASS;
use lib 't/lib';
use DBIx::QuickORM::Tester qw/dbs_do all_dbs/;
use DBIx::QuickORM;
use Scalar::Util qw/readonly/;
use Hash::Util qw/hashref_locked/;
use DBIx::QuickORM::Conflator::UUID;
my $uuid = DBIx::QuickORM::Conflator::UUID->create;
my $str = $uuid->as_string;
my $bin = $uuid->as_binary;
ok(hashref_locked($uuid), "Created UUID object is locked");
ok($uuid->qorm_immutible, "tell qorm this is an immutible object");
ok($uuid->does('DBIx::QuickORM::Role::Conflator'), "consumes the conflator role");
dbs_do db => sub {
my ($dbname, $dbc, $st) = @_;
my $db;
my $orm = orm sub {
$db = db sub {
t/unit/QuickORM/Conflator/UUID.t view on Meta::CPAN
is(uc($row1->stored->{$_}), $str, "Got stringy data ($_)") for grep { $_ !~ m/bin/i || ($supports_uuid && m/auto/) } @cols;
my $ref = "$row1";
$row1 = undef;
$s->orm->cache->clear;
$row1 = $s->find(1);
ok("$row1" ne $ref, "Got a clean row from the db, new ref");
is($row1->column('bin_type')->as_string, $str, "Round trip bin_type");
ok(hashref_locked($row1->column('char_type')), "Inflated form is locked");
like(dies { $row1->column('char_type')->{as_string} = "foo" }, qr/Modification of a read-only value attempted/, "Cannot mutate inflated UUID");
};
done_testing;
( run in 0.553 second using v1.01-cache-2.11-cpan-49f99fa48dc )