{"id":304,"date":"2006-09-17T11:34:07","date_gmt":"2006-09-17T15:34:07","guid":{"rendered":"https:\/\/www.goer.org\/wordpress\/hacking_mt_26_or_i_dont_understand_perl"},"modified":"2006-09-17T11:34:07","modified_gmt":"2006-09-17T15:34:07","slug":"hacking_mt_26_or_i_dont_understand_perl","status":"publish","type":"post","link":"https:\/\/www.goer.org\/Journal\/2006\/09\/hacking_mt_26_or_i_dont_understand_perl.html","title":{"rendered":"Hacking MT 2.6; Or, I Don&#8217;t Understand Perl"},"content":{"rendered":"<p>So I&#8217;m trying to make a couple of minor modifications to my Movable Type installation&#8217;s <code>MT::App::Comments<\/code> Perl module, in order to make life a little more difficult for comment spammers. My goal is hampered slightly because I don&#8217;t know a damn thing about Perl.<\/p>\n<p>In fact, the only language I know <em>reasonably<\/em> well is Java. Which means that any time I look at code for Language X, my brain does its best to overlay Java syntax on top of Language X, adding in any bits of Language X that I might have accidentally picked up over the years.<sup><small>[<a href=\"#17-1\">1<\/a>]<\/small><\/sup>  For example, I can read C++, sort of, because Java&#8217;s syntax was designed to be a lot like C++. Except that C++ has all these funny characters sprinkled in: ampersands and asterisks and God knows what else. And when my brain goes down into the depths to retrieve the meaning of these funny characters, it unlocks a door called &#8220;<a href=\"http:\/\/www.cs.hmc.edu\/courses\/mostRecent\/cs5\/\">CS 5<\/a>&#8220;,<sup><small>[<a href=\"#17-2\">2<\/a>]<\/small><\/sup> and I curl up in a fetal ball and start rocking back and forth and moaning, and the only thing that snaps me out of it is hearing my co-worker Jud singing &#8220;The Lunchtime Song.&#8221; Yes, we really have a lunchtime song. Want to make something of it?<\/p>\n<p>Anyway, Movable Type is written in Perl, and the module that handles comments contains several hundred lines of code, some of which looks like:<\/p>\n<pre>if (!$q-&gt;param('text')) {\n    return $app-&gt;handle_error($app-&gt;translate(\"Comment text is required.\"));\n}<\/pre>\n<p>Now, even my poor little Java-addled brain can understand what this means. For starters, I understand &#8220;<code>if<\/code>&#8221; and curly braces. I undertand the &#8220;<code>!<\/code>&#8220;, the &#8220;<code>return<\/code>&#8220;, and the basic idea behind &#8220;<code>handle_error(<var>stuff<\/var>);<\/code>&#8220;. Heck, I even think I understand &#8220;<code>q-&gt;param('text')<\/code>&#8220;! And in fact, if you try to submit a comment and you leave the &#8220;text&#8221; field blank, you do indeed get an error message:<\/p>\n<pre>Comment text is required.<\/pre>\n<p>Try it! It&#8217;s fun!<\/p>\n<p>So as a test of my elite Perl-hacking skills, I changed the snippet above to:<\/p>\n<pre>if (!$q-&gt;param('text')) {\n    return $app-&gt;handle_error($app-&gt;translate(\"Comment text is required<strong>, silly<\/strong>.\"));\n}<\/pre>\n<p>But to my great disappointment, submitting a comment with no text resulted in:<\/p>\n<pre>Comment text is required.<\/pre>\n<p>This could mean one of two things:<\/p>\n<ul>\n<li>The Perl module is cached in memory, and the server is not picking up my change.<\/li>\n<li>The actual error message is specifed somewhere else in the code, and the snippet I was editing is just a red herring.<\/li>\n<\/ul>\n<p>The red herring possibility seems unlikely. First, it would be perverse to create a module named <code>MT::App::Comments<\/code>, have a snippet that <em>appears<\/em> to handle the empty text field error, but actually handle the error somewhere else. I mean, I know the Perl world is whacky and crazy and <a href=\"http:\/\/en.wikipedia.org\/wiki\/There%27s_more_than_one_way_to_do_it\">There&#8217;s! More! Than! One! Way! To Do It!<\/a>, but seriously. Second, I grepped through all of MT&#8217;s Perl code and did not find that particular error string anywhere other than in the <code>Comments.pm<\/code> file.<\/p>\n<p>That leaves us with the caching possibility. To test this, I renamed the <code>Comments.pm<\/code> file, and lo! this completely broke comments. Excellent! Except that when I moved the file back, comment functionality resumed, but the system <em>still<\/em> wasn&#8217;t picking up my changes. So it seems that the system&#8217;s cache does bother to check whether any of its Perl module files have moved, but it doesn&#8217;t bother to waste time checking whether the module contents have actually changed. Perish the thought!<\/p>\n<p>I can understand a caching system that is extremely &#8220;sticky&#8221; &#8212; even if you totally mess with the underlying files, the system doggedly continues to run with whatever it&#8217;s got in memory, until you somehow force the system to re-initialize. And I can understand a caching system that continually monitors the state of its files and obediently re-reads the code if it detects any changes. But the in-between behavior makes no sense. Why would you break if a file is missing, but not bother to read the file again when the file magically reappears? I have a hard time believing that this is actually the case. I must be misunderstanding how Perl is working here. Then again, after encountering the utter stupidity of <code>pod2html<\/code> for Perl 5.8 on Red Hat,<sup><small>[<a href=\"#17-3\">3<\/a>]<\/small><\/sup> I&#8217;m willing to believe anything.<\/p>\n<p><strong>Update:<\/strong> Success! Turns out I was grepping in the wrong place. The hack is now in place. See comments. <\/p>\n<p><small><a name=\"17-1\"><\/a>1. This is sort of like trying to read French by A) looking for words that are very similar in English and B) sprinkling in the thirty-odd actual French words that you dimly remember from high school. Which is, coincidentally, <em>exactly<\/em> how I read French. <em>Quel surprise!<\/em><\/small><\/p>\n<p><small><a name=\"17-2\"><\/a>2. After taking that class, I swore I would never, <strong>ever<\/strong> work for the computer industry. And if I ever <em>had<\/em> to write software, it would only be to do something <em>useful<\/em>, like solving a physics problem.<\/small><\/p>\n<p><small><a name=\"17-3\"><\/a>3. As opposed to <code>pod2html<\/code> for Perl 5.8 on FreeBSD, which basically works okay-ish.<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For example, I can read C++, sort of, because Java&#8217;s syntax was designed to be a lot like C++. Except that C++ has all these funny characters sprinkled in: ampersands and asterisks and God knows what else. And when my brain goes down into the depths to retrieve the meaning of these funny characters, it unlocks a door called &#8220;<a href=\"http:\/\/www.cs.hmc.edu\/courses\/mostRecent\/cs5\/\">CS 5<\/a>&#8220;, and I curl up in a fetal ball and start rocking back and forth and moaning, and the only thing that snaps me out of it is hearing my co-worker Jud singing &#8220;The Lunchtime Song.&#8221; Yes, we really have a lunchtime song. Want to make something of it?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-304","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts\/304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/comments?post=304"}],"version-history":[{"count":0,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/posts\/304\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/media?parent=304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/categories?post=304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.goer.org\/Journal\/wp-json\/wp\/v2\/tags?post=304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}