Here's a version using Moose::Exporter.

#!/usr/bin/perl use lib 'lib'; use strict; use warnings; use feature 'say'; use Data::Dumper; package Testzool { use Acme::Pool; # normal has qw'name is rw default rosemary'; # readonly with default value hasrod 'favfood', 'pizza'; # readwrite with default value hasrwd 'age', 111; # readonly hasro qw'id default 1234567'; # readwrite hasrw 'cash'; # make has() from string hasstr 'height is rw default 1456'; }; package main; run(); sub run { my $obj = Testzool->new; $obj->cash(86); say "obj = ", Dumper($obj); }

and the Acme::Pool module:

# POOL -> Perl Object Oriented: Extra Lazy # should have an umlaut on the second O but it fell off. package Acme::Pool; use strict; use warnings; use feature 'say'; our $VERSION = '0.02'; use Moose(); use Moose::Exporter; Moose::Exporter->setup_import_methods (also => 'Moose', with_meta => [ qw/hasrw hasrwd hasro hasrod hasstr/] ); sub hasrw { my ($meta, $name, %options) = @_; $meta->add_attribute($name, is => 'rw', %options, ); } sub hasrwd { my ($meta, $name, $default, %options) = @_; $meta->add_attribute($name, is => 'rw', default => $default, %opti +ons, ); } sub hasro { my ($meta, $name, %options) = @_; $meta->add_attribute($name, is => 'ro', %options, ); } sub hasrod { my ($meta, $name, $default, %options) = @_; $meta->add_attribute($name, is => 'ro', default => $default, %opt +ions, ); } sub hasstr { my ($meta, $spec, %options) = @_; my @words = split ' ', $spec; my $name = $words[0]; $meta->add_attribute(@words, %options, ); } return 1; # file loaded successfully __END__

In reply to Re: 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.