Skip to content

Commit

Permalink
Item14237: Merge commit '6dccd6952e519b8f1a004099542a9a1d7a89b3d3' in…
Browse files Browse the repository at this point in the history
…to Item14237

* commit '6dccd6952e519b8f1a004099542a9a1d7a89b3d3':
  Item13897: Fixed cloning of non-HASH blessed objects.
  Item13897: Don't attempt to finalize login manager in global destruction.
  • Loading branch information
vrurg committed Dec 16, 2016
2 parents 2e758cc + 6dccd69 commit 3e0a428
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions core/lib/Foswiki/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ features.
require Carp;
require Foswiki::Exception;
use Try::Tiny;
use Scalar::Util qw(blessed refaddr weaken isweak);
use Scalar::Util qw(blessed refaddr reftype weaken isweak);

use Foswiki::Class;

Expand Down Expand Up @@ -241,8 +241,24 @@ sub _cloneData {
# cloning as a hash and blessing the resulting hashref into
# $val's class.
# SMELL Pretty much unreliable for complex classes.
$cloned =
$this->_cloneData( {%$val}, "$attr.blessed($class)" );
my $reftype = reftype($val);
if ( $reftype eq 'HASH' ) {
$cloned =
$this->_cloneData( {%$val}, "$attr.blessed($class)" );
}
elsif ( $reftype eq 'ARRAY' ) {
$cloned =
$this->_cloneData( [@$val], "$attr.blessed($class)" );
}
elsif ( $reftype eq 'SCALAR' ) {
$cloned =
$this->_cloneData( \$$val, "$attr.blessed($class)" );
}
else {
# Cannot clone unknown datatypes, just copy the original
# ref.
$cloned = $val;
}
bless $cloned, ref($val)
if $cloned != $val;
}
Expand Down

0 comments on commit 3e0a428

Please sign in to comment.