Thanks for the pointer, but I'm still not able to find the filename of the package. I have played a little with caller(), but it seems to provide details of the calling program, rather than the included module?

Here is more what I am looking to do:

# my.pl use My::Factory; my $obj = My::Factory->new('Apple'); ... # My/Factory.pm package My::Factory; 1; sub new{ my $factoryclass = shift; my $class = "My::" . shift; # My::Apple my $filename = $class; $filename =~ s/::/\//g; $filename .= '.pm'; # My/Apple.pm if ( -e $filename ) { require $filename; } else { die "not found: $filename"; } }

Which all looks good and dandy, except that My::Factory is picked up from @INC at runtime. I thought that a package might know its own filename?

Note that I don't want to pick up My::Apple from somewhere else in @INC - I want it to be in the same place as My/Factory.pm

Apologies if that is not clear...

Off to see if I can figure out how Carp does it...

Regards

Jeff


In reply to Re: Re: Filename of current package by jaa
in thread Filename of current package by jaa

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.