-### get a copy of self without circular refs for use in closures
-sub weak_copy {
- my $self = shift;
- my $self_copy;
- if (eval { require Scalar::Util }
- && defined &Scalar::Util::weaken) {
- $self_copy = $self;
- Scalar::Util::weaken($self_copy);
- } else {
- $self_copy = bless {%$self}, ref($self); # hackish way to avoid circular refs on old perls (pre 5.8)
- }
- return $self_copy;
-}
-