I'm wanting to create a test harness using Test::More to test nearly a dozen classes. The problem is that due to the interdependence between classes, substantive tests cannot be written without a number of classes being instantiated at the same time (The classes represent the object model of a database...), so implementing boilerplate code will only be useful as long as I can embed a number of knobs into the interface.

So, what I have dreamed up is to create yet another module which accepts a hash reference as an argument which specifies the class name(s), method(s), & arguments which are then instantiated & connected together -- passing something akin go the following:

{ 'classname_a' => { 'method_a' => [ parameter1, parameter2 ], 'method_b' => [ parameter1 ], 'method_c' => undef }, 'classname_b' => { 'method_a' => undef, 'method_b' => [ parameter1 ] } }
What I haven't resolved is how to decode this structure into the needed syntax. I haven't been able to get past the following:
sub create { my $ref = shift; my @parameters; my @objects; foreach my $classname (keys %$ref) { my $r = new $classname; # instantiate class foreach my $method (keys %{$ref{$classname}}) { for my $parameter (keys %{$ref{$classname}{$method}}) { push @parameters, ${$ref{$classname}{$method}{$paramet +er}}; } $r->$method(@parameters); } push @objects, $r; } return \@objects; }

I'm sure I am not the first to think of trying to take the output from Data::Dumper & recreate the object(s) hierarchy represented.

Any corrections you would suggest for the syntax (or design...) would be greatly appreciated. Thank you very much.

In reply to creating objects via string representations? by Anonymous Monk

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.