Re: 'around' method modifier does not seem to work
[email protected] (Marcos Barbeitos) Sat, 8 Aug 2015 17:18:46 -0300
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <CA+gEHsU0j9JkupjdaEjz93byDVGA+9PMNQBEZQrGfhQSmTjrRQ@mail.gmail.com> |
--001a113ee386b49d75051cd275c3
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Howdy, everybody, thank you so very much for your help.
Ben was indeed correct; if I do:
around 'sequence' =3D> sub
{
my $orig =3D shift;
my $self =3D shift;
if ( @_ =3D=3D 1 )
{
my $sequence =3D _get_parsed_sequence( shift );
return $self->$orig( $sequence );
}
else
{
return $self->{sequence};
}
};
I get it to work. Not a very elegant solution, for I must access the
attribute directly instead of using an accessor.
One issue still remains though, if I pass the argument to the constructor:
my $collection =3D DCSE::Collection->new
(
id =3D> 'test'
, sequence =3D> $sequence
, helix =3D> $dcse->helix
);
I believe that 'around' is not called, for I get the unparsed argument when
I fetch the attribute.
I will look into 'writers' and 'readers', maybe they will work better in
this case?
Cheers!
On Fri, Aug 7, 2015 at 11:31 PM, Kent Fredric <[email protected]> wrote=
:
> On 8 August 2015 at 09:09, Chris Prather <[email protected]> wrote:
> > If you check the part he quoted in the original email, that is in there=
.
> > Obviously three of us missed it so maybe it could be highlighted better=
.
>
>
> I think there's confusion stemming from there being *two* methods
> being wrapped, one has the guard, and the other has its internals
> elided, and we assume there is a guard.
>
> Method one is called "size":
>
> around 'size' =3D> sub {
> my $orig =3D shift;
> my $self =3D shift;
>
> return $self->$orig() ##### Guard
> unless @_;
>
> my $size =3D shift;
> $size =3D $size / 2
> if $self->likes_small_things();
>
> return $self->$orig($size);
> };
>
>
> Method two is called "sequence":
>
> around 'sequence' =3D> sub
> {
> my $orig =3D shift;
> my $self =3D shift;
> my $sequence =3D uc shift;
>
> # Do lots of things with $sequence and then
> #### NO CLEAR GUARD
>
> return $self->$orig( $sequence );
> }
>
>
>
> And as he describes, the issue he experiences is predominantly with
> the second of these, which makes sense, given there is no code that
> *we* can see with the guard mechanism.
>
>
>
> --
> Kent
>
> KENTNL - https://metacpan.org/author/KENTNL
>
--=20
Marcos S. Barbeitos
Departamento de Zoologia - Sala 360
Setor de Ci=C3=AAncias Biol=C3=B3gicas
Universidade Federal do Paran=C3=A1
Caixa Postal 19020
Curitiba, PR 81531-990
Brazil
Phone: (55 41) 3361-1634
--001a113ee386b49d75051cd275c3
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Howdy, everybody, thank you so very much for your help.<di=
v><br></div><div>Ben was indeed correct; if I do:</div><div><br></div><div>=
<div>around 'sequence' =3D> sub</div><div>{</div><div>=C2=A0 =C2=
=A0 my $orig =3D shift;</div><div>=C2=A0 =C2=A0 my $self =3D shift;</div><d=
iv><br></div><div>=C2=A0 =C2=A0 if ( =C2=A0@_ =3D=3D 1 )</div><div>=C2=A0 =
=C2=A0 {</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"=
> </span>my $sequence =3D _get_parsed_sequence( shift );</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 return $self->$orig( $sequence );</div><div>=C2=A0 =
=C2=A0 }</div><div>=C2=A0 =C2=A0 else</div><div>=C2=A0 =C2=A0 {</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return $self->{sequence}; =C2=A0 =C2=A0=C2=
=A0</div><div>=C2=A0 =C2=A0 }</div><div>};</div></div><div><br></div><div>I=
get it to work.=C2=A0 Not a very elegant solution, for I must access the a=
ttribute directly instead of using an accessor.=C2=A0</div><div><br></div><=
div>One issue still remains though, if I pass the argument to the construct=
or:</div><div><br></div><div><div>my $collection =3D DCSE::Collection->n=
ew</div><div>(</div><div>=C2=A0 =C2=A0id =3D> 'test'</div><div>=
=C2=A0, sequence =3D> $sequence</div><div>=C2=A0, helix =3D> $dcse-&g=
t;helix</div><div>);</div></div><div><br></div><div>I believe that 'aro=
und' is not called, for I get the unparsed argument when I fetch the at=
tribute.=C2=A0</div><div><br></div><div>I will look into 'writers' =
and 'readers', maybe they will work better in this case?</div><div>=
<br></div><div>Cheers!</div></div><div class=3D"gmail_extra"><br><div class=
=3D"gmail_quote">On Fri, Aug 7, 2015 at 11:31 PM, Kent Fredric <span dir=3D=
"ltr"><<a href=3D"mailto:[email protected]" target=3D"_blank">kentfr=
[email protected]</a>></span> wrote:<br><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><sp=
an class=3D"">On 8 August 2015 at 09:09, Chris Prather <<a href=3D"mailt=
o:[email protected]">[email protected]</a>> wrote:<br>
> If you check the part he quoted in the original email, that is in ther=
e.<br>
> Obviously three of us missed it so maybe it could be highlighted bette=
r.<br>
<br>
<br>
</span>I think there's confusion stemming from there being *two* method=
s<br>
being wrapped, one has the guard, and the other has its internals<br>
elided, and we assume there is a guard.<br>
<br>
Method one is called "size":<br>
<span class=3D""><br>
around 'size' =3D> sub {<br>
=C2=A0 =C2=A0 =C2=A0 my $orig =3D shift;<br>
=C2=A0 =C2=A0 =C2=A0 my $self =3D shift;<br>
<br>
</span>=C2=A0 =C2=A0 =C2=A0 return $self->$orig()=C2=A0 =C2=A0##### Guar=
d<br>
<span class=3D"">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 unless @_;<br>
<br>
=C2=A0 =C2=A0 =C2=A0 my $size =3D shift;<br>
=C2=A0 =C2=A0 =C2=A0 $size =3D $size / 2<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if $self->likes_small_things();<br>
<br>
=C2=A0 =C2=A0 =C2=A0 return $self->$orig($size);<br>
=C2=A0 };<br>
<br>
<br>
</span>Method two is called "sequence":<br>
<span class=3D""><br>
around 'sequence' =3D> sub<br>
{<br>
=C2=A0 =C2=A0 my $orig =3D shift;<br>
=C2=A0 =C2=A0 my $self =3D shift;<br>
=C2=A0 =C2=A0 my $sequence =3D uc shift;<br>
<br>
=C2=A0 =C2=A0 # Do lots of things with $sequence and then<br>
</span>=C2=A0 =C2=A0 #### NO CLEAR GUARD<br>
<span class=3D""><br>
=C2=A0 =C2=A0 return $self->$orig( $sequence );<br>
}<br>
<br>
<br>
<br>
</span>And as he describes, the issue he experiences is predominantly with<=
br>
the second of these, which makes sense, given there is no code that<br>
*we* can see with the guard mechanism.<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
<br>
<br>
--<br>
Kent<br>
<br>
KENTNL - <a href=3D"https://metacpan.org/author/KENTNL" rel=3D"noreferrer" =
target=3D"_blank">https://metacpan.org/author/KENTNL</a><br>
</font></span></blockquote></div><br><br clear=3D"all"><div><br></div>-- <b=
r><div class=3D"gmail_signature"><div dir=3D"ltr">Marcos S. Barbeitos<br><b=
r>Departamento de Zoologia - Sala 360<br>Setor de Ci=C3=AAncias Biol=C3=B3g=
icas<br>Universidade Federal do Paran=C3=A1<br>Caixa Postal 19020<br>Curiti=
ba, PR 81531-990<br>Brazil<br><br>Phone: (55 41) 3361-1634</div></div>
</div>
--001a113ee386b49d75051cd275c3--