Discussion in 'Perl Misc' started by colli, Sep 19, 2007.

  1. colli

    colli Guest

    I need to load one of mine perl template module whose package (which
    is evoked at the head of each module) at the head of the code should
    change to be the same of the name of the module I decided to call.
    Each time I load it I would like to change the name of my module (but
    the template still remain the same)
    It is a default module template but can assume different so
    a different package should be evoked for different module
    name...Instead of MYNAME I would be able to change into MYNAME1 and to
    change dinamically the package.
    Is there a perl function to insert in my module instead of the static
    expression: package MYNAME; ?

    Thank you in advance
    colli, Sep 19, 2007
    1. Advertisements

  2. I'm not sure I understand your question, but chances may be that
    you're after __PACKAGE__.

    Michele Dondi, Sep 19, 2007
    1. Advertisements

  3. colli

    Ben Morrow Guest

    There are various ways you could do this, none of which are for the
    faint of heart :). One simple way would be to put the entire module into
    a string eval: then you can perform any replacements you like on the
    code before evalling it. Another would be to use a source filter. Both
    these approaches would fall foul of the fact that Perl will only load a
    given file once, but that can be got around.

    However, before you do this you should take a step back. What are you
    actually trying to achieve here? Chances are you can do it without
    resorting to rewriting your module on the fly, say by creating a
    'package factory' module that will, on request, create a new package and
    import some functions into it.

    Ben Morrow, Sep 19, 2007
  4. This can be "easily" done with the [email protected] facility.

    Michele Dondi, Sep 19, 2007
  5. colli

    colli Guest

    Thank you very much
    colli, Sep 20, 2007
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.