Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Thanks! I made some modifications and used the idea. Mine turned out something like:

1 package Local::Multipath; ... 45 my %mpByType; 46 47 sub new { 48 my ($class, %opts) = @_; 49 return bless \%opts, $class; 50 } 51 52 sub factory { 53 my (%opts) = @_; 54 croak ("Missing parameters!") unless exists $opts{co}; 55 my $type = _whichType; 56 my $module = "Local::Multipath::$type"; 57 { 58 eval "use $module"; 59 } 60 croak "Failed to load module $module: $@\n" if $@; 61 $mpByType{$type}->new (%opts); 62 } 63 64 sub REGISTER_TYPE { 65 my ($type) = @_; 66 my ($name) = $type =~ m/Multipath::(.*)/; 67 $mpByType{$name} = $type; 68 }
...
1 package Local::Multipath::DMMP; 2 use strict; 3 use warnings; ... 7 8 REGISTER_TYPE Local::Multipath::DMMP; ...
... somewhere else in code land ...
my $mp = Local::Multipath::factory (co => $conf);

The _whichType function returns 'DMMP' or 'Powerpath' after sniffing around for what we actually have.

It's nearly the same as what you suggested, but I didn't need the added 'type' attribute in this case, so simpler.

I could almost get away without the REGISTER_TYPE, but it has the added appeal of not having to hard code the things Multipath can handle. Just add a new module like the DMMP module shown to add new capabilities;

Thanks for the suggestion: perfect synergy.


In reply to Re^2: Inheritance: parent class determine which child class to use? by fbicknel
in thread Inheritance: parent class determine which child class to use? by fbicknel

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (10)
    As of 2014-10-21 22:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (112 votes), past polls