in reply to Re: Moose log string class
in thread Moose log string class
Regarding:
a) Thanks.
b) I did not understand what you said.
c) I found nothing in the cookbook about explicit "reader" and "writer" attribute modifiers as described in the Moose Manual about Attributes
For example, I'd like to do something like this (which does not work with Moose even though one is supposed to be able to explicitly specify "reader" and "writer" accessors by name):package QuackLog; use Moose; use namespace::autoclean; use strict; my +@log_string_parts = qw(timestamp foo bar baz qux norf quack honk woof + meow blerf); has $_=> (is => 'rw') for(@log_string_parts); has log_s +tring => ( is => 'rw', reader=> 'get_log_string', writer => 'set_log_ +string', ); sub get_log_string{ my ($self) = shift; return(join ' ',m +ap {$self->can($_);$self->$_} @log_string_parts); } sub set_log_strin +g{ my ($self,$s)=@_; my @part_values=split / /,$s; for my $method (@l +og_string_parts){ $self->can($method); $self->$method(shift @part_val +ues); } $self; } __PACKAGE__->meta->make_immutable();
This, however, produces a compile time error:
You are overwriting a locally defined method (get_log_string) with an +accessor...
PS: I did try the symbolic $method lookup, having used it many times before in Perl objects, but for some reason it didn't work, and I attributed the failure to my lack of understanding of Moose rather than the more likely explanation which was just a bad choice of syntax.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Moose log string class ( cached attribute trigger clearer )
by Anonymous Monk on Feb 12, 2015 at 03:38 UTC |