It's been a while since I hit the keys on my codeboard - so apologies if ya'all know all this anyway.

I've recently discovered Object::Pad - and love it. Fingers crossed for some future OO goodness in CORe.

I've kind of forgotten where to ask Perl questions, and posted one on Discord->#perl:

A question on Object::Pad and virtual parent classes.

I want to class Parent :does(RoleA) :does(RoleB) and have class ChildA isa:(Parent); class ChildB isa:(Parent) etc. without having to implement the RoleA and RoleB requires methods inside Parent - in other words, Parent is a virtual class - one that would never be instantiated.

If I do this, it appears that the :does() are evaluated on Parent at compilation rather than instantiation of ChildA or ChildB which actually do implement the requires.

Is there a way to do virtual parent classes?

Kudos to gordonfish for suggesting using role to do this.

So as illustration, you can use role as follows to compose virtual classes.

#!/usr/bin/perl #----------------------------------------------------------------- +------------- use v5.32; use Object::Pad; role Role::FeederThings { requires earnDosh; requires buyKFC; } role Role::TaxiDriver { requires waitForever; requires driveForMiles; } role Role::DadThings :does(Role::FeederThings) :does(Role::TaxiDriver) { } class Parent :does(Role::DadThings) { }

Which results in:

Class Parent does not provide a required method named 'earnDosh' at +./,t1.pl line 25.

Just sharing...

0.02$AU, Jeff.


In reply to Object::Pad - Virtual Classes can be composed using Roles. by jaa

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.