I am using perlclass syntax whenever I write a new module, and I often rewrite an existing one when I make other changes to it.
I had moved from blessed classes to Moose long ago and found it rewarding to rewrite when I touched old code. I find Moo(se) classes easier to read and Moo(se) brings a lot of convenience (validation, delegations, coercions) so that I could eliminate some subroutines.
The new core OOP still lacks most of these convenience features, I just shrug it away... because I can afford it.
Some random observations:
- I prefer the core OOP keywords to Moo(se) syntax. Moose was a game changer, and also a showcase what you can do with the Perl interpreter, but it is bound to Perl syntax with its imported routines. Moose took care for that by defining conventions:
has 'x' => (is => 'rw', isa => 'Int');
That is a clever use of the fat comma and superfluous parentheses. To the Perl interpreter it looks the same as the less readable alternatives
has('x','is','rw','isa','Int');
has(qw/x is rw isa Int/);
In core OOP, you write:
field $x :reader :writer; # no types (yet)
To be fair, this has its own quirks due to the way attributes are parsed by the interpreter. One can write that like that:
field $x : reader writer;
This is quite a challenge for syntax-aware editors...
- Core OOP has no roles (yet). I usually work around that by converting the role to a class and making its objects fields of the class "consuming" the role. Several times I found that I actually prefer this "has-a" relationship.
- The Perl debugger and various data dumpers and serializers do not (yet) work on core objects. I like to use the debugger, my approach is cheating: I use Feature::Compat::Class and let it fall back to Object::Pad which provides a meta object protocol which can be used by the debugger.
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.