I'm sorry but I don't understand what you are asking, in both questions.

I think in your first question, you want to compose a class from two other base classes, but I don't understand what part should be abstract ("Race", "Class") and what part should be concrete ("Elf", "Ranger"), or where your problem is.

My approach for the first topic would be to keep the race and class of a character as separate objects in the player character. Maybe some transmutation changes the race of a character. Also, the boni/mali usually conferred by race and class are quite similar, so I think it would be more beneficial to keep them the same and have them add/subtract from the player base stats.

sub HollyGame::ElfRanger::new { my( $class, %options ) = @_; $options{ class } = HollyGame::Ranger->new(...); $options{ race } = HollyGame::Elf->new(...); bless \%options => $class; }

If you want to make even that more generic, you can maybe glean the race+class from the classname:

sub HollyGame::RaceClassBase::new { my( $class, %options ) = @_; my( $race, $class ) = ($class =~ /::([A-Z][a-z]+)([A-Z][a-z]+)/); $options{ class } = "HollyGame::$class"->new(...); $options{ race } = "HollyGame::$race"->new(...); bless \%options => $class; } package HollyGame::ElfRanger; use base 'HollyGame::RaceClassBase'; ... HollyGame::ElfRanger->new();

For your second question, an "object" is just a hash, so you can of course change the key in it:

sub new { my( $class, %options) = @_; # rename from "tobechangedname" to "newname" my $optval = delete $options{ tobechangedname }; $options{ newname } = $optval; bless \%options => $class; }

In reply to Re: without CPAN, templates and random named module class members by Corion
in thread without CPAN, templates and random named module class members by holyghost

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.