Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^4: appending to html at beginning (don't use CGI)

by haukex (Archbishop)
on Feb 03, 2017 at 16:46 UTC ( [id://1180985]=note: print w/replies, xml ) Need Help??


in reply to Re^3: appending to html at beginning ( use CGI for parsing cgi)
in thread appending to html at beginning

Hi Anonymous,

cgi module is best for doing that

Plack, Catalyst, Dancer2, Mojolicious, and more... (Update: As hippo pointed out, CGI::Minimal, CGI::Lite, or CGI::Simple)

- versus -

A module that is no longer recommended by its own documentation, and was removed from Perl's core. I didn't even say the module was summarily bad, just that it shouldn't be recommended for newcomers/new developments.

You're using some strange definitions of "best" and "trolling" ;-P

Regards,
-- Hauke D

  • Comment on Re^4: appending to html at beginning (don't use CGI)

Replies are listed 'Best First'.
Re^5: appending to html at beginning (don't use CGI)
by Corion (Patriarch) on Feb 03, 2017 at 16:48 UTC

    Please - Plack and all the frameworks building on it are a far conceptual step away from CGI programs. If you want people to switch away from hand-parsing CGI parameters, I think it's better to lead them the longer but easier way via CGI.pm than leading them to the cliff that are HTTP frameworks.

      I completely agree with this sentiment. Also, it is not the case that CGI.pm is the only pure CGI game in town. I would recommend one of the smaller modules which does not come with the baggage of HTML-generating code as a better place to start. Take your pick from: CGI::Minimal, CGI::Lite, CGI::Simple or even the old CGI::Thin. Any of these would be a gentler introduction than Plack and will be much faster to run in a traditional CGI environment (of which plenty still exist, BTW).

        Hi hippo,

        Also, it is not the case that CGI.pm is the only pure CGI game in town.

        That's a very good point, and I updated my node accordingly.

        ... and will be much faster to run in a traditional CGI environment

        If you mean speed-wise, you may be right, but if you mean how quickly one can get up and running, I think Plack::Handler::CGI makes that relatively easy:

        #!/usr/bin/env plackup use warnings; use strict; use Plack::Request (); my $app = sub { my $req = Plack::Request->new(shift); # access params via e.g. $req->parameters->{...} ...

        Regards,
        -- Hauke D

      Hi Corion,

      the cliff that are HTTP frameworks

      I see your point, but I have to disagree that all of the alternatives to CGI are so much more "worse". If we are talking about full-blown Catalyst, Dancer2, or Mojolicious apps, then yes, I would tend to agree with you that they might be a little too powerful and the learning curve might be a bit too steep for a newcomer. However, IMO plain Plack and Mojolicious::Lite are quite approachable. If someone learns only one toolbox for writing server-side scripts, I personally don't think CGI should be it, but instead one of the two aforementioned modules.

      Regards,
      -- Hauke D

Re^5: appending to html at beginning (don't use CGI)
by Anonymous Monk on Mar 03, 2017 at 18:48 UTC
    #!/usr/bin/env plackup use strict; use warnings; use Data::Dumper; use Plack::Request; use Plack::Response; my $app = sub { my $req = Plack::Request->new( shift ); my $q = $req->parameters; my $navn = $q->{navn}; my $navn2 = $q->{navn2}; my $adj1 = $q->{adj1}; my $bann1 = $q->{bann1}; my $res = Plack::Response->new( 200 ); $res->body( $readystory ); $res->finalize; };
    VERSUS
    use CGI (); my $q = CGI->new; my $navn = $q->param('navn'); my $navn2 = $q->param('navn2'); my $adj1 = $q->param('adj1'); my $bann1 = $q->param('bann1'); ... print $q->header, $readystory;
    Furthermore:
    vagrant@localhost ~ $ cpanm --notest Plack --> Working on Plack Fetching http://www.cpan.org/authors/id/M/MI/MIYAGAWA/Plack-1.0043.tar +.gz ... OK ==> Found dependencies: File::ShareDir::Install --> Working on File::ShareDir::Install Fetching http://www.cpan.org/authors/id/E/ET/ETHER/File-ShareDir-Insta +ll-0.11.tar.gz ... OK ==> Found dependencies: Module::Build::Tiny --> Working on Module::Build::Tiny Fetching http://www.cpan.org/authors/id/L/LE/LEONT/Module-Build-Tiny-0 +.039.tar.gz ... OK ==> Found dependencies: ExtUtils::Config, ExtUtils::Helpers, ExtUtils: +:InstallPaths --> Working on ExtUtils::Config Fetching http://www.cpan.org/authors/id/L/LE/LEONT/ExtUtils-Config-0.0 +08.tar.gz ... OK Configuring ExtUtils-Config-0.008 ... OK Building ExtUtils-Config-0.008 ... OK Successfully installed ExtUtils-Config-0.008 --> Working on ExtUtils::Helpers Fetching http://www.cpan.org/authors/id/L/LE/LEONT/ExtUtils-Helpers-0. +026.tar.gz ... OK Configuring ExtUtils-Helpers-0.026 ... OK Building ExtUtils-Helpers-0.026 ... OK Successfully installed ExtUtils-Helpers-0.026 --> Working on ExtUtils::InstallPaths Fetching http://www.cpan.org/authors/id/L/LE/LEONT/ExtUtils-InstallPat +hs-0.011.tar.gz ... OK Configuring ExtUtils-InstallPaths-0.011 ... OK Building ExtUtils-InstallPaths-0.011 ... OK Successfully installed ExtUtils-InstallPaths-0.011 Configuring Module-Build-Tiny-0.039 ... OK Building Module-Build-Tiny-0.039 ... OK Successfully installed Module-Build-Tiny-0.039 Configuring File-ShareDir-Install-0.11 ... OK Building File-ShareDir-Install-0.11 ... OK Successfully installed File-ShareDir-Install-0.11 Configuring Plack-1.0043 ... OK ==> Found dependencies: File::ShareDir, Cookie::Baker, Test::TCP, File +sys::Notify::Simple, HTTP::Entity::Parser, Stream::Buffered, Apache:: +LogFormat::Compiler, Devel::StackTrace::AsHTML, Hash::MultiValue, WWW +::Form::UrlEncoded, HTTP::Headers::Fast --> Working on File::ShareDir Fetching http://www.cpan.org/authors/id/R/RE/REHSACK/File-ShareDir-1.1 +02.tar.gz ... OK Configuring File-ShareDir-1.102 ... OK ==> Found dependencies: Class::Inspector --> Working on Class::Inspector Fetching http://www.cpan.org/authors/id/P/PL/PLICEASE/Class-Inspector- +1.31.tar.gz ... OK Configuring Class-Inspector-1.31 ... OK Building Class-Inspector-1.31 ... OK Successfully installed Class-Inspector-1.31 Building File-ShareDir-1.102 ... OK Successfully installed File-ShareDir-1.102 --> Working on Cookie::Baker Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/Cookie-Baker-0.0 +7.tar.gz ... OK Configuring Cookie-Baker-0.07 ... OK Building Cookie-Baker-0.07 ... OK Successfully installed Cookie-Baker-0.07 --> Working on Test::TCP Fetching http://www.cpan.org/authors/id/S/SY/SYOHEX/Test-TCP-2.17.tar. +gz ... OK Configuring Test-TCP-2.17 ... OK ==> Found dependencies: Test::SharedFork --> Working on Test::SharedFork Fetching http://www.cpan.org/authors/id/E/EX/EXODIST/Test-SharedFork-0 +.35.tar.gz ... OK Configuring Test-SharedFork-0.35 ... OK Building Test-SharedFork-0.35 ... OK Successfully installed Test-SharedFork-0.35 Building Test-TCP-2.17 ... OK Successfully installed Test-TCP-2.17 --> Working on Filesys::Notify::Simple Fetching http://www.cpan.org/authors/id/M/MI/MIYAGAWA/Filesys-Notify-S +imple-0.12.tar.gz ... OK Configuring Filesys-Notify-Simple-0.12 ... OK Building Filesys-Notify-Simple-0.12 ... OK Successfully installed Filesys-Notify-Simple-0.12 --> Working on HTTP::Entity::Parser Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/HTTP-Entity-Pars +er-0.19.tar.gz ... OK Configuring HTTP-Entity-Parser-0.19 ... OK ==> Found dependencies: Hash::MultiValue, WWW::Form::UrlEncoded, HTTP: +:MultiPartParser, Stream::Buffered, JSON::MaybeXS --> Working on Hash::MultiValue Fetching http://www.cpan.org/authors/id/A/AR/ARISTOTLE/Hash-MultiValue +-0.16.tar.gz ... OK Configuring Hash-MultiValue-0.16 ... OK Building Hash-MultiValue-0.16 ... OK Successfully installed Hash-MultiValue-0.16 --> Working on WWW::Form::UrlEncoded Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/WWW-Form-UrlEnco +ded-0.24.tar.gz ... OK Configuring WWW-Form-UrlEncoded-0.24 ... OK Building WWW-Form-UrlEncoded-0.24 ... OK Successfully installed WWW-Form-UrlEncoded-0.24 --> Working on HTTP::MultiPartParser Fetching http://www.cpan.org/authors/id/C/CH/CHANSEN/HTTP-MultiPartPar +ser-0.01.tar.gz ... OK Configuring HTTP-MultiPartParser-0.01 ... OK Building HTTP-MultiPartParser-0.01 ... OK Successfully installed HTTP-MultiPartParser-0.01 --> Working on Stream::Buffered Fetching http://www.cpan.org/authors/id/D/DO/DOY/Stream-Buffered-0.03. +tar.gz ... OK Configuring Stream-Buffered-0.03 ... OK Building Stream-Buffered-0.03 ... OK Successfully installed Stream-Buffered-0.03 --> Working on JSON::MaybeXS Fetching http://www.cpan.org/authors/id/E/ET/ETHER/JSON-MaybeXS-1.0030 +09.tar.gz ... OK Configuring JSON-MaybeXS-1.003009 ... OK ==> Found dependencies: Cpanel::JSON::XS --> Working on Cpanel::JSON::XS Fetching http://www.cpan.org/authors/id/R/RU/RURBAN/Cpanel-JSON-XS-3.0 +227.tar.gz ... OK Configuring Cpanel-JSON-XS-3.0227 ... OK Building Cpanel-JSON-XS-3.0227 ... OK Successfully installed Cpanel-JSON-XS-3.0227 Building JSON-MaybeXS-1.003009 ... OK Successfully installed JSON-MaybeXS-1.003009 Building HTTP-Entity-Parser-0.19 ... OK Successfully installed HTTP-Entity-Parser-0.19 --> Working on Apache::LogFormat::Compiler Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/Apache-LogFormat +-Compiler-0.33.tar.gz ... OK Configuring Apache-LogFormat-Compiler-0.33 ... OK ==> Found dependencies: POSIX::strftime::Compiler --> Working on POSIX::strftime::Compiler Fetching http://www.cpan.org/authors/id/K/KA/KAZEBURO/POSIX-strftime-C +ompiler-0.42.tar.gz ... OK Configuring POSIX-strftime-Compiler-0.42 ... OK Building POSIX-strftime-Compiler-0.42 ... OK Successfully installed POSIX-strftime-Compiler-0.42 Building Apache-LogFormat-Compiler-0.33 ... OK Successfully installed Apache-LogFormat-Compiler-0.33 --> Working on Devel::StackTrace::AsHTML Fetching http://www.cpan.org/authors/id/M/MI/MIYAGAWA/Devel-StackTrace +-AsHTML-0.15.tar.gz ... OK Configuring Devel-StackTrace-AsHTML-0.15 ... OK Building Devel-StackTrace-AsHTML-0.15 ... OK Successfully installed Devel-StackTrace-AsHTML-0.15 --> Working on HTTP::Headers::Fast Fetching http://www.cpan.org/authors/id/T/TO/TOKUHIROM/HTTP-Headers-Fa +st-0.21.tar.gz ... OK Configuring HTTP-Headers-Fast-0.21 ... OK Building HTTP-Headers-Fast-0.21 ... OK Successfully installed HTTP-Headers-Fast-0.21 Building Plack-1.0043 ... OK Successfully installed Plack-1.0043 23 distributions installed
Re^5: appending to html at beginning (CGI.pm)
by Anonymous Monk on Feb 04, 2017 at 02:33 UTC

    Plack, Catalyst, Dancer2, Mojolicious, and more...

    All of those run slower then CGI.pm under CGI -- thats because they do a lot more than parse CGI parameters, have more dependencies, have bigger APIs ...

    (Update: As hippo pointed out, CGI::Minimal, CGI::Lite, or CGI::Simple) A module that is no longer recommended by its own documentation, and was removed from Perl's core. I didn't even say the module was summarily bad, just that it shouldn't be recommended for newcomers/new developments.

    By that logic, why would you even mention those other CGI::... modules?

    They were never in the perl core

    and they're just lesser imitations of the CGI.pm module

    You're using some strange definitions of "best" and "trolling" ;-P

    Look, its nice you've got enthusiasm for participation,

    but you should avoid railing against things, esp by copy/paste,

    thats just trolling

    Code over propaganda

      Hi Anonymous,

      By that logic, why would you even mention those other CGI::... modules?

      Simply because they're not deprecated, and don't have substantial portions of their functionality declared unmaintained. I just mentioned the removal from the core to underline that.

      And just in case it isn't clear yet, I have nothing against CGI (the protocol / environment), the point I was making is that CGI.pm (the module) shouldn't be recommended to newcomers or new developments, and that there are better alternatives.

      they're just lesser imitations ... you should avoid railing against things

      Right.

      thats just trolling

      ... says the anonymous post with mild insults and no substantial evidence or arguments.

      Feel free to register an account and build a reputation on which a respectful discussion could be based. Or, continue posting anonymously, but remember that each AM post needs to stand on its own, and each post has to fight a small uphill battle.

      Regards,
      -- Hauke D

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-25 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found