Monks,

I am currently working on a web-based portal-style application that must be capable of importing a number of services (modules) at run-time.

Each service provides different functionality, for example a hook into an existing system to allow data to be aggregated, or providing some completely new functionality.

The portal system under construction makes use of a fixed interface, implemented and extended by each service to allow the portal to dynamically determine each service's interface at run-time. For example, Service X might implement methods get_legacy_data and update_legacy_data, returning a description of these methods via a call to the required get_service_interface method.

For the majority of method calls, a simple list of parameters is passed, using the following code:

sub call_service { my $svc = shift; my $cmd = shift; my @args = @_; foreach ( @args ) { $_ = "\"$_\"" } my $arg = join ",", @args; return eval $svc . "::" . $cmd . "(" . $arg . ")"; }

My problem comes where I need to pass a data structure, rather than a flat list of elements, into some service, for example an array of arrays. The method above simply converts each array in the structure into a string, which obviously isn't the intended result.

Can anyone suggest a way of changing the sub above to allow more complex data structures to be passed?

Thanks in advance,


In reply to Passing a data structure via a dynamically-built subroutine call by Tanalis

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.