What you need to bear in mind, is that an attribute could have several different names associated with it. Consider:
use v5.14;
package Foo {
use Moo;
has foo1 => (
is => "rw",
init_arg => "foo2",
reader => "foo3",
writer => "foo4",
);
}
# Create an object, setting the attribute...
my $obj = Foo->new(foo2 => 40);
# Increment the value...
$obj->foo4( $obj->foo3 + 1 );
# Or cheat and access the hashref directly...
$obj->{foo1}++;
# Print the value of the attribute...
say $obj->foo3;
Moo does have all this data buried away, but you may be better off using Moose or Mouse which provide documented, public APIs for all this attribute introspection stuff.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
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.