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

Note: This post is possibly much more a question about importing modules/packages than it is about CGI.pm.

To use HTML 4.0 standard tags that aren't supported yet by CGI.pm, you can do the following:

use CGI qw(:standard col thead tbody);

So now, the col, thead, and tbody can all be used with CGI.pm. I'd like to know what exactly is happening here. I looked all through CGI.pm and couldn't find any pertinent information. Why does this work? Can someone explain what is going on?

Thanks.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot";
$nysus = $PM . $MCF;

Replies are listed 'Best First'.
Re: CGI.pm: Importing unsupported HTML tags
by nysus (Parson) on Jun 17, 2001 at 22:32 UTC
    Update: OK, I just found out that CGI.pm supports an "any" pragma which allows the creation of 'ad hoc' HTML tags.

    But, I did not use this pragma (called with "-any") in the code above and yet I can still create these 'ad hoc' tags. Any ideas?

    Update to update: OK, it appears that the "-any" pragma is enabled whenever using the ":standard" export tag. When I don't use ":standard", I get an error for an unknown subroutine. According to the CGI.pm documentation, ":standard" in turn calls export tags :html2, :form, and :cgi. I'm guessing it's one of these turns "-any" on. None of this appears to be documented. Does anyone know the ins and outs of all this?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot";
    $nysus = $PM . $MCF;

      Without use CGI qw( -any );, then potential typos in method calls are caught, as in:

      $q= CGI->new(); print $q->threader();
      But you don't have to specify "-any" in order to be able to put any function name matching /^\w+\z/ in the export list to use CGI.

      I guess that it is thought that this one place you can be extra careful to avoid typos for the sake of having easy access to custom HTML tags (especially since you'd then have to make the exact same typo in your code for it to not be caught).

      BTW, this has everything to do with CGI.pm-specific magic and nearly nothing to do with the way that "normal" modules export symbols.

              - tye (but my friends call me "Tye")
(marcink) Re: CGI.pm: Importing unsupported HTML tags
by marcink (Monk) on Jun 17, 2001 at 22:40 UTC
    Short version (I might be wrong, since it's the first time I see this in use):

    The import function calls _setup_symbols, which in turn calls _compile_all that calls _compile for each symbol in 'use' that has no corresponding function already defined. The _compile function does some magic and then calls _make_tag_func which builds "CGI::tagname" for unrecognized tagnames.
    Whew ;-)

    I don't have the time to read through all the details right now, but I like this mechanism. I'll add this to my todo list -- thanks for asking this question.

    -mk