Thanks Toby. The lists of names is nice, but then they don't have defaults. Which would mean the constructors would have to hold the default values. I'd rather the defaults were in the definition.

Moose::Tiny and Object::Tiny only do read-only, so they won't work.

Something like this might work:

package Haz; use Modern::Perl; use lib 'lib'; use Moo; use Acme::Mo; # has split / /, 'cheezburgers is rw default 22'; haz 'cheezburgers is rw default 22'; rw 'weight default 100'; ro 'name default barbara'; rwdef100 'money'; package main; run(); sub run { my $haz = Haz->new; say "haz = ", Dumper($haz); say 'i haz ', $haz->cheezburgers, ' cheezburgers'; $haz->weight(99); say 'weight: ', $haz->weight; say 'name: ', $haz->name; #$haz->name('jane'); say "it all worked"; } __END__
# lib/Acme/Mo.pm package Acme::Mo; use Modern::Perl; use Filter::Simple; sub hazmat { my $def = shift; $def =~ s/['"]//g; $def =~ s/(\w+)/'$1',/g; my $line = "has $def;"; return $line; } sub hasrw { my $def = shift; $def .= ' is rw'; return hazmat($def); } sub hasro { my $def = shift; $def .= ' is ro'; return hazmat($def); } sub hasrwdef100 { my $def = shift; $def .= ' is rw default 100'; return hazmat($def); } FILTER { s/^ro (.*);/hasro($1)/gem; }; FILTER { s/^rw (.*);/hasrw($1)/gem; }; FILTER { s/^haz (.*);/hazmat($1)/gem; }; FILTER { s/^rwdef100 (.*);/hasrwdef100($1)/gem; }; 1; __END__

In reply to Re^2: Extra-lazy object oriented programming by Anonymous Monk
in thread Extra-lazy object oriented programming by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.