in reply to moose reader / writer
Using Moose::Meta::Attribute::Native::Trait::Array lets you write code like...
Perl: perlintro perlretut perldoc Basic debugging checklist Yes, even you can use CPAN
PerlMonks: How do I post a question effectively? Markup in the Monastery How do I post a question effectively? I know what I mean. Why don't you?
General: How To Ask Questions The Smart Way What every computer scientist should know about floating-point arithmetic
To Be Continued...
package Thing; use Moose; has '_data' => ( is => 'ro', isa => 'ArrayRef', traits => [ 'Array' ], default => sub { [] }, # writer => '_add_data', # reader => '_get_data', handles => { add_data => 'push', get_data => 'get', }, ); package main; use Data::Dump; my $thing = Thing->new; $thing->add_data({$_ => $_**2 }) for 1..5; dd $thing->get_data(2); dd $thing; __END__ { 3 => 9 } bless({ _data => [{ 1 => 1 }, { 2 => 4 }, { 3 => 9 }, { 4 => 16 }, { 5 => 25 + }], }, "Thing")
Does that do the job for you?
Perl: perlintro perlretut perldoc Basic debugging checklist Yes, even you can use CPAN
PerlMonks: How do I post a question effectively? Markup in the Monastery How do I post a question effectively? I know what I mean. Why don't you?
General: How To Ask Questions The Smart Way What every computer scientist should know about floating-point arithmetic
To Be Continued...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: moose reader / writer
by ag4ve (Monk) on Sep 19, 2011 at 19:03 UTC |
In Section
Seekers of Perl Wisdom