From: rkinyon@cpan.org Date: Tue, 27 May 2008 13:06:47 +0000 (+0000) Subject: Fixed indentation and removed the importation of symbols from Scalar::Util and Data... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=75a6a3798bcd1ee6d1bf906de809666247237618;p=dbsrgits%2FDBM-Deep.git Fixed indentation and removed the importation of symbols from Scalar::Util and Data::Dumper git-svn-id: http://svn.ali.as/cpan/trunk/DBM-Deep@3429 88f4d9cd-8a04-0410-9d60-8f63309c3137 --- diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 45e7eca..72a7016 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -7,8 +7,11 @@ use warnings; our $VERSION = q(1.0010); -use Scalar::Util qw(refaddr reftype); -use Data::Dumper; +# Never import symbols into our namespace. We are a class, not a library. +# -RobK, 2008-05-27 +use Scalar::Util (); +use Data::Dumper (); + # File-wide notes: # * Every method in here assumes that the storage has been appropriately # safeguarded. This can be anything from flock() to some sort of manual @@ -280,52 +283,52 @@ sub write_value { } elsif ( $r eq 'ARRAY' || $r eq 'HASH' ) { - # - # Checking if $value is tied and getting it's underlying variable - # - my $tmpvar; - if ( $r eq 'ARRAY' ) { - $tmpvar = tied @$value; - } elsif ( $r eq 'HASH' ) { - $tmpvar = tied %$value; - } + # + # Checking if $value is tied and getting it's underlying variable + # + my $tmpvar; + if ( $r eq 'ARRAY' ) { + $tmpvar = tied @$value; + } elsif ( $r eq 'HASH' ) { + $tmpvar = tied %$value; + } - # - # Checking if underlying variable is a DBM::Deep instance - # - my $is_ref_dbm_deep = eval { local $SIG{'__DIE__'}; $tmpvar->isa( 'DBM::Deep' ); }; - if ( $is_ref_dbm_deep ) { # - # Checking if storage of destination and source variables is the same + # Checking if underlying variable is a DBM::Deep instance # - if ( $tmpvar->_engine->storage == $self->storage ) { - # - # If yes - loading source sector and getting it's data reference address + my $is_ref_dbm_deep = eval { local $SIG{'__DIE__'}; $tmpvar->isa( 'DBM::Deep' ); }; + if ( $is_ref_dbm_deep ) { # - my $value_sector = $self->_load_sector( $tmpvar->_base_offset ); - my $data_addr = refaddr $value_sector->data; - my $origin_addr; + # Checking if storage of destination and source variables is the same # - # Getting destination reference address for data by key - # - if ( reftype $sector->data eq 'ARRAY' ) { - $origin_addr = refaddr ${$sector->data}[$key]; - } elsif ( reftype $sector->data eq 'HASH' ) { - $origin_addr = refaddr ${$sector->data}{$key}; - } + if ( $tmpvar->_engine->storage == $self->storage ) { + # + # If yes - loading source sector and getting its data reference address + # + my $value_sector = $self->_load_sector( $tmpvar->_base_offset ); + my $data_addr = Scalar::Util::refaddr( $value_sector->data ); + my $origin_addr; + # + # Getting destination reference address for data by key + # + if ( Scalar::Util::reftype( $sector->data ) eq 'ARRAY' ) { + $origin_addr = Scalar::Util::refaddr( ${$sector->data}[$key] ); + } elsif ( Scalar::Util::reftype( $sector->data ) eq 'HASH' ) { + $origin_addr = Scalar::Util::refaddr( ${$sector->data}{$key} ); + } - # - # Do nothing if reference addresses of source and destination data are same - # - if (defined $data_addr && defined $origin_addr) { - return 1 if ($data_addr == $origin_addr); + # + # Do nothing if reference addresses of source and destination data are same + # + if (defined $data_addr && defined $origin_addr) { + return 1 if ($data_addr == $origin_addr); + } + } else { + DBM::Deep->_throw_error( "Cannot store values across DBM::Deep files. Please use export() instead." ); } - } else { - DBM::Deep->_throw_error( "Cannot store values across DBM::Deep files. Please use export() instead." ); } - } - my $is_dbm_deep = eval { local $SIG{'__DIE__'}; $value->isa( 'DBM::Deep' ); }; + my $is_dbm_deep = eval { local $SIG{'__DIE__'}; $value->isa( 'DBM::Deep' ); }; if ( $is_dbm_deep ) { if ( $value->_engine->storage == $self->storage ) { my $value_sector = $self->_load_sector( $value->_base_offset ); @@ -363,6 +366,7 @@ sub write_value { data => $value, type => $type, }); + $sector->write_data({ key => $key, key_md5 => $self->_apply_digest( $key ),