Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
eval came to my mind (I hope I am not totally missing the point here)

StaticMammal.pm (The equivalent of your A):

#!/usr/bin/perl -wT package StaticMammal; use strict; use warnings; sub new { my ($class) = @_; my $new_critter = bless {}, $class; return $new_critter; } sub walk { my ($self) = @_; print "A " . ref( $self ) . " walks " . $self->walks_how() . "\n"; return; } sub talk { my ($self) = @_; print "A " . ref( $self ) . " says " . $self->talks_how() . "\n"; return; } sub walks_how { return q(ponderously); } sub talks_how { return q(Grrr); } 1; __END__
DynamicMammals.pm (The middleman that generates the equivalent of your Bn):
#!/usr/bin/perl -wT package DynamicMammals; use strict; use warnings; use lib '.'; my %style_of = ( Cat => { talks => q(meow), walks => q(in beauty, like the night), }, Dog => { talks => q(woof), }, FrankenMammal => { ## empty hash }, ); my $package_str = q(); foreach my $mammal (keys %style_of) { $package_str .= qq( package Dynamic$mammal; use base qw(StaticMammal); ); my $action_href = $style_of{ $mammal }; foreach my $action (keys %$action_href) { $package_str .= sprintf q( sub %s_how { return q(%s); } ), $action, $action_href->{ $action}; } } eval $package_str; if (my $msg = $@) { die "Eval error: $msg\nwhile trying to eval:\n$package_str"; } 1; __END__
Something that calls the equivalent of your Bn:
#!/usr/bin/perl -wT use strict; use warnings; use lib '.'; use DynamicMammals; my $felix = DynamicCat->new(); my $spot = DynamicDog->new(); my $thing = DynamicFrankenMammal->new(); foreach my $critter ($felix, $spot, $thing) { $critter->walk(); $critter->talk(); } __END__

In reply to Re: Autocreating Classes by fenLisesi
in thread Autocreating Classes by water

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 perusing the Monastery: (15)
    As of 2014-07-31 18:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (250 votes), past polls