In an ideal world, these user agent classes would have been written from the ground up as Moose roles, so could be combined however you like.

Something like this should work though...

use 5.010; use Class::Load qw/load_class/; sub compose { load_class($_) foreach @_; # Note "state" is Perl 5.10 mojo. For back compat, use # "my $count = 0" OUTSIDE the sub definition. That is, # create a closure over it. state $count = 0; my $package = sprintf('%s::__COMPOSED__::X%04x', __PACKAGE__, ++$c +ount); { no strict 'refs'; @{"$package\::ISA"} = @_; } $package; } my $class = compose(qw/LWP::UserAgent Data::Dumper/); say $class; my $obj = $class->new; say $obj; say $obj->can('agent'); say $obj->can('Dumper'); # Or even... my $obj2 = compose(qw/LWP::UserAgent Data::Dumper HTTP::Request/)->new +;

The problems creep in when the many classes you're inheriting from all override the same method. For example, LWP::UserAgent::Proxified, LWP::UserAgent::Determined and LWP::UserAgent::Cached might all override LWP::UserAgent's "request" method in different ways.

If LWP::UserAgent::Proxified inherits from all of them, then although Perl's method resolution order is well-defined, it will only call the overridden method from a single one of its child classes.

This is where Moose roles - and in particular, method modifiers - really shine. The base class provides the default "request" implementation, and he Proxified, Determined and Cached roles provide modifiers for the default implementation. The roles can usually be combined safely, with the various modifiers all getting applied to the "request" method.


In reply to Re: base class manipulation: Is there something similar on CPAN? by tobyink
in thread base class manipulation: Is there something similar on CPAN? by OlegG

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.