CGI::Minimal and Cookies

J

John Bokma

From the documentation of CGI::Minimal: "See 'CGI::Cookie' for cookie
generation". Which sounds like a lot of fun, except that CGI::Cookie does:

use CGI;

Which probably makes use CGI::Minimal pointless. Or am I wrong?

How to use Cookies (reading/setting) with CGI::Minimal? I couldn't find a
CGI::Minimal::Cookie module :-( (There is a "thin" module, but a peek at
the code made me shudder...)
 
D

davidfilmer

How to use Cookies (reading/setting) with CGI::Minimal? I couldn't find a
CGI::Minimal::Cookie module :-(

Yeah, I don't think Minimal has cookie support. As I read the docs,
the note about cookies was only in the context of a warning that
Minimal's own date_rfc1123 method is suitable for most HTTP uses
EXCEPT cookies (which have an oddball date format: 'Wdy, DD-Mon-YY
HH:MM:SS GMT'). The docs refer us to CGI::Cookie for cookie
manipulation. Bummer.

However, what is so scary about importing only the cookie method of
CGI?
use CGI qw{ cookie };
 
B

Ben Morrow

Quoth John Bokma said:
From the documentation of CGI::Minimal: "See 'CGI::Cookie' for cookie
generation". Which sounds like a lot of fun, except that CGI::Cookie does:

use CGI;

Which probably makes use CGI::Minimal pointless. Or am I wrong?

Which version? I have 1.26 here, and it doesn't use CGI. It does use
CGI::Util, which contains a group of routines for doing URI-escaping and
such; maybe older versions just used CGI instead, and the code's been
refactored?

Ben
 
X

xhoster

Ben Morrow said:
Which version? I have 1.26 here, and it doesn't use CGI. It does use
CGI::Util, which contains a group of routines for doing URI-escaping and
such; maybe older versions just used CGI instead, and the code's been
refactored?


I see it there, in the next line after the use CGI::Util. Maybe you
deleted use CGI in your local copy? After a quick look through the code, I
expect it would work to omit that line.

http://search.cpan.org/src/LDS/CGI.pm-3.16/CGI/Cookie.pm

$CGI::Cookie::VERSION='1.26';

use CGI::Util qw(rearrange unescape escape);
use CGI;
use overload '""' => \&as_string,
'cmp' => \&compare,
'fallback'=>1;




Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
J

John Bokma

Ben Morrow said:
Which version? I have 1.26 here, and it doesn't use CGI.

I checked the current source at CPAN (1.28) [1].

It looks like (quick search, I might have missed something) that only sub
bake uses it (print CGI::header(....)). If so, loading CGI for just that
looks like major overkill :-(.
It does use
CGI::Util, which contains a group of routines for doing URI-escaping
and such; maybe older versions just used CGI instead, and the code's
been refactored?


[1] http://search.cpan.org/src/LDS/CGI.pm-3.31/CGI/Cookie.pm
 
B

Ben Morrow

Quoth (e-mail address removed):
I see it there, in the next line after the use CGI::Util. Maybe you
deleted use CGI in your local copy?

No, certainly not... :)
Further investigation reveals that line was added in CGI::Cookie 1.27,
in CGI.pm-3.17. I wonder why...

Ben
 
J

John Bokma

Ben Morrow said:
No, certainly not... :)
Further investigation reveals that line was added in CGI::Cookie 1.27,
in CGI.pm-3.17. I wonder why...

On one hand I can understand why: instead of print "Set-Cookie: ..."
print CGI::header(-cookie => ... ); is used, which I consider the
preferred way to do this *if* CGI is already loaded. But OTHO/IMO
CGI::Cookie shouldn't be dependend on such a heavy module if this can be
avoided.


I've contacted Lincoln Stein. If anything comes out of this, I post a
follow-up.
 
X

xhoster

Ben Morrow said:
Quoth (e-mail address removed):

No, certainly not... :)
Further investigation reveals that line was added in CGI::Cookie 1.27,
in CGI.pm-3.17.

It looks like they added it in CGI-3.16, but forgot to update the version
in Cookie, so it still says it is 1.26. Or maybe I don't understand how
these bundle things work.
I wonder why...

It looks like when they added the "bake" method, they made it use a method
from CGI, so added it.

Unfortunately you can't prevent a "use" from happening via subclassing.



Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
J

John Bokma

Unfortunately you can't prevent a "use" from happening via
subclassing.

I've already considered creating a nearly empty CGI.pm, and making sure
it's loaded first >:->.

Anyway, I contacted the author, and hopefully it's fixed in the near
future. It's not that urgent (to me).
 
B

Ben Morrow

Quoth (e-mail address removed):
It looks like they added it in CGI-3.16, but forgot to update the version
in Cookie, so it still says it is 1.26. Or maybe I don't understand how
these bundle things work.

Yes, it does. Bad Lincoln, no cookie. (SCNR)

It's annoying, especially since $cookie->bake is AFAICS equivalent
to $CGI->header(-cookie => $cookie), and the docs for CGI::Cookie state
it can be used independantly.
It looks like when they added the "bake" method, they made it use a method
from CGI, so added it.

Unfortunately you can't prevent a "use" from happening via subclassing.

{
local $INC{'CGI.pm'} = $0;
use CGI::Cookie;
}

perhaps with a

{
package CGI;
use autouse CGI => 'header';
}

as well. Of course, it will break if you call the ->bake method, so
don't do that.

Ben
 
J

John Bokma

Ben Morrow said:
Quoth (e-mail address removed):
<snip: CGI::Cookie uses CGI.pm>

{
local $INC{'CGI.pm'} = $0;
use CGI::Cookie;
}

perhaps with a

{
package CGI;
use autouse CGI => 'header';
}

as well. Of course, it will break if you call the ->bake method, so
don't do that.

Heh, since I bake my cookies via Template::Toolkit (Set-Cookie: ... in (my
own) http_headers.tt), I don't care about that. Thanks for the work-around
suggestions.
 
B

Ben Morrow

Quoth "comp.llang.perl.moderated said:
[Xho wrote:]
Unfortunately you can't prevent a "use" from happening via subclassing.

{
local $INC{'CGI.pm'} = $0;
use CGI::Cookie;
}


Wouldn't that need a BEGIN {} tweak since
'use CGI::Cookie' loads earlier ... ?

Yes, of course. My mistake... :) To still achieve the 'local', it would
need to be

BEGIN {
local $INC{'CGI.pm'} = $0;
require CGI::Cookie;
CGI::Cookie->import(...);
}

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top