First off, personally I stay as far away from indirect object syntax as I can. It _will_ bite you at some point or another. Replace that new $name to $name->new() and teach yourself never to use the syntax and youll never get bitten.

As for the solution to your problem it seems like it would be pretty likely that its due to filename case issues on your system. The file name is probably: api/bess/query/Query.pm but the package name is "Api::Bess::Query" so when you require it you cant directly use the filespec to determine the actual package contained. This is more serious than you may think as the rules do NOT say that the contents of a file that is use()d/require()d is the same as the file is named. Thus there is no reliable way to go from the filename to the package name that it contains. For instance

#file: Bar.pm packge Foo; sub yada { print "...\n" }; __END__ perl -MBar -e "Foo::yada()"
should work just fine.

Thus you will need to parse the file looking for package statements. This gets even more complex in that a file can contain multiple packages (I do this very often indeed) and also could be dynamically creating packages at run or compile time. Thus the file when required may actually generate a class and not contain anything parseable.

So parse the file for package statements and then act apon them, but expect that it wont be a generalized solution.

UPDATE: I suppose what you could do is find out the packages that exist prior to the require as well as after, filter the ones that already existed and then go from there. I know its possible but offhand im not sure how to do it. Id have to research into it more extensively than I have time. Perhaps a guru (there are more :-) is around that can clarify the approach.

Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)


In reply to Re: Dynamically load unknown modules by demerphq
in thread Dynamically load unknown modules by Ryszard

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.