Re: [Newb] Mangling parameters, avoiding recursions?

[email protected] (Joel Bernstein)
Newsgroups perl.moose
Message-ID <CAOfr53Yas3fP_iF=YCad3SiG=studq1siY-x0NpGn5TwxYwSkQ@mail.gmail.com>
On 8 July 2011 21:04, Ekki Plicht (DF4OR) <[email protected]> wrote:

> around 'kdnr' => sub {
>    my ($org, $self, $value) = @_;
>    return $self->kdnr unless $value;
#...
>    return $self->kdnr($value);
> };

> When reading the data set the debugcounter skyrockets within seconds,
> a little bit later I get a "Deep recursion" error and much later the
> process is killed.

Well. Yes. Each 'around' modifier is calling back to the method it's
wrapping, which calls the around modifier, which ...
What you're missing is that the around modifier is passed a reference
to the original method in $_[0]. You're capturing it into $org. All
you need to do is redispatch that method rather than the one you're
wrapping.

That is:
return  $self->$orig unless $value;
....
return $self->$orig($value);

HTH,

/joel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.