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

Hello! I am writing a simple authentication module for my web app. Some parts of the app (that is, some CGI scripts) are only for the authenticated users, so that each of them begins a bit like this:
use Auth 'check_auth'; check_auth();
What I want to do is to combine these two lines into one by doing something like this:
use Auth qw(-auth_only);
The Auth module would then know that it should check the authentication cookie immediately. The question is, how do I “detect” the qw(-auth_only) part in the Auth module?

Replies are listed 'Best First'.
Re: Configuring module by import keyword
by moritz (Cardinal) on Sep 03, 2008 at 17:37 UTC
    In your package Auth write a sub called import that does what you want. See also import and perlmod.
      Thank You, that’s it. My import function ended something like this:
      sub import { # … Auth->export_to_level(1, grep { $_ !~ /^-/ } @_); }
      The grepping part ensures that we do not try to export functions that do not really exist (-auth and such are just pragmas, the corresponding functions do not exist).