develooper Front page | perl.moose | Postings from August 2015

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

Thread Previous | Thread Next
From:
Marcos Barbeitos
Date:
August 10, 2015 19:03
Subject:
Re: 'around' method modifier does not seem to work
Message ID:
CA+gEHsUbUSz+b2TeKqM8-JPu=+jFkE+85SiaUrCj2AhZg7qYsg@mail.gmail.com
Hi Karen and everybody else,

Thanks for the tip, it works as expected, except when I pass the attribute
to the constructor.  In that case, I get the original sequence, and not its
parsed version.

I added a print statement to the 'around' modifier so that I could keep
track of how many times 'around' was called.

I noticed that the modifier was called when you set the attribute and
everytime you fetch it, but not when it is passed to the constructor. As
Buddy noticed, maybe it really shouldn't be.

No biggie, though, I found out that I may actually have to re-structure the
code and I'll probably have no need for the modifier after I do.

Again, many thanks to all!

On Sat, Aug 8, 2015 at 8:52 PM, Karen Etheridge <perl@froods.org> wrote:

> > On Sat, Aug 8, 2015 at 1:18 PM, Marcos Barbeitos <msbarbeitos@gmail.com>
> wrote:
>
> >     I get it to work.  Not a very elegant solution, for I must access
> the attribute directly instead of using an accessor.
>
> No, instead of
> >             return $self->{sequence};
> you should do
>               return $self->$orig();
> to use the proper reader mechanism.
>
> >     One issue still remains though, if I pass the argument to the
> constructor:
> >     my $collection = DCSE::Collection->new
> >     (
> >        id => 'test'
> >      , sequence => $sequence
> >      , helix => $dcse->helix
> >     );
> >
> >     I believe that 'around' is not called, for I get the unparsed
> argument when I fetch the attribute.
>
> This should be fixed when you fix the code path for the reader as above.
>
>


-- 
Marcos S. Barbeitos

Departamento de Zoologia - Sala 360
Setor de Ciências Biológicas
Universidade Federal do Paraná
Caixa Postal 19020
Curitiba, PR 81531-990
Brazil

Phone: (55 41) 3361-1634

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About