CGI::Minimal and Cookies

Discussion in 'Perl Misc' started by John Bokma, Dec 17, 2007.

  1. John Bokma

    John Bokma Guest

    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...)

    --
    John
     
    John Bokma, Dec 17, 2007
    #1
    1. Advertising

  2. John Bokma

    Guest

    On Dec 17, 3:06 pm, John Bokma <> wrote:
    > 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 };

    --
    David Filmer (http://DavidFilmer.com)
     
    , Dec 17, 2007
    #2
    1. Advertising

  3. John Bokma

    Ben Morrow Guest

    Quoth 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?


    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
     
    Ben Morrow, Dec 18, 2007
    #3
  4. John Bokma

    Guest

    Ben Morrow <> wrote:
    > Quoth 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?

    >
    > 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.
     
    , Dec 18, 2007
    #4
  5. John Bokma

    John Bokma Guest

    Ben Morrow <> wrote:

    > 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

    --
    John

    Arachnids near Coyolillo - part 1
    http://johnbokma.com/mexit/2006/05/04/arachnids-coyolillo-1.html
     
    John Bokma, Dec 18, 2007
    #5
  6. John Bokma

    Ben Morrow Guest

    Quoth :
    > Ben Morrow <> wrote:
    > > Quoth 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?

    > >
    > > 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?


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

    Ben
     
    Ben Morrow, Dec 18, 2007
    #6
  7. John Bokma

    John Bokma Guest

    Ben Morrow <> wrote:

    > 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.

    --
    John

    Arachnids near Coyolillo - part 1
    http://johnbokma.com/mexit/2006/05/04/arachnids-coyolillo-1.html
     
    John Bokma, Dec 18, 2007
    #7
  8. John Bokma

    Guest

    Ben Morrow <> wrote:
    > Quoth :
    > > Ben Morrow <> wrote:
    > > > Quoth 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?
    > > >
    > > > 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?

    >
    > 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.
     
    , Dec 18, 2007
    #8
  9. John Bokma

    John Bokma Guest

    wrote:

    > 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).



    --
    John

    Arachnids near Coyolillo - part 1
    http://johnbokma.com/mexit/2006/05/04/arachnids-coyolillo-1.html
     
    John Bokma, Dec 18, 2007
    #9
  10. John Bokma

    Ben Morrow Guest

    Quoth :
    > Ben Morrow <> wrote:

    <snip: CGI::Cookie uses CGI.pm>
    >
    > 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.

    > > 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.


    {
    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
     
    Ben Morrow, Dec 18, 2007
    #10
  11. John Bokma

    John Bokma Guest

    Ben Morrow <> wrote:

    > Quoth :
    >> Ben Morrow <> wrote:

    > <snip: CGI::Cookie uses CGI.pm>


    >> 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.


    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.

    --
    John

    Arachnids near Coyolillo - part 1
    http://johnbokma.com/mexit/2006/05/04/arachnids-coyolillo-1.html
     
    John Bokma, Dec 18, 2007
    #11
  12. On Dec 18, 10:58 am, Ben Morrow <> 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 ... ?


    > 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.



    --
    Charles DeRykus
     
    comp.llang.perl.moderated, Dec 19, 2007
    #12
  13. John Bokma

    Ben Morrow Guest

    Quoth "comp.llang.perl.moderated" <>:
    > On Dec 18, 10:58 am, Ben Morrow <> wrote:
    > > [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
     
    Ben Morrow, Dec 19, 2007
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,502
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,539
    Fredrik Lindner
    Nov 6, 2003
  3. archana
    Replies:
    1
    Views:
    510
  4. _Who
    Replies:
    7
    Views:
    2,686
  5. Mr I
    Replies:
    13
    Views:
    361
Loading...

Share This Page