Hi, writing OO code by hand is a pain the arse and consumes valuable time that should be spent developing your game scenarios :-) Use a Modern Perl OO framework instead. Working "without CPAN" is for masochists.

Here is a small demonstration using Moo based on what I could glean from your OP. I hope it's useful.

use 5.026; use warnings; use Data::Dumper; { package Entity; use Moo; use Types::Standard qw/ InstanceOf Int /; has race => ( is => 'ro', isa => InstanceOf['Race'], require +d => 1 ); has class => ( is => 'ro', isa => InstanceOf['Class'], require +d => 1 ); has game_rank => ( is => 'rw', isa => Int, default => sub{ 0 } ); sub increase_rank { $_[0]->game_rank( $_[0]->game_rank + $_[1] ) } sub decrease_rank { $_[0]->game_rank( $_[0]->game_rank - $_[1] ) } 1; } { package Race; use Moo; use Types::Standard qw/ Str /; has name => ( is => 'ro', isa => Str, required => 1 ); has realm => ( is => 'ro', isa => Str, default => sub {'Middle Ear +th'} ); 1; } { package Class; use Moo; use Types::Standard qw/ Str /; has name => ( is => 'ro', isa => Str, required => 1 ); has is_noble => ( is => 'lazy', builder => sub { $_[0]->name eq 'h +igh' } ); 1; } { package Elf; use Moo::Role; use Types::Standard qw/ Enum Str /; has name => ( is => 'ro', isa => Str, required => 1 ); has sex => ( is => 'ro', isa => Enum[qw/ m f /], required => 1 ); 1; } { package Ranger; use Moo::Role; use Types::Standard qw/ Str /; has ranger_rank => ( is => 'ro', isa => Str, default => sub { 'Pri +vate' } ); 1; } { package RangerElf; use Moo; use Types::Standard qw/ Str /; extends 'Entity'; with 'Elf', 'Ranger'; around BUILDARGS => sub { my ( $orig, $class, %args ) = @_; $args{'class'} = Class->new( name => $args{'class'} ); $args{'race'} = Race->new( name => 'Elf', realm => 'Gondor' ) +; return $class->$orig( %args ); }; has sword_name => ( is => 'rw', isa => Str ); 1; } ##################################################### my $ranger = RangerElf->new( name => 'Fingolfin', sex => 'm', class => 'high', ranger_rank => 'Captain', ); say sprintf '%s\'s game ranking is now: %s', $ranger->name, $ranger->game_rank; if ( $ranger->race->name eq 'Elf' ) { say sprintf 'As an Elf, %s gets a special sword.', $ranger->name; $ranger->sword_name('Ringil'); } if ( $ranger->class->name eq 'high' and $ranger->sword_name ) { say sprintf '%s\'s game ranking is now: %s', $ranger->name, $ranger->increase_rank(10); } say sprintf '%s %s a member of the nobility.', $ranger->name, $ranger->class->is_noble ? 'is' : 'is not'; say '-' x 32; say 'Obj dump: ' . Dumper $ranger; __END__
Outputs:
$ perl 1203175.pl Fingolfin's game ranking is now: 0 As an Elf, Fingolfin gets a special sword. Fingolfin's game ranking is now: 10 Fingolfin is a member of the nobility. -------------------------------- Obj dump: $VAR1 = bless( { 'class' => bless( { 'is_noble' => 1, 'name' => 'high' }, 'Class' ), 'game_rank' => 10, 'name' => 'Fingolfin', 'race' => bless( { 'name' => 'Elf', 'realm' => 'Gondor' }, 'Race' ), 'ranger_rank' => 'Captain', 'sex' => 'm', 'sword_name' => 'Ringil' }, 'RangerElf' );


The way forward always starts with a minimal test.

In reply to Re: without CPAN, templates and random named module class members by 1nickt
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.