Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: CGI::Tiny versus undefined parameter/form field

by Polyglot (Chaplain)
on Dec 12, 2022 at 15:16 UTC ( [id://11148786]=note: print w/replies, xml ) Need Help??


in reply to Re: CGI::Tiny versus undefined parameter/form field
in thread CGI::Tiny versus undefined parameter/form field

Thank you. I didn't try that code yet, but I noticed something in it that differed from mine. You have this line...

my $bookparam = $cgi->param('book') || '';

...inside the  cgi { ... } codeblock. I have "$cgi->param()" calls scattered across a multitude of subroutines, as each subroutine needs to deal with a particular set of form inputs. What is to be done if those only work inside that single code block?

This would operate in a way that differed fundamentally from standard CGI. With CGI, I was able to create the "object," then use it throughout the script.

It seems this may be the problem.

Blessings,

~Polyglot~

Replies are listed 'Best First'.
Re^3: CGI::Tiny versus undefined parameter/form field
by pryrt (Abbot) on Dec 12, 2022 at 15:31 UTC
    ...inside the cgi { ... } codeblock. I have "$cgi->param()" calls scattered across a multitude of subroutines

    Per the CGI::Tiny documentation, that $cgi object is only valid inside the cgi { ... } codeblock. "There is no CGI::Tiny object constructor; the object is accessible within the cgi block, only reads request data from the environment once it is accessed, and ensures that a valid response is rendered to avoid gateway errors even in the event of an exception or premature exit." You might be able to rework it so that the code in the cgi {...} block is calling all your subroutines, and you pass the $cgi object as an argument to each of those subroutines, but that may be a lot of refactoring.

    As I said, if you're really looking for a drop-in replacement for CGI.pm, where you can use the $cgi object throughout your code with the same syntax you are used to from CGI.pm, you will likely want to use something like CGI::Simple instead of CGI::Tiny.

Re^3: CGI::Tiny versus undefined parameter/form field
by hippo (Bishop) on Dec 12, 2022 at 16:32 UTC
    This would operate in a way that differed fundamentally from standard CGI.

    Of course. And the documentation goes to some lengths to explain this. Perhaps you have not read it yet?


    🦛

      I do, naturally, have the very same difficulty with understanding abstractions in documentation as I have with them in actual code. I scanned the documentation for parts that I thought I could understand, and did not look closely at the rest. Obviously, I had mistaken the module for being a compatible replacement to CGI. It isn't, and therefore is not suited to my needs.

      It reminds me a little of an AJAX module I once incorporated into my scripts. It worked for awhile, until I discovered it was occasionally doing something unpredictable, and altering my data during transfers--resulting in errors in the database. That's when I learned to program the AJAX for myself, and kicked the module to the proverbial curb, never to be needed again (and those errors have not recurred). I often find the need to do things myself, as what others have done is not compatible. I doubt I am alone in this.

      Blessings,

      ~Polyglot~

Re^3: CGI::Tiny versus undefined parameter/form field
by tybalt89 (Monsignor) on Dec 12, 2022 at 19:09 UTC

    Just put all the calls to those multitude of subroutines inside the cgi block and switch to our :)

    #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11148743 use warnings; use CGI::Tiny; our $cgi; cgi { $cgi = $_; some_sub_somewhere_else(); }; sub some_sub_somewhere_else { my $bookparam = $cgi->param('book') || ''; $cgi->render (text => "bookparam is $bookparam\n"); }

Log In?
Username:
Password:

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

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

    No recent polls found