I am working on an internal Perl based client for a REST service. So I have two OO modules, let us say A & B. The module A is the one that the end user uses & the module A in turn "uses" module B, which is pretty much a wrapper around HTTP::Request module to make HTTP requests to the server. This could look like:
use A; my $a = A->new(); $a->execute(<params>);

Module A has an execute() method, which when invoked, creates the headers etc & sends data to the server using module B. Now this is where it gets interesting for me.

This REST service (apart from other stuff) returns a representation of a custom CSV file object. So, I can say get me a handle to a particular CSV file & it'll return a JSON representation of it. And on this, I can do other operations like data mining (which will be happening on the server). I want to represent this object as say C. So when I say $a->getCSVHandle(), I should be returning to the end user an object type C. That means module A will import module C and in getCSVHandle() method, it instantiates class C (with its relevant instance vars) & retunrs it. So, when I call any methods on this C object, it should do some relevant data munging & in turn use module A's execute method to send the HTTP request, because that is the end goal anyway.

But to use the module A's execute method, I will have to "use" it in module C, which will create a circular dependency as module A already imports C, which I want to avoid. How can I achieve the end result without getting in to this nasty circular dependency?


In reply to Accessing a module's method without causing circular dependency by rovingeyes

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.