Hi,
I'm having trouble accessing child data from a base class method. Instead of a reference to the class data, I'm getting a reference to an empty array. Can anyone tell me what I'm doing wrong?

BaseClass.pm:

package BaseClass; sub _classobj { my $invocant = shift; my $class = ref $invocant || $invocant; no strict "refs"; return \%$class; } sub new { my $invocant = shift; my $class = ref $invocant || $invocant; my $classData = $class->_classobj(); my $name = $classData->{Column_Header}; my $value = (@_) ? shift : undef; bless { name => "$name", value => "$value", cdata => \%classData, }, $class; } sub get_column { my $invocant = shift; my $class = ref ($invocant) || $invocant; my $cdata = $class->_classobj; unless defined "$cdata" { print "class data not found \n"; die; } my $column = $$cdata->{Input_column}; return $column; } 1;

ChildClass.pm
package ChildClass; use base qw(BaseClass); our %ChildClass = ( Blank_ok => 'no', Column_header=> '^(cell|name)$', Field_length => 20, Input_column => 'Unknown', Invalid_characters => '[^\W-]', ); 1;
test_script.pl
#! /usr/bin/perl use strict; use warnings; use diagnostics; use Carp; use ChildClass; print "column: ", ChildClass->get_column;

I tried to mimick the setup listed here perltootc. When at the return statement for _classobj() in the debugger I get the following for each command:

> p $class<br> ChildClass<br> > x %ChildClass<br> empty array<br> > x %ChildClass::ChildClass<br> 0 'Invalid_characters'<br> 1 '[^\\W-]'<br> 2 'Column_header'<br> 3 '^(cell|name)$'<br> 4 'Blank_ok'<br> 5 'no'<br> 6 'Input_column'<br> 7 'Unknown'<br> 8 'Field_length'<br> 9 20
Why should I have to fully qualify the ChildClass hash? In the perltootc tutorial that doesn't seem to be necessary from the _classobj method...

In reply to Trouble Accessing Class Data by kernelsanders

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.