...almost there :)   but you'd still have to get rid of the "::" in case of a package name like "Foo::Module". Also, you could write ref($self) || $self, in which case you could call load_config on both the class or an object instance.

#!/usr/bin/perl package Base::Module; sub load_config { my $class = shift; my $module = $class->config_module; print "about to require $module\n"; #require $module; } sub config_module { $self = shift; my $pkg = ref($self) || $self; $pkg =~ s#::#/#g; # optionally remove "/Module" # $pkg =~ s#/[^/]+\z##; return "$pkg/Config.pm"; } package Foo::Module; use base qw(Base::Module); sub new { return bless {}, shift; } package main; Foo::Module->load_config(); Foo::Module->new()->load_config(); __END__ $ ./727519.pl about to require Foo/Module/Config.pm about to require Foo/Module/Config.pm

BTW, the sub config_module would work the same way when declared in Foo::Module, though - if I'm understanding you correctly - your idea was to put it in the base class...  (Actually, it would first be looked up in Foo::Module, and only then, when this fails, in Base::Module (via inheritance).)


In reply to Re^5: "use"ing from dynamic namespace by almut
in thread "use"ing from dynamic namespace by dsheroh

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.