1 package DBM::Deep::Sector::DBI::Reference;
6 use warnings FATAL => 'all';
8 use base 'DBM::Deep::Sector::DBI';
15 my $e = $self->engine;
17 unless ( $self->offset ) {
18 $self->{offset} = $self->engine->storage->write_to(
20 ref_type => $self->type,
24 my ($rows) = $self->engine->storage->read_from(
25 refs => $self->offset,
29 $self->{type} = $rows->[0]{ref_type};
39 my ($rows) = $self->engine->storage->read_from(
40 datas => { ref_id => $self->offset, key => $args->{key} },
44 return unless $rows->[0]{id};
57 if ( ( $args->{value}->type || 'S' ) eq 'S' ) {
58 $args->{value}{offset} = $self->engine->storage->write_to(
59 datas => $args->{value}{offset},
60 ref_id => $self->offset,
63 value => $args->{value}{data},
64 class => $args->{value}{class},
67 $args->{value}->reload;
70 # Write the Scalar of the Reference
71 $self->engine->storage->write_to(
73 ref_id => $self->offset,
76 value => $args->{value}{offset},
77 class => $args->{value}{class},
86 my $old_value = $self->get_data_for({
92 $data = $old_value->data({ export => 1 });
109 my $obj = DBM::Deep->new({
111 base_offset => $self->offset,
112 # staleness => $self->staleness,
113 storage => $self->engine->storage,
114 engine => $self->engine,
117 if ( $self->engine->storage->{autobless} ) {
118 my $classname = $self->get_classname;
119 if ( defined $classname ) {
120 bless $obj, $classname;
124 # We're not exporting, so just return.
125 unless ( $args->{export} ) {
129 # We shouldn't export if this is still referred to.
130 if ( $self->get_refcount > 1 ) {
140 # We're not ready to be removed yet.
141 if ( $self->decrement_refcount > 0 ) {
145 $self->engine->storage->delete_from(
146 'datas', { ref_id => $self->offset },
149 $self->engine->storage->delete_from(
150 'datas', { value => $self->offset, data_type => 'R' },
153 $self->SUPER::free( @_ );
156 sub increment_refcount {
158 my $refcount = $self->get_refcount;
160 $self->write_refcount( $refcount );
164 sub decrement_refcount {
166 my $refcount = $self->get_refcount;
168 $self->write_refcount( $refcount );
174 my ($rows) = $self->engine->storage->read_from(
175 'refs', $self->offset,
178 return $rows->[0]{refcount};
184 $self->engine->storage->{dbh}->do(
185 "UPDATE refs SET refcount = ? WHERE id = ?", undef,