Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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) (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__ (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

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (6)
    As of 2017-11-19 14:25 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (281 votes). Check out past polls.