[cgiapp] Peer review request: weak reference patch for CGI::Application::Plugin::HTDot

Ricardo SIGNES perl.cgiapp at rjbs.manxome.org
Sun Jun 22 07:17:45 EDT 2008


* Mark Stosberg <mark at summersault.com> [2008-06-21T10:53:56]
>  $t->param( c => $self ) if $var =~ /^c\./;
> 
> Is it correct that it should actually be this?
> 
>   use Scalar::Util 'weaken';
>   $t->param( c => weaken($self) ) if $var =~ /^c\./;

No.  Scalar::Util weakens the actual reference.  It does not return a new, weak
reference.

What you're doing is this:

  $t->param(c => $self);
  weaken $self;

The $self in the template stash is a strong reference, and the object itself is
weak.  I'm not sure of the scope of $t, here, but were $t to go out of scope,
taking its params with it, and if there were no other references to the object,
$self would become undef.

What you want is something like:

  $t->param(c => $self);
  weaken $t->param('c');

I suggest testing my assertions with Scalar::Util::isweak.

-- 
rjbs


More information about the cgiapp mailing list