Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <55C69077.3040703@gmail.com> (permalink) |
| Date | 2015-08-08 16:27 -0700 |
| Subject | Re: 'around' method modifier does not seem to work |
| References | <CANoac9Ukr4rW4f18bfSHFXpBD6EP9krrraSqAvvHBg0hzxx-tg@mail.gmail.com> <1438981770245.5432f7da@Nodemailer> <CAATnKFAv5Gw9sUU3wsDyLSXmphFAEZMF_inKi60yqwhror7jZQ@mail.gmail.com> <CA+gEHsU0j9JkupjdaEjz93byDVGA+9PMNQBEZQrGfhQSmTjrRQ@mail.gmail.com> |
| From | barefootcoder@gmail.com (Buddy Burden) |
Marcos,
> around 'sequence' => sub
> {
> my $orig = shift;
> my $self = shift;
>
> if ( @_ == 1 )
> {
> my $sequence = _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.
Well, you have the accessor right there, if you'd like to use it: it's
called `$orig`:
return @_ ? $self->$orig( _get_parsed_sequence(shift) ) : $self->$orig;
> 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.
One of the few useful things I learned from C++ that's applicable to
Moose: initialization != assignment. In C++ you'd be stuck with
duplicating some code, but in Moose ...
> I will look into 'writers' and 'readers', maybe they will work better in
> this case?
Look into "triggers." ;->
-- Buddy
Back to perl.moose | Previous | Next — Previous in thread | Next in thread | Find similar
'around' method modifier does not seem to work msbarbeitos@gmail.com (Marcos Barbeitos) - 2015-08-06 20:04 -0300
Re: 'around' method modifier does not seem to work btilly@gmail.com (Ben Tilly) - 2015-08-06 19:02 -0700
Re: 'around' method modifier does not seem to work perigrin@prather.org ("Chris Prather") - 2015-08-07 09:27 -0700
Re: 'around' method modifier does not seem to work btilly@gmail.com (Ben Tilly) - 2015-08-07 11:28 -0700
Re: 'around' method modifier does not seem to work perigrin@prather.org ("Chris Prather") - 2015-08-07 14:09 -0700
Re: 'around' method modifier does not seem to work kentfredric@gmail.com (Kent Fredric) - 2015-08-08 14:31 +1200
Re: 'around' method modifier does not seem to work msbarbeitos@gmail.com (Marcos Barbeitos) - 2015-08-08 17:18 -0300
Re: 'around' method modifier does not seem to work barefootcoder@gmail.com (Buddy Burden) - 2015-08-08 16:27 -0700
Re: 'around' method modifier does not seem to work kentfredric@gmail.com (Kent Fredric) - 2015-08-11 14:15 +1200
csiph-web