import conundrum

Discussion in 'Perl Misc' started by kj, Mar 29, 2007.

  1. kj

    kj Guest

    According to the documentation for "use", if one wants to prevent
    a module's import from being called when the module is use'd, one
    is supposed pass an empty list as the second argument to "use":

    use Foo::Bar ();

    But now suppose that Foo::Bar in turn use's some other module Foo:

    ############################################################
    # Foo/Bar.pm
    package Foo::Bar;
    use Foo;

    # yadda-yadda

    1;
    __END__
    ############################################################

    and, furthermore, suppose that Foo *has* an import method:

    ############################################################
    # Foo.pm
    package Foo;

    sub import {
    shift->go_nuts( @_ );
    }

    # yadda-yadda

    1;
    __END__
    ############################################################

    In this case, even if the user loads Foo/Bar.pm with "use Foo::Bar
    ()", Foo::import is still invoked.

    My problem is this: how to give the users of Foo::Bar the opportunity
    to veto the calling of Foo::import? The only approach I can think
    of is to define a Foo::Bar::import method whose only function is
    to call Foo::import, and change the line "use Foo" to "use Foo ()":

    ############################################################
    # Bar/Foo.pm
    package Foo::Bar;

    use Foo ();

    sub import {
    shift;
    Foo->import( @_ );
    }

    # yadda-yadda

    1;
    __END__
    ############################################################

    This does indeed have the effect of "transmitting" the "()" argument
    from "use Foo::Bar ()" through to Foo. But in a suite of modules
    of any complexity this approach quickly becomes cumbersome.

    Is there any other for Foo to know that it has been use'd by a
    module that *itself* was use'd with a "()" argument?

    TIA!

    kj

    --
    NOTE: In my address everything before the first period is backwards;
    and the last period, and everything after it, should be discarded.
    kj, Mar 29, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Owen

    Clunky Cache Code Conundrum?

    Jim Owen, Jul 3, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    365
    dave wanta
    Jul 3, 2003
  2. Iain
    Replies:
    0
    Views:
    355
  3. Nobody
    Replies:
    6
    Views:
    466
    Hemal Pandya
    Jul 14, 2005
  4. VisionSet

    RMI conundrum

    VisionSet, Dec 23, 2005, in forum: Java
    Replies:
    2
    Views:
    371
    VisionSet
    Jan 2, 2006
  5. VisionSet

    Repost: RMI Conundrum

    VisionSet, Dec 30, 2005, in forum: Java
    Replies:
    4
    Views:
    371
    John C. Bollinger
    Dec 31, 2005
Loading...

Share This Page