Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Module questions

by satchboost (Scribe)
on Apr 04, 2001 at 20:12 UTC ( [id://69715]=note: print w/replies, xml ) Need Help??


in reply to Module questions

The previous answer to your fourth question was inaccurate. The reason you have to write use CGI; as well as use CGI::Cookie; is that they are separate packages. PERL doesn't do any sort of inheritance naturally for you, like C++ or JAVA. Within the executable, there is no connection between CGI and CGI::Cookie.

That said, you can get around all of this by clever module design, which is what I suspect the author(s) of CGI did.

Replies are listed 'Best First'.
Re: Re: Module questions
by davorg (Chancellor) on Apr 04, 2001 at 20:24 UTC

    But you don't have to use CGI::Cookie as CGI.pm has the following line of code in its cookie function.

    require CGI::Cookie;

    Is that "clever module design"?

    Oh, and it's "Perl", not "PERL".

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

      The poster asked about mod_perl, so I'll add this:
      If you ARE using mod_perl, then in the mod_perl startup script, you'll want to include both 'use CGI' and 'use CGI::Cookie', as the cookie module does not seem to get included until runtime (after child processes are forked) even when doing 'use CGI qw(-compile :all);'.
      I tried not including CGI::Cookie and only haveing use CGI.

      Unforunately this did not work.

      It seems you have to include both.
        That does not seem correct, I ran this:
        #!/usr/bin/perl -l -w use strict; use CGI qw(:all); print for keys %INC; my $c = cookie('bob'); print "--------"; print for keys %INC;
        And got these results:
        $ ./tst | grep "^[C-]" Carp.pm CGI/Util.pm CGI.pm -------- Carp.pm CGI/Util.pm CGI/Cookie.pm CGI.pm
        So using just 'CGI' SHOULD work and load the CGI::Cookie module when you call the cookie function.
      Fair enough. That is clever module design. I suspect that it's also common module design, but it's not something that a beginner, as the poster indicated s/he was, would think about. In addition, it's listed among the common mistakes someone from C++ would make coming to PERL(!). It's certainly not what I thought about when I first started working on modules.

      And as long as you understood what I was talking about, it could've been peRl, Per1, or PerL. *grins* I don't want to start a flamewar, but that did seem a little nitpicky.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://69715]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-16 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found