Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^5: How do I go from PROCEDURAL to object oriented programming?

by Anonymous Monk
on Apr 22, 2015 at 16:15 UTC ( [id://1124285]=note: print w/replies, xml ) Need Help??


in reply to Re^4: How do I go from PROCEDURAL to object oriented programming?
in thread How do I go from procedural to object oriented programming?

"Lady_Aleena is writing code to run under CGI, Moose is too slow when run under CGI"

Her code just spits out HTML using methods that she wrote. The only time she actually uses CGI.pm is to gather query params, which is done by instantiating an OBJECT (oh the irony), not by importing into her namespace. She avoids CGI.pm generation methods in favor of her own home rolled ones -- which have a high potential for being more of a bottleneck than Moose under CGI. Moose under CGI is not going to have anywhere near the negative impact you are suggesting on her code. Making your classes immutable can often speed things up, by the way. The suggestion to use Dancer was spot-on.

Really -- what you should be preaching is:

JUST SAY NO TO CGI.pm

  • Comment on Re^5: How do I go from PROCEDURAL to object oriented programming?

Replies are listed 'Best First'.
Re^6: How do I go from procedural to object oriented programming?
by Lady_Aleena (Priest) on Apr 22, 2015 at 18:27 UTC

    Anonymous Monk, using other people's objects is easier than writing them which takes a very different mind set from what I have now. What else should I use for my params if CGI is on its way out? I have not seen any suggested substitutes for CGI's param.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
      I am not the Anonymous Monk that was attacking jeffa for using Moose. Did you know that CGI.pm has been removed from the Perl core? This means that your hosting provider could one day perform a major upgrade that results in you no longer having access to the CGI.pm they provide for you today. Now is the time to find alternatives: CGI::Alternatives.

      Maybe all you need is CGI::Lite.

        Anonymous Monk, I am aware CGI has been removed from the core. If my web host does upgrade, I will first go into shock then second go to work replacing CGI with whichever module is its clear successor. I looked over the alternatives and saw param/params listed in Dancer, but I'm not too clear on how to use Dancer's param.

        CGI::Lite does not seem to have a param option, neither does Plack, which has been mentioned by others in this discussion.

        I am at the ready to change use CGI; to whichever module is the easiest to use. Below are the lines where I use CGI's param. I am at the ready to do a find/replace in the 15 scripts where I use it, if someone would be kind enough to get me started in the right direction.

        use CGI; use CGI::Carp qw(fatalsToBrowser); use HTML::Entities qw(encode_entities); my $cgi = CGI->new; # in Movies/Movie_by_alpha.pl my $year = $cgi->param('year') ? encode_entities($cgi->param('ye +ar'), '<>"') : ''; my $media = $cgi->param('media') ? encode_entities($cgi->param('me +dia'), '<>"') : ''; my $format = $cgi->param('format') ? encode_entities($cgi->param('fo +rmat'), '<>"') : ''; my $genre = $cgi->param('genre') ? encode_entities($cgi->param('ge +nre'), '<>"') : ''; my $basis = $cgi->param('based on') ? encode_entities($cgi->param('ba +sed on'), '<>"') : ''; my $title = $cgi->param('title') ? encode_entities($cgi->param('ti +tle'), '<>"') : ''; # in Movies/Movies_by_genre.pl my $select = encode_entities($cgi->param('genre'),'<>"'); # in Movies/Movies_by_series.pl my $select = encode_entities($cgi->param('series'),'<>"'); # in Role_playing/Magic_items/spell_scrolls.pl my $select = encode_entities($cgi->param('spell scroll'),'<>"'); # in Role_playing/Miscellany/Character_mutations_generator.pl my $iterations = $cgi->param('iterations') ? encode_entities($cgi->par +am('iterations'),'<>"') : 1; # in Role_playing/Miscellany/Word_finds.pl my $select = encode_entities($cgi->param('word find'),'<>"'); # in Role_playing/Monsters/index.pl my $select = $cgi->param('monster') ? encode_entities($cgi->param('mon +ster'),'<>"') : undef; # in Role_playing/Player_characters/Spellbooks.pl my $select = encode_entities($cgi->param('spellbook'),'<>"'); # in Role_playing/Reference_tables/Proficiencies.pl my $alpha = $cgi->param('alpha') ? encode_entities($cgi->param('alph +a'),'<>"') : ''; my @classes = $cgi->param('class') ? $cgi->param('class') : ''; # can' +t encode entities or array won't work. my $slots = $cgi->param('slots') ? encode_entities($cgi->param('slot +s'),'<>"') : ''; my $ability = $cgi->param('rel_ability') ? encode_entities($cgi->param +('rel_ability'),'<>"') : ''; # in Role_playing/Reference_tables/Weapons.pl my $broad = $cgi->param('broad') ? encode_entities($cgi->param('broad' +),'<>"') : ''; my $tight = $cgi->param('tight') ? encode_entities($cgi->param('tight' +),'<>"') : ''; # in working/Twitter/Follower_check.pl my $follower = encode_entities($cgi->param('follower'),'<>"'); my $outreach = encode_entities($cgi->param('outreach'),'<>"'); # in working/Twitter/Tweet_a_message.pl # can't encode entities on arrays since they won't work. my @account_select = $cgi->param('account_select'); my @list_select = $cgi->param('list_select'); my $tweet = encode_entities($cgi->param('tweet'),'<>"'); # in working/Twitter/Twitter_lists_properties.pl my $sort_by = encode_entities($cgi->param('sort'),'<>"'); # in working/Twitter/Twitter_mentions.pl my $select = encode_entities($cgi->param('accounts'),'<>"'); # in working/Twitter/Twitter_people.pl my $select = encode_entities($cgi->param('accounts'),'<>"');

        Update 1: I am doing this now to hopefully get the discussion about procedural to object oriented programming back on track.

        Update 2: I do not know if any of the current CGI alternative modules have a perl version restriction. The perl on my web host is 5.8.8. If any of them require a higher perl, you can skip it.

        No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
        Lady Aleena
Re^6: How do I go from PROCEDURAL to object oriented programming?
by Anonymous Monk on Apr 22, 2015 at 23:16 UTC

    ... the only time she actually uses CGI.pm is to gather query params ...

    Who mentioned CGI.pm?

    I was talking about Common Gateway Interface, the non-persistent execution environment

      You meant something barely anyone uses anymore and no one should use for at least ten years already.

      Using Common Gateway Interface, the non-persistent execution environment, should be considered a misconfiguration.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

      You did. You clearly never mentioned Plack, which is where everyone now is.

        You did. You clearly never mentioned Plack, which is where everyone now is.

        Great argument ... and is everyone there now for free?

        Plack is very much like Dancer/Moose under Common Gateway Interface, just extra overhead

Log In?
Username:
Password:

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

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

    No recent polls found