Re: 'around' method modifier does not seem to work

[email protected] (Karen Etheridge) Thu, 6 Aug 2015 17:22:48 -0700
Newsgroups perl.moose
Message-ID <CAPJsHfBBD_vZBGa3u6Xi7FPR7Na-xEX6_KXpWRSX+jF1jraOYA@mail.gmail.com>
--001a113cd95ab36650051cada256
Content-Type: text/plain; charset=UTF-8

On Thu, Aug 6, 2015 at 4:04 PM, Marcos Barbeitos <[email protected]>
wrote:
>     around 'sequence' => sub
>     {
>         my $orig = shift;
>         my $self = shift;
>         my $sequence = uc shift;
>
>         # Do lots of things with $sequence and then
>
>         return $self->$orig( $sequence );
>     }
>
>     With no success, as expected. However, if I do:
>
>     around 'sequence' => sub
>     {
>         my $orig = shift;
>         my $self = shift;
>
>         return $self->$orig( @_ );
>     }
>
>     The attribute is set and life goes on. Of course, that does not work
for me because I need to do a bunch of things to the argument passed to
this method.

The only difference I see between these two subs is the argument passed to
$orig.
So, have you tried printing it to check that it is what you expect it to be?

--001a113cd95ab36650051cada256
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thu, Aug 6, 2015 at 4:04 PM, Marcos Barbeitos &lt;<a hr=
ef=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<br=
>&gt;=C2=A0=C2=A0=C2=A0=C2=A0 around &#39;sequence&#39; =3D&gt; sub<br>&gt;=
=C2=A0=C2=A0=C2=A0=C2=A0 {<br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 my $orig =3D shift;<br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 my $self =3D shift;<br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 my $sequence =3D uc shift;<br>&gt; <br>&gt;=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # Do lots of things with $sequence and th=
en<br>&gt; <br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return =
$self-&gt;$orig( $sequence );<br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0 }<br>&gt; <br=
>&gt;=C2=A0=C2=A0=C2=A0=C2=A0 With no success, as expected. However, if I d=
o:<br>&gt; <br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0 around &#39;sequence&#39; =3D&g=
t; sub<br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0 {<br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 my $orig =3D shift;<br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 my $self =3D shift;<br>&gt; <br>&gt;=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return $self-&gt;$orig( @_ );<br>&gt;=
=C2=A0=C2=A0=C2=A0=C2=A0 }<br>&gt; <br>&gt;=C2=A0=C2=A0=C2=A0=C2=A0 The att=
ribute is set and life goes on. Of course, that does not work for me becaus=
e I need to do a bunch of things to the argument passed to this method.<br>=
<br>The only difference I see between these two subs is the argument passed=
 to $orig.<br>So, have you tried printing it to check that it is what you e=
xpect it to be?<br><br></div>

--001a113cd95ab36650051cada256--