in reply to Re: Controlling "use" statements
in thread Controlling "use" statements

Thank you, this is very useful. As a followup, what would be the correct way to include certain features with the module?

For example, I want the equivalent of

use CGI::Carp qw(fatalsToBrowser set_message)

I know that

require CGI::Carp qw(...)

won't work, because it can only handle barewords. What is the correct way to do this?

Thanks.

Replies are listed 'Best First'.
Re^3: Controlling "use" statements
by ikegami (Patriarch) on Jun 13, 2007 at 19:50 UTC
    use CGI::Carp qw(fatalsToBrowser set_message)

    is a shortcut for

    BEGIN { require CGI::Carp; import CGI::Carp qw(fatalsToBrowser set_message); }

    You can easily add an if in there.

    BEGIN { if ($DEBUG) { require CGI::Carp; import CGI::Carp qw(fatalsToBrowser set_message); } }
Re^3: Controlling "use" statements
by shmem (Chancellor) on Jun 13, 2007 at 19:44 UTC
    BEGIN { use vars qw($devel); $devel = 0; # production } BEGIN { my @args = $devel ? qw(fatalsToBrowser set_message) : (); require CGI::Carp; CGI::Carp->import(@args); }

    The equivalent of use Module LIST is BEGIN { require Module; Module->import(LIST) }.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}