<$0.02>
When I'm doing something so simple that
Moo is more than I need, I usually turn to
Class::Accessor::Fast. You could easily copy the source from
Class::Accessor and/or
Class::Accessor::Fast if you really can't install modules from CPAN.
package Foo;
use strict; use warnings;
use parent 'Class::Accessor::Fast';
BEGIN {
__PACKAGE__->mk_accessors(qw/ bar qux /);
}
sub new {
my $class = shift;
return $class->SUPER::new();
}
1; # return true
perl -MFoo -E'
my $foo = Foo->new;
$foo->bar("baz");
$foo->qux( $foo->bar );
say $foo->bar;
say $foo->qux;
'
Output:
baz
baz
</$0.02>
The way forward always starts with a minimal test.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.