palkia has asked for the wisdom of the Perl Monks concerning the following question:

Hello

Not long ago I've installed the Win32::GUI module.
Force-installed to be exact (in case that's the source of the problem (see details).
Not whenever I use Win32::GUI; , along with use warnings; and/or use diagnostics; , it starts the program with the warning:
'use Win32::GUI;' is currently exporting constants into the callers scope. This functionality is deprecated. Use 'use Win32::GUI();' or list your required exports explicitly instead. at C:\Program Files\perl exp\exp22.pl line 7
Line 7 is the line of the use Win32::GUI;
Since I'm still just learning perl, I really have no idea what that warning is trying to say.
Still I followed blindly with the only suggested option I could understand and added '()' after the Win32::GUI and the warning was gone.

But still I wonder:
1. What constants did it talked about and what is the problem with them being exported ?
2. How (syntax) do I and why should I, list my "required exports explicitly" ?
2.1 what are my required exports ? does this refer to vars and/or subs ? or maybe even something else ?
2.2 what if I will/won't, "list my required exports explicitly" (what does it do) ?

Thx

Update:
I believe I understand now.
Thank you both very much :-]

Question resolved.
  • Comment on Strange warning when USEing Win32::GUI module with warnings / diagnostics
  • Download Code

Replies are listed 'Best First'.
Re: Strange warning when USEing Win32::GUI module with warnings / diagnostics
by toolic (Bishop) on Aug 07, 2011 at 02:17 UTC
    The CPAN documentation for Win32::Gui elaborates a little on this warning in the EXPORTS section, including a deprecation schedule for future releases. I have not used this module, but it sounds like you are doing the correct thing by adding the (). According to use:
    If you do not want to call the package's import method (for instance, to stop your namespace from being altered), explicitly supply the empty list
    Regarding your questions...
    1. What constants did it talked about and what is the problem with them being exported ?
    I guess you have to follow the SEE ALSO link inWin32::GUI::Constants to see what constants are used/needed. Generally, you don't want to clutter the namespace with unused constants, variables and functions.
    2. How (syntax) do I and why should I, list my "required exports explicitly" ?
    Generally speaking, the syntax to use is something like (where FOO is the name of a constant):
    use Win32::GUI qw(FOO);
    You should follow the MANIFEST link and look through the scripts in the 'samples' and 't' directories to see if there are specific examples of usage.
Re: Strange warning when USEing Win32::GUI module with warnings / diagnostics
by jethro (Monsignor) on Aug 07, 2011 at 02:42 UTC

    This is a warning of the module itself about a deprecated feature, i.e. it isn't a warning coming from perl. In the source code you can read this comment:

    # use Win32::GUI; currently exports a load of constants for # backwards compatibility with earlier Win32::GUI versions. # This is deprecated, and in the future # use Win32::GUI; and # use Win32::GUI(); will have the same behaviour.

    So the answers to your questions are (as far as I can answer them)

    1) The problem with these constants probably is that modules should not export lots of names because they might clash with variable names in the main script (i.e. the script you are writing). Probably there is already a different mechanism in place to get at these constants easily, a hash maybe?

    2) You can list exports simply by adding them to the parens, i.e. "use Win32::GUI('function1','function2');". The reason is that in that case you know exactly which names are reserved, other names are free to use

    2.1) both vars and subs

    2.2) If you use the empty parens, no name exporting takes place at all and you have to call any function1() in Win32::GUI as Win32::GUI::function1(). If you don't use parens, you get the warning and many functions and constants are included in your namespace