Greetings brethren. Some of you may remember my comments and questions from last month about making effective use of multiple inheritance for run-time selection of mixin classes, in response to which I received some helpful input.

I've continued working on ideas drawn from those discussions and have assembled a reusable solution to this problem, and I'd like to run it by the monastery for feedback before posting it to CPAN.

The new package provides a class factory that creates new packages that inherit from multiple classes, and includes a method to allow mixin methods to redispatch to the base class functionality.

I've tentatively named it "Class::MixinFactory" in hopes of capturing the salient details -- it generates new classes by assembling mixins -- but would welcome alternate suggestions.

A simple use might look the following:

package MyClass; use Class::MixinFactory -hasafactory; sub new { ... } sub foo { return "Foo Bar" } package MyClass::Logging; sub foo { warn "Calling foo"; (shift)->NEXT('foo', @_) } package MyClass::UpperCase; sub foo { uc( (shift)->NEXT('foo', @_) ) } package main; my $class = MyClass->class( 'Logging', 'UpperCase' ); print $class->new()->foo(); # Calls MyClass::Logging::foo, MyClass::UpperCase::foo, MyClass::foo

I've posted a draft of the documentation online.

There are a number of related modules on CPAN, but none with quite the same mix of functionality:

Feedback would be welcome; some of the questions I'm considering are:


In reply to Stacking Mixin Classes at Run-time with Class::MixinFactory by simonm

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.