1 package DBM::Deep::Engine::DBI;
6 use warnings FATAL => 'all';
8 use base 'DBM::Deep::Engine';
22 my ($obj, $old_key, $new_key) = @_;
37 my ($obj, $key, $value) = @_;
39 my $r = Scalar::Util::reftype( $value ) || '';
43 last if $r eq 'ARRAY';
45 DBM::Deep->_throw_error(
46 "Storage of references of type '$r' is not supported."
50 # Load the reference entry
51 # Determine if the row was deleted under us
55 if ( $r eq 'ARRAY' || $r eq 'HASH' ) {
57 if ( $r eq 'ARRAY' ) {
58 $tmpvar = tied @$value;
59 } elsif ( $r eq 'HASH' ) {
60 $tmpvar = tied %$value;
64 my $is_dbm_deep = eval { local $SIG{'__DIE__'}; $tmpvar->isa( 'DBM::Deep' ); };
66 unless ( $is_dbm_deep ) {
67 DBM::Deep->_throw_error( "Cannot store something that is tied." );
70 unless ( $tmpvar->_engine->storage == $self->storage ) {
71 DBM::Deep->_throw_error( "Cannot store values across DBM::Deep files. Please use export() instead." );
74 # Load $tmpvar's sector
76 # First, verify if we're storing the same thing to this spot. If we
77 # are, then this should be a no-op. -EJS, 2008-05-19
79 # See whether or not we are storing ourselves to ourself.
80 # Write the sector as data in this reference (keyed by $key)
81 $value_sector->increment_refcount;
86 $type = substr( $r, 0, 1 );
90 DBM::Deep->_throw_error( "Cannot store something that is tied." );
94 # This code is to make sure we write all the values in the $value to the
95 # disk and to make sure all changes to $value after the assignment are
96 # reflected on disk. This may be counter-intuitive at first, but it is
98 # NOTE - simply tying $value won't perform a STORE on each value. Hence,
99 # the copy to a temp value.
100 if ( $r eq 'ARRAY' ) {
102 tie @$value, 'DBM::Deep', {
103 base_offset => $value_sector->offset,
104 staleness => $value_sector->staleness,
105 storage => $self->storage,
109 bless $value, 'DBM::Deep::Array' unless Scalar::Util::blessed( $value );
111 elsif ( $r eq 'HASH' ) {
113 tie %$value, 'DBM::Deep', {
114 base_offset => $value_sector->offset,
115 staleness => $value_sector->staleness,
116 storage => $self->storage,
121 bless $value, 'DBM::Deep::Hash' unless Scalar::Util::blessed( $value );