Oh Holiest of Perlish Truth Seekers:

I have created a hierarchy of classes in OO style for a testing program. At the top of the hierarchy is the TestSuite class, which creates several other types of objects, and these new objects will each create several others, etc. Everything is ultimately spawned by the TestSuite, since it is created first. However, most objects do not have an IS-A relationship with TestSuite.

My question is this: if I have a hash of globally useful information in a TestSuite instance object, how can I make this hash accessible by any object that happens to be created by a TestSuite, without passing it as a method parameter to every new object created by TestSuite? Or, if it is already accessible, how do I properly access it from one of the secondary or tertiary objects? For example:

my $ts = new TestSuite(); # $ts->{info} is now defined $ts->make_a_blob(); # $ts->{blob} is now a ref to an object of type Blob $ts->print_blob() # Calls $self->{blob}->print_stuff(); # I want the method Blob::print_stuff() to access information in $ts-> +{info} #I want to avoid doing this: $ts->{blob}->print_stuff( $ts->{info} );
In other words, what's the best way for Blob::print_stuff() to access $ts->{info} if we assume Blob::print_stuff() is always called from a method of TestSuite? much thanks

In reply to Proper way to create 'globals' by zaven

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.