Skip to content

Commit

Permalink
Slightly golf ::ResultSource::DESTROY and several weaken() calls
Browse files Browse the repository at this point in the history
No functional changes
  • Loading branch information
ribasushi committed Apr 14, 2016
1 parent e7dcdf6 commit d098704
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/DBIx/Class/ResultSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use base qw/DBIx::Class/;
use DBIx::Class::Carp;
use DBIx::Class::ResultSetColumn;
use DBIx::Class::ResultClass::HashRefInflator;
use Scalar::Util qw/blessed weaken reftype/;
use Scalar::Util qw( blessed reftype );
use DBIx::Class::_Util qw(
dbic_internal_try dump_value
fail_on_internal_wantarray fail_on_internal_call UNRESOLVABLE_CONDITION
Expand Down
13 changes: 9 additions & 4 deletions lib/DBIx/Class/ResultSource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2366,10 +2366,15 @@ sub DESTROY {
# if schema is still there reintroduce ourselves with strong refs back to us
if ($_[0]->{schema}) {
my $srcregs = $_[0]->{schema}->source_registrations;
for (keys %$srcregs) {
next unless $srcregs->{$_};
$srcregs->{$_} = $_[0] if $srcregs->{$_} == $_[0];
}

defined $srcregs->{$_}
and
$srcregs->{$_} == $_[0]
and
$srcregs->{$_} = $_[0]
and
last
for keys %$srcregs;
}

1;
Expand Down
8 changes: 3 additions & 5 deletions lib/DBIx/Class/Storage/TxnScopeGuard.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ sub new {
#
# Deliberately *NOT* using is_exception - if someone left a misbehaving
# antipattern value in $@, it's not our business to whine about it
if( defined $@ and length $@ ) {
weaken(
$guard->{existing_exception_ref} = (length ref $@) ? $@ : \$@
);
}
weaken(
$guard->{existing_exception_ref} = (length ref $@) ? $@ : \$@
) if( defined $@ and length $@ );

$storage->txn_begin;

Expand Down
16 changes: 8 additions & 8 deletions lib/DBIx/Class/_Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ sub is_exception ($) {
my $destruction_registry = {};

sub CLONE {
$destruction_registry = { map
{ defined $_ ? ( refaddr($_) => $_ ) : () }
values %$destruction_registry
};
%$destruction_registry = map {
(defined $_)
? ( refaddr($_) => $_ )
: ()
} values %$destruction_registry;

weaken( $destruction_registry->{$_} )
for keys %$destruction_registry;
weaken($_) for values %$destruction_registry;

# Dummy NEXTSTATE ensuring the all temporaries on the stack are garbage
# collected before leaving this scope. Depending on the code above, this
Expand Down Expand Up @@ -553,8 +553,8 @@ sub mkdir_p ($) {
), 'with_stacktrace');
}

my $mark = [];
weaken ( $list_ctx_ok_stack_marker = $mark );
weaken( $list_ctx_ok_stack_marker = my $mark = [] );

$mark;
}
}
Expand Down

0 comments on commit d098704

Please sign in to comment.