DekGenius.com
[ Team LiB ] Previous Section Next Section

12.11 Custom Import Routines

Let's use CGI.pm as an example of a custom import routine. Not satisfied with the incredible flexibility of the Exporter's import routine, author Lincoln Stein created a special import for the CGI module.[16] If you've ever gawked at the dizzying array of options that can appear after use CGI, it's all a simple matter of programming.

[16] Some have dubbed this the "Lincoln Loader" out of simultaneous deep respect for Lincoln and the sheer terror of having to deal with something that just doesn't work like anything else they've encountered.

As part of the extension provided by this custom import, you can use the CGI module as an object-oriented module:

use CGI;
my $q = CGI->new;         # create a query object
my $f = $q->param("foo"); # get the foo field

or a function-oriented module:

use CGI qw(param);        # import the param function
my $f = param("foo");     # get the foo field

If you don't want to spell out every possible subfunction, bring them all in:

use CGI qw(:all);         # define "param" and 800-gazillion others
my $f = param("foo");

And then there's pragmata available. For example, if you want to disable the normal sticky field handling, simply add -nosticky into the import list:

use CGI qw(-nosticky :all);

If you want to create the start_table and end_table routines, in addition to the others, it's simply:

use CGI qw(-nosticky :all *table);

Truly a dizzying array of options.

    [ Team LiB ] Previous Section Next Section