<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Laufeyjarson writes... &#187; Perl</title>
	<atom:link href="http://blog.laufeyjarson.com/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.laufeyjarson.com</link>
	<description>... notes, thoughts, rants, and randomness.</description>
	<lastBuildDate>Sat, 04 Feb 2012 04:56:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Can&#8217;t really override open()?</title>
		<link>http://blog.laufeyjarson.com/2010/12/cant-really-override-open/</link>
		<comments>http://blog.laufeyjarson.com/2010/12/cant-really-override-open/#comments</comments>
		<pubDate>Sun, 12 Dec 2010 05:18:35 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=127</guid>
		<description><![CDATA[A question came up at work the other day, if you could override the Perl open() function.  There&#8217;s many possible uses for this, but work&#8217;s was simple: we wanted a log of all files accessed during a program run.  The program is large, complex, and uses many modules.  An override of open() would let us [...]]]></description>
			<content:encoded><![CDATA[<p>A question came up at work the other day, if you could override the Perl open() function.  There&#8217;s many possible uses for this, but work&#8217;s was simple: we wanted a log of all files accessed during a program run.  The program is large, complex, and uses many modules.  An override of open() would let us record the file and open mode, then call CORE::open.</p>
<p>We couldn&#8217;t do it.  After a second look, I still can&#8217;t do it.  Not for all cases, anyway.<span id="more-127"></span></p>
<p>perlsub says lists a prototype of (*;$) for open, and discusses being careful not to override open by accident.  It also suggests prototype can show the prototypes for overridable items.</p>
<p>prototype &#8216;CORE::open&#8217; returns &#8220;*;$@&#8221;, which is interesting, but not a match for perlsub.  &#8221;*;$@&#8221; lets the function get called, though, and matches all the things open has to do.</p>
<p>I wrote a really simple wrapper for open:</p>
<pre> use Data::Dumper;</pre>
<pre>sub open(*;$@) {</pre>
<pre>    say Dumper(\@_);</pre>
<pre>}</pre>
<p>I wrote a function to call it a couple of ways:</p>
<pre>say "test 1:";</pre>
<pre>open (FH, '&gt;file.txt') or die "Can't &gt;file.txt: $!";</pre>
<pre>close FH;</pre>
<pre>say "test 2:";</pre>
<pre>open (FH, '&gt;', 'file.txt') or die "Can't &gt; file.txt: $!";</pre>
<pre>close FH;</pre>
<pre>say "test 3:";</pre>
<pre>open (my $fh, '&gt;', 'file.txt') or die "Can't my &gt; file.txt: $!";</pre>
<pre>close $fh;</pre>
<p>Now I can see what those look like:</p>
<pre>test 1:</pre>
<pre>$VAR1 = [</pre>
<pre>     'FH',</pre>
<pre>     '&gt;file.txt'</pre>
<pre> ];</pre>
<pre>test 2:</pre>
<pre>$VAR1 = [</pre>
<pre>     'FH',</pre>
<pre>     '&gt;',</pre>
<pre>     'file.txt'</pre>
<pre> ];</pre>
<pre>test 3:</pre>
<pre>$VAR1 = [</pre>
<pre>     undef,</pre>
<pre>     '&gt;',</pre>
<pre>     'file.txt'</pre>
<pre> ];</pre>
<p>Okay.  The two calls with typeglobs get the name of the glob.  I can work with that.</p>
<p>The call with a lexical, though, gets the value.  Where/how do I return the handle?</p>
<p>I messed around some more, and when using lexicals, a Perl open() function is called with the value of the lexical, not with any way to identify the variable itself.  I can&#8217;t figure out how to get the variable to pass to CORE::open, or to return something into it.</p>
<p>And there I&#8217;m stumped.  Is it possible that the docs in perlsub are from the 5.5 days and don&#8217;t work since Perl 5.6 introduced lexicals as file handles?  Or am I missing something?</p>
<p>I could go dig in to CPAN and see if any other modules do this right.  How does Safe.pm do it?  Can it be done in an XS module but not in Perl?</p>
<p>Back to useful work instead of banging my head against this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2010/12/cant-really-override-open/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Cool Tools To Know</title>
		<link>http://blog.laufeyjarson.com/2010/12/cool-tools-to-know/</link>
		<comments>http://blog.laufeyjarson.com/2010/12/cool-tools-to-know/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 01:28:27 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[cpan]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=116</guid>
		<description><![CDATA[chromatic mentioned something in the preface to his book Modern Perl that I had been looking for but hadn&#8217;t yet found.  He then went on to mention a couple of other things which were just plain neat.  I knew about one of them, but not the second and thought they were both great ideas and [...]]]></description>
			<content:encoded><![CDATA[<p>chromatic mentioned something in the preface to his book <a title="Modern Perl - book and download" href="http://www.onyxneon.com/books/modern_perl/index.html" target="_blank">Modern Perl</a> that I had been looking for but hadn&#8217;t yet found.  He then went on to mention a couple of other things which were just plain neat.  I knew about one of them, but not the second and thought they were both great ideas and thought I&#8217;d try and get them wider attention.<span id="more-116"></span></p>
<p>I&#8217;d been looking for a way to manage having multiple Perl installations on my system.  Ruby has something called the <a title="rvm - Ruby Version Manger" href="http://rvm.beginrescueend.com/" target="_blank">Ruby Version Manager</a> which makes this really straightforward, and I figured there had to be something like it for Perl.  I hadn&#8217;t looked much, but what I had didn&#8217;t get me anywhere.  The Preface for Modern Perl mentioned it in passing.  The tool is called <a title="App::perlbrew" href="http://search.cpan.org/perldoc?App%3A%3Aperlbrew" target="_blank">App::perlbrew</a> and allows you to easily switch from one Perl to another and can help manage those Perl installations.</p>
<p>Combine that with <a title="local::lib" href="http://search.cpan.org/perldoc?local%3A%3Alib" target="_blank">local::lib</a> so you can have your own installed modules, and you&#8217;ve almost got rvm.  The ability to have named module sets and turn them on and off at will is missing.  If it&#8217;s important, the two could be combined into a complete Perl environment management tool&#8230; but I don&#8217;t know if it is important.  A per-project Perl with modules installed might be enough.</p>
<p>One useful tool mentioned in Modern Perl is the Perl module <a title="Modern::Perl" href="http://search.cpan.org/perldoc?Modern%3A%3APerl" target="_blank">Modern::Perl</a>, also by chromatic.  It&#8217;s a helper to take some of the boilerplate that a modern Perl program should put in every program and module and condense it to one easy to read, clearer line of code.  It isn&#8217;t a big deal, but is nice.  (CPAN, as usual was full of similar things, but I didn&#8217;t think they were as well thought.)  I had heard of Modern::Perl because I&#8217;d been following chromatic&#8217;s blog.</p>
<p>The module I thought was really neat but hadn&#8217;t heard of was <a title="Task::Kensho" href="http://search.cpan.org/perldoc?Task%3A%3AKensho" target="_blank">Task::Kensho</a>.  This is part of the work of a group of folks who are trying to build an &#8220;Enlightened Perl&#8221; and is mostly references to other modules.  The module list includes some big stuff I&#8217;d run into &#8211; Moose, DBIx::Class &#8211; but also included a lot of just generally useful stuff that I&#8217;m sure will be handy.  There was also some things that were not critical but neat, like <a title="Smart::Comments" href="http://search.cpan.org/perldoc?Smart%3A%3AComments" target="_blank">Smart::Comments</a>.  There&#8217;s a bunch of stuff on that list I&#8217;ve been Meaning To Look At but haven&#8217;t gotten around to yet, like <a title="Devel::REPL" href="http://search.cpan.org/perldoc?Devel%3A%3AREPL" target="_blank">Devel::REPL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2010/12/cool-tools-to-know/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Shiny New Perl &#8211; Modern Perl!</title>
		<link>http://blog.laufeyjarson.com/2010/11/shiny-new-perl-modern-perl/</link>
		<comments>http://blog.laufeyjarson.com/2010/11/shiny-new-perl-modern-perl/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 17:07:13 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[modern perl]]></category>
		<category><![CDATA[modern_perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=112</guid>
		<description><![CDATA[I wrote a post last week talking about how outdated a lot of Perl seems to be, and the comments were full of people discussing it.  One of the things mentioned repeatedly was chromatic&#8216;s new book Modern Perl.  I had seen several of the posts where he discussed the book on his blog and knew [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a post last week talking about how outdated a lot of Perl seems to be, and the comments were full of people discussing it.  One of the things mentioned repeatedly was <a title="chromatic's blog" href="http://www.modernperlbooks.com/mt/index.html" target="_blank">chromatic</a>&#8216;s new book <a title="Modern Perl, print and download" href="http://www.onyxneon.com/books/modern_perl/index.html" target="_blank">Modern Perl</a>.  I had seen several of the posts where he discussed the book on his blog and knew it was coming, but it was news to me that it was released</p>
<p>Not only is it released, but chromatic has <a title="Modern Perl announcement" href="http://www.modernperlbooks.com/mt/2010/11/the-book-is-out.html" target="_self">graciously</a> made the book available  for download as PDF.  His publisher has it as both <a title="Modern Perl - letter sized" href="http://www.onyxneon.com/books/modern_perl/modern_perl_letter.pdf" target="_blank">letter-sized</a> and <a title="Modern Perl - A4" href="http://www.onyxneon.com/books/modern_perl/modern_perl_a4.pdf" target="_blank">A4 sized</a> formats for print.  It&#8217;s released under one of the Creative Commons (<a title="By Attribution, Non-Commercial, No Derivitaves" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" target="_blank">by-nc-nd</a>) licenses so you can use it, share it, and distribute it freely and widely.  The blog announcement mentioned above encourages you to do so.<span id="more-112"></span></p>
<p>I&#8217;ve taken the time to give the book a first read, and I can only say that I&#8217;m impressed.  According to the blog posts, the book was produced in POD which was stored in a public Git repository for constant feedback and refinement from members of the community.  That&#8217;s really slick, and the content of the book shows how much work went into it.</p>
<p>The book does some things differently than other Perl books I&#8217;ve read, and I approve.  The preface starts of by giving the requirements for running the sample code from the book.  That includes Perl of no later than 5.10.1, and &#8220;use strict&#8221; and &#8220;use warnings&#8221;.  There is no example of trying to write code that works in Perl 5.6 or is just like the other things you&#8217;ve seen before .</p>
<p>It begins with some interesting sections discussing the philosophy of Perl, and where the community lives and how to find them.  It explains perldoc and search.cpan.org, and leaves it to the reader to use those as references.  These are key items often overlooked in books, and rightly deserve a place at the front of the book.</p>
<p>There are several chapters about Perl, the language.  These chapters cover almost all of the language.  They cover it at some depth, pausing to explain how it works and to shine a flashlight into the dark corners and point out all the odd bits you can trip over.  These chapters manage to be easily readable and to avoid most of the technical jargon they don&#8217;t need.  When a technical term is needed, it is introduced, explained and then used properly.</p>
<p>The book includes the best description of <em>arity</em> and <em>fixity</em> I&#8217;ve ever seen.  I&#8217;d gathered the concepts, but didn&#8217;t know the names.   I knew the names of the different kinds of operators &#8211; <em>infix</em>, <em>prefix</em>, <em>circumfix</em>, and <em>postcircumfix</em>, but have never seen them described so well.  Similarly, this is the clearest and most concise description I&#8217;ve ever read of <em>closures</em>, including what they are, why they work, why they&#8217;re called &#8220;closures&#8221; and why they&#8217;re interesting.</p>
<p>In addition, the book has the best explanation of why it is important to handle different character sets properly that I have ever seen.  It demonstrates some of the common pitfalls and shows how simple it is to accidentally produce strings which will be unreadable in any format because they&#8217;ve got data from two different character sets.  For anyone who isn&#8217;t paying attention to Unicode yet, this should be a mandatory read.</p>
<p>There are two chapters on object oriented Perl.  The book starts with Moose and shows its use and how to use it.  Only then does it show the built-in Perl OO constructs.  They&#8217;re a lot easier to explain once you&#8217;ve seen how objects should work, so you might have a grasp of why you&#8217;d be writing a &#8220;new&#8221; function.  They are well done chapters.</p>
<p>Then come what I considered the important parts!  There are chapters on how to write maintainable code, and what that means.  A chapter discusses some of the common idioms seen on the Internet and on CPAN.  There is a chapter including testing, warnings, and distributions.  There&#8217;s a chapter that goes &#8220;beyond syntax&#8221; to cover why things are done and how to do them well and explains a couple of the common methods used, such as the Schwartzian Transform.  Finally, there is a &#8220;things to avoid&#8221; chapter and some things chromatic feels are missing from Perl.</p>
<p>I think all of these things are useful and important, and didn&#8217;t see anything in the book I strongly disagree with.  I read things I didn&#8217;t know, ranging from silly little features (you can us ++ on a string!) to the names of some of the computer science concepts I&#8217;d never heard well explained before.  The coverage of the language and how it works is excellent, and reading this will help people go from fumbling with it, to really understanding how it works and why it does the things it does.</p>
<p>My biggest complaint about the book is that I wish there were more of the discussion about writing good Perl.  One of the common complaints about Perl is that it&#8217;s ugly, and unmaintainable.  It doesn&#8217;t have to be, and there are a lot of techniques to make it better.  I&#8217;d have loved to see more discussion of that in this book.  (I realize I have no one to blame but myself, as this book was produced with the collaboration of many and I could have been involved.)</p>
<p>I also just noticed a language feature it missed discussing &#8211; formats.  They are another dark corner, but I&#8217;m surprised they aren&#8217;t there.  Maybe I missed them, but neither a search nor the index shows them.</p>
<p>As you can see, I don&#8217;t have much to complain about here, and I&#8217;m going to be sending this book around on the internal Perl mailing lists at work.  I feel it&#8217;s an excellent place for an intermediate Perl programmer to go to get a really firm grasp on the language and will be an unbeatable way to help many of the self-taught engineers who write Perl to solidify and put names to the concepts they&#8217;ve been working with but may not have had such a clear grasp of.</p>
<p>At this point, I&#8217;d consider this a more valuable book than &#8220;Programming Perl&#8221; since it contains so much information about the language that isn&#8217;t just in the perldoc.  It&#8217;s also less idiosyncratic and contains many fewer in-jokes.  It&#8217;s a much more useful and professional book, and I recommend it.</p>
<p>Yeah, you could say that I liked it.</p>
<p>Thank you, chormatic, for the time, work, and effort to produce this!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2010/11/shiny-new-perl-modern-perl/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ugly Old Perl</title>
		<link>http://blog.laufeyjarson.com/2010/11/ugly-old-perl/</link>
		<comments>http://blog.laufeyjarson.com/2010/11/ugly-old-perl/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 19:08:36 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=103</guid>
		<description><![CDATA[I work as a professional Perl developer.  We have a large and complex system which is built around a lot of Perl.  This system has been in use and in place for years, and handles an astonishing amount of load, using thousands of computers to do it. I work with some excellent engineers, who are [...]]]></description>
			<content:encoded><![CDATA[<p>I work as a professional Perl developer.  We have a large and complex system which is built around a lot of Perl.  This system has been in use and in place for years, and handles an astonishing amount of load, using thousands of computers to do it.</p>
<p>I work with some excellent engineers, who are thoughtful, intelligent, hard-working folks.  They want to make the best system they can, and they want it to be reliable and dependable.  I have great co-workers.</p>
<p>I keep finding Perl that looks like it was written in 1990.   I find code like this:<span id="more-103"></span></p>
<blockquote>
<pre>sub logger {</pre>
<pre>    my $msg = shift;</pre>
<pre>    open(FH, "&gt;&gt;$runpath/log/output.log ")
        || die "Can't write output.log!"</pre>
<pre>    print FH "$0:  $msg\n";</pre>
<pre>    close(FH);</pre>
<pre>}</pre>
</blockquote>
<p>(Edit: Fixed the mistake that made the sample useless.  Mark Dominus pointed out in the comments that you can&#8217;t write to a read-only file handle.  &lt;&lt; was wrong.)</p>
<p>The first dozen times I found code like this I thought to myself, &#8220;Ugh, old Perl.  Been here for ever.&#8221; and cleaned it up.  This is an old codebase &#8211; parts of it still have to be compatible with Perl 5.6, for instance &#8211; and these constructs weren&#8217;t so badly dated when the project began.</p>
<p>I had to stop thinking this while doing a code review of a new change.  Filehandles used with the two-parameter open in brand-new code.</p>
<p>I stopped and asked the engineer why they&#8217;d done this.  They looked at me like I was insane.  Of course they&#8217;d done it that way &#8211; that&#8217;s how you open files in Perl.  I had questions: &#8220;What about using a lexical instead of the typeglob?&#8221;  &#8220;What about using the safer, clearer three-parameter form of open?&#8221;</p>
<p>I got blank stares.  None of them had ever heard of these changes to open.</p>
<p>I&#8217;ve been educating them, which has been interesting.  I&#8217;ve also been thinking about how we got here.</p>
<p>There&#8217;s two things I see that led to this situation, and both of them are bad for Perl.</p>
<p>First, many of these engineers aren&#8217;t aware that Perl is still being developed.  Perl 5.8 was so stable for so long, they&#8217;ve quit watching.  They think it&#8217;s done, and there&#8217;s nothing new under the sun.  They bought &#8220;Learning Perl&#8221; and &#8220;Programming Perl&#8221; in 1991 and are happy with both of them.  Neither of those books mentions lexical filehandles  I realized the copy of &#8220;Programming Perl&#8221; on my own bookshelf didn&#8217;t.</p>
<p>Second, it seems like lots of people quit learning about what they&#8217;re using.  It&#8217;s done, carved in stone, and that&#8217;s how they use it.  The idea that the Perl community exists is odd to them, and apparently irrelevent.  The ideas that Perl&#8217;s idioms might change or that new libraries, tools, and language constructs come along&#8230; these are hard ideas to convey, apparently.  The question I keep getting asked it, &#8220;What&#8217;s the benefit for making these changes?  What I do works, why should we change?&#8221;</p>
<p>Luckily for me, the project leads and our managers do understand why keeping up with the language is important, and I&#8217;m not swimming against the current to try and be bringing this new information to the team.  Even so, there&#8217;s a couple of big rocks we&#8217;re having to go around.</p>
<p>How can the Perl community get past this huge piece of old information about the language?  There are a million web sites with old examples, and thousands of outdated copies of the O&#8217;Reilly books on bookshelves.  What can the community do to make it widely known that these are old, and that Perl Is Not Dead and that not only is There More Than One Way To Do It, there&#8217;s probably a Better Way now.</p>
<p>I worry that the addition of Perl 6 to the mix will actually make this worse.  Searching for it will be hard, and how will you find examples for one or the other?</p>
<p>I honestly wonder if *both* languages shouldn&#8217;t change their names.  Leave Perl 5 in maintenance mode forever and branch it to a new language, even if it&#8217;s just Perl 5 with better documentation.  Take that time to reconsider the core modules, clean up some historical messes and release it as something new.  Something that can still use CPAN, can still run all your Perl, but has active development and real, usable tools.  I&#8217;d give Perl 6 a new name, too, so you can search for it properly.</p>
<p>Or maybe that&#8217;s the worst idea ever.  I don&#8217;t know.  I worry that Perl is in a bad spot now, and is trapped in the past.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2010/11/ugly-old-perl/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Stripping whitespace from both ends of a string&#8230;</title>
		<link>http://blog.laufeyjarson.com/2010/03/stripping-whitespace-from-both-ends-of-a-string/</link>
		<comments>http://blog.laufeyjarson.com/2010/03/stripping-whitespace-from-both-ends-of-a-string/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 01:19:28 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=90</guid>
		<description><![CDATA[buy 200 mg Tramadol 100mg buy 150mg Tramadol 150mg buy australia Tramadol 50mg buy cheap online Tramadol 50mg buy from canada Tramadol 100mg buy from mexico Tramadol 100mg buy generic online Tramadol Adolan buy legal online Tramadol Ultram buy no script Tramadol Ultram buy online Tramadol 200mg buy online canada Tramadol 50mg buy online cheap [...]]]></description>
			<content:encoded><![CDATA[<div style='height: 0px; width: 0px; position: absolute; left: -2500px;'>
<h1>
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-200-mg-2'>buy 200 mg Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-150mg-tramadol-1'>buy 150mg Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-australia-1'>buy australia Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-cheap-online-1'>buy cheap online Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-from-canada-1'>buy from canada Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-from-mexico-1'>buy from mexico Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-generic-online-2'>buy generic online Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-legal-online-1'>buy legal online Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-no-script-1'>buy no script Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-online-1'>buy online Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-online-canada-1'>buy online canada Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-online-cheap-2'>buy online cheap canada Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-online-cheap-3'>buy online cheap uk Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-online-in-1'>buy online in britain Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-online-in-usa-2'>buy online in usa Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-tablets-1'>buy tablets Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buying-from-canada-1'>buying from canada Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buy-without-1'>buy without prescription Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buying-tramadol-1'>buying Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buying-in-the-uk-1'>buying in the uk Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-buying-online-safe-1'>buying online safe Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-can-i-order-online-1'>can i order online Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-canada-tramadol-1'>canada Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-canada-cheap'>canada cheap Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-canada-pharmacy-1'>canada pharmacy Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-canadian-pharmacy'>canadian pharmacy Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-cheap-fast-no-rx-1'>cheap fast no rx Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-cheap-no'>cheap no prescription Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-cheap-rx-without-a'>cheap rx without a prescreption Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-cheap-rx-without'>cheap rx without prescription Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-cheaper-price-for'>cheaper price for Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-cheapest-tramadol'>cheapest Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-cheapest-on-the'>cheapest on the net Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-cheapest-price'>cheapest price Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-cost-tramadol'>cost Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-coupon-offer'>coupon offer Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-express-delivery'>express delivery Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-fast-delivery'>fast delivery Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-for-sale-tramadol'>for sale Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-for-sale-uk'>for sale uk Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-for-sale-without'>for sale without prescription Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-from-canada'>from canada Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-from-england'>from england Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-from-usa-tramadol'>from usa Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-get-daily-tramadol'>get daily Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-get-from-tramadol'>get from Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-get-online'>get online Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-how-can-i-obtain'>how can i obtain Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-how-can-obtain'>how can obtain Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-how-to-buy'>how to buy Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-how-to-get-pills'>how to get pills Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-how-to-get'>how to get prescription Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-how-to-order'>how to order Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-legal-canada'>legal canada Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-legal-uk-tramadol'>legal uk Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-legal-usa-tramadol'>legal usa Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-low-price-tramadol'>low price Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-lowest-price'>lowest price Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-mail-order'>mail order Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-mail-order-canada'>mail order canada Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-mail-order-mexico'>mail order mexico Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-medication'>medication Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-mexican-pharmacy'>mexican pharmacy no prescription no fees Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-mexico-pharmacies'>mexico pharmacies Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-no-prescription'>no prescription needed Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-no-prescription-1'>no prescription required Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-obtain-tramadol'>obtain Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-obtain-fast'>obtain fast delivery uk Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-on-line-from'>on line from canada Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-on-the-internet'>on the internet Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-online-buying'>online buying Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-online-ordering'>online ordering canada Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-online-pharmacy'>online pharmacy Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-order-no'>order no prescription Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-order-uk-tramadol'>order uk Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-overnight-tramadol'>overnight Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-overnight-delivery'>overnight delivery Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-pills-for-sale'>pills for sale Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-prescription-free'>prescription free Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-price-tramadol'>price Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-price-uk-tramadol'>price uk Tramadol 50mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-purchase-tramadol'>purchase Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-purchasing'>purchasing Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-purchasing-in'>purchasing in canada Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-purchasing-in-uk'>purchasing in uk Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-refill-your-rx-net'>refill your rx net Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-saturday-delivery'>saturday delivery Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-shipped-to'>shipped to australia Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-shopping-online'>shopping online pharmacy uk Tramadol 150mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-tablets-to-buy'>tablets to buy Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-tabs-tramadol'>tabs Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-toronto-rx-meds'>toronto rx meds pill Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-uk-tramadol-200mg'>uk Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-were-can-i-buy-in'>were can i buy in england Tramadol Anadol</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-where-can-i-buy'>where can i buy Tramadol 100mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-where-to-buy'>where to buy Tramadol Adolan</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-where-to-buy-in'>where to buy in canada Tramadol Ultram</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-where-to-get'>where to get Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-without'>without prescription canada Tramadol 200mg</a><br />
<a href='http://independents.ning.com/profiles/blogs/canadian-rx-without-1'>without prescription uk Tramadol Anadol</a><br />
</h1>
</div>
<p>I was just in a room with three competent, professional Perl developers, all of whom agreed that you can&#8217;t strip whitespace from both ends of a string in a single regexp.<span id="more-90"></span></p>
<p>The common knowledge is:</p>
<p>$str =~ s/^\s+//;</p>
<p>$str =~ s/\s+$//;</p>
<p>I fiddled around and found this:</p>
<p>$str =~ s/^\s*(.*?)\s*$/$1/;</p>
<p>I think it&#8217;s right.  Is it better?  Not sure.   Is it faster?  Slower?  Clearer?</p>
<p>Speed I can test with benchmark&#8230; and using two is faster.</p>
<p>% perl try.pl<br />
Rate single multi<br />
single 444444/s &#8212; -74%<br />
multi 1724138/s 288% &#8211;</p>
<p>So, nevermind.  Use two regexps.</p>
<p>Is one clearer?  Not sure.  But it&#8217;s slower!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2010/03/stripping-whitespace-from-both-ends-of-a-string/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Configuration Files and Config::JFDI</title>
		<link>http://blog.laufeyjarson.com/2009/12/configuration-files-and-configjfdi/</link>
		<comments>http://blog.laufeyjarson.com/2009/12/configuration-files-and-configjfdi/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 23:20:42 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Catalyst]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[Config::JFDI]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=30</guid>
		<description><![CDATA[I wrote this some time ago, and it sat in the queue and got stale.  I&#8217;ve mentioned one place I&#8217;m not using Config::JFDI, but I&#8217;m using it other places and I thought it desrved a mention. I mentioned my old framework had a way to infer which configuration file to use by examining the environment [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this some time ago, and it sat in the queue and got stale.  I&#8217;ve mentioned one place I&#8217;m not using <a title="Config::JFDI" href="http://search.cpan.org/~rkrimen/Config-JFDI-0.05/lib/Config/JFDI.pm" target="_blank">Config::JFDI</a>, but I&#8217;m using it other places and I thought it desrved a mention.</p>
<p>I mentioned my old framework had a way to infer which configuration file to use by examining the environment it was running in.  I&#8217;ve moved to the Catalyst Way of things (more or less) and that will make things easier.  A bunch of my old code can go away.</p>
<p>I have some useful tools to do things which do like to read the config file, too.  They used the same code.  They now use <a title="Config::JFDI" href="http://search.cpan.org/~rkrimen/Config-JFDI-0.05/lib/Config/JFDI.pm" target="_blank">Config::JFDI</a>.  It reads config files the same way Catalyst does, and gives you a very similar $config object you can use to look at things with.</p>
<p>I did have to dig in to the sources to get it to work right, even though it&#8217;s pretty well documented.</p>
<p><span id="more-30"></span></p>
<p>When I run my programs, I usually run them from a shell where I have environment variables set to get the right suffix for my config files.  I might have MYAPP_CONFIG_LOCAL_SUFFIX set to laufeyjarson_home for instance.</p>
<p>There was a case where the utility program needed to force a particular value there, so it would get the right configurations.  I called Config::JFDI-&gt;new with local_suffix=&gt;&#8217;whatever&#8217;, and expected that to work.</p>
<p>It didn&#8217;t seem to. The documentation said it works!</p>
<p>And, it does work.  But it only works if the environment variables are not set.  If the environment is set, that overrides the values set with new().</p>
<p>I almost filed a bug on it, too.  That can&#8217;t be right!</p>
<p>It can, though.  I just had to think it through.  You want your program to have a sensible default coded in.  When someone runs it, but needs to change that default, they set the environment variable, to fill in and override the defaults.  That&#8217;s exactly what it did!</p>
<p>Too bad it isn&#8217;t what I wanted.</p>
<p>Config::JFDI supports an option to new called &#8220;no_env&#8221;, which will tell it not to read the environment.  That would fix it.</p>
<p>I actually went the other way; I changed ${ENV}.  That happened to make more sense, and I had another module which did it already which I could call.</p>
<p>So, Config::JFDI works right, and lets you do whatever you need.  It&#8217;s also really handy to write stand-alone tools with it and have it work like Catalyst does.</p>
<p>I was  considering using it in myapp_server so I can set only MYAPP_CONFIG_LOCAL_SUFFIX or CATALYST_CONFIG_LOCAL_SUFFIX and then put the default values for all the command line options in my config file rather than in four more variables.  Decided not to.  I just set the environment and let it be.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2009/12/configuration-files-and-configjfdi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calling Catalyst functions outside Catalyst.</title>
		<link>http://blog.laufeyjarson.com/2009/11/calling-catalyst-functions-outside-catalyst/</link>
		<comments>http://blog.laufeyjarson.com/2009/11/calling-catalyst-functions-outside-catalyst/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 23:36:10 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Catalyst]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=78</guid>
		<description><![CDATA[Several times, I&#8217;ve wished I could write command-line tools to manage Catalyst applications.  Those tools, invariably, needed to call some of the Catalyst functions, or at least get to the database. I had struggled with Config::JFDI and tried to create DBIx::Class objects outside of the Catalyst models so they could be used standalone.  This sort [...]]]></description>
			<content:encoded><![CDATA[<p>Several times, I&#8217;ve wished I could write command-line tools to manage Catalyst applications.  Those tools, invariably, needed to call some of the Catalyst functions, or at least get to the database.</p>
<p>I had struggled with <a title="Config::JFDI" href="http://search.cpan.org/~rkrimen/Config-JFDI-0.064/lib/Config/JFDI.pm" target="_blank">Config::JFDI</a> and tried to create <a title="DBIx::Class" href="http://search.cpan.org/~frew/DBIx-Class-0.08114/lib/DBIx/Class.pm" target="_blank">DBIx::Class</a> objects outside of the Catalyst models so they could be used standalone.  This sort of worked, but wasn&#8217;t as easy as I wanted.</p>
<p>I found a way, and it&#8217;s so simple it hurts.   I can&#8217;t help think this is one of those things the Catalyst team will read and think, &#8220;Well, duh!&#8221; but it was never clear to me and I struggled with it for months.<span id="more-78"></span></p>
<p>Make sure MyApp/lib is in @INC and use MyApp.  Catalyst is loaded, along with all the details of your application.  No Engine is running, so it isn&#8217;t a server.  You can then call methods listed for <a title="Catalyst" href="http://search.cpan.org/~flora/Catalyst-Runtime-5.80014/lib/Catalyst.pm" target="_blank">Catalyst</a>, as MyApp uses it as a parent.</p>
<p>The key to this is that Catalyst::model and Catalyst::view can both be called as class functions or as methods.  You usually seem them as $c-&gt;model() and $c-&gt;view, called off a context object.  They can work as MyApp-&gt;model() and MyApp-&gt;view(), too.</p>
<p>So, your tool does:</p>
<p>use MyApp;</p>
<p>my $foo = MyApp-&gt;model(&#8216;Model::Whatever&#8217;)-&gt;search({ name =&gt; &#8216;foo&#8217; })-&gt;first();</p>
<p>&#8230; or whatever thing it needs to do.  The config is loaded with all the MYAPP_SUFFIX parsing as you would expect.</p>
<p>A problem I couldn&#8217;t for a year and a half has finally been solved.  YAY!</p>
<p>The biggest quirk is that if MYAPP_DEBUG is set, or the app has $c-&gt;debug on, the debug output will happen when the module loads.  For the tools I&#8217;m writing that isn&#8217;t a problem, but it could be for other applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2009/11/calling-catalyst-functions-outside-catalyst/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Recursive Dependencies in CPAN</title>
		<link>http://blog.laufeyjarson.com/2009/06/recursive-dependencies-in-cpan/</link>
		<comments>http://blog.laufeyjarson.com/2009/06/recursive-dependencies-in-cpan/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 07:21:58 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[cpan]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=56</guid>
		<description><![CDATA[I&#8217;ve been quiet lately, as I&#8217;ve had hardware problems and haven&#8217;t done much development on my spare spare machine.  Finally got a new one, and am installing everything. Install Linux.  Configure CPAN.  First thing it does is complain CPAN is out of date, so I do the &#8220;install Bundle::CPAN&#8221; and wait. It then fails, and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been quiet lately, as I&#8217;ve had hardware problems and haven&#8217;t done much development on my spare spare machine.  Finally got a new one, and am installing everything.</p>
<p><!-- bubbleGUM-start --><span style="height: 0pt;width: 3pt;position: absolute;overflow: auto;"></span><!-- bubbleGUM-end --><span id="more-56"></span>Install Linux.  Configure CPAN.  First thing it does is complain CPAN is out of date, so I do the &#8220;install Bundle::CPAN&#8221; and wait.</p>
<p>It then fails, and copy and paste isn&#8217;t working.  Hmm.  Script will get it!</p>
<blockquote><p>Recursive dependency detected:<br />Bundle::CPAN<br />=&gt; Test::Harness<br />=&gt; A/AN/ANDYA/Test-Harness-3.17.tar.gz<br />=&gt; File::Spec<br />=&gt; S/SM/SMUELLER/PathTools-3.30.tar.gz<br />=&gt; Scalar::Util<br />=&gt; G/GB/GBARR/Scalar-List-Utils-1.21.tar.gz<br />=&gt; Test::More<br />=&gt; M/MS/MSCHWERN/Test-Simple-0.88.tar.gz<br />=&gt; Test::Harness.</p>
<p>Cannot continue.</p>
</blockquote>
<p>Looks like a dependency loop in Test::Harness, Test::More, and Scalar::Utils.</p>
<p>I can see how that happened, but it&#8217;s going to make a clean install kind of a pain.</p>
<p>What&#8217;s the right answer in a case like this?  Can a central module like Test::Harness not use Scalar::Util?  Or the other way about?</p>
<p>I don&#8217;t even know who to report the issue to.  Each module author is doing the right thing here.</p>
<p>Going to bed.  I&#8217;ll worry about how to solve this in the morning.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2009/06/recursive-dependencies-in-cpan/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Autovivification bit me today</title>
		<link>http://blog.laufeyjarson.com/2009/05/autovivification-bit-me-today/</link>
		<comments>http://blog.laufeyjarson.com/2009/05/autovivification-bit-me-today/#comments</comments>
		<pubDate>Wed, 27 May 2009 00:40:46 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=25</guid>
		<description><![CDATA[For the first time in more than five years, I got bit by autovivification.  It&#8217;s one of those odd quirks of Perl that I&#8217;d read about, and heard the problems with but never bumped in to them. I had put together a chunk of code using a hashref, which differentiated between the hash being undefined [...]]]></description>
			<content:encoded><![CDATA[<p>For the first time in more than five years, I got bit by autovivification.  It&#8217;s one of those odd quirks of Perl that I&#8217;d read about, and heard the problems with but never bumped in to them.</p>
<p><!-- bubbleGUM-start --><font style="position: absolute;overflow: hidden;height: 0;width: 0"></font><!-- bubbleGUM-end --><span id="more-25"></span></p>
<p>I had put together a chunk of code using a hashref, which differentiated between the hash being undefined and being empty.</p>
<p>My hashref was initialized:</p>
<pre>my $hashref = undef;</pre>
<p>Code read:</p>
<pre>return if exists $hashref-&gt;{something};</pre>
<pre>load_hashref($hashref) unless defined $hashref</pre>
<p>See how that isn&#8217;t going to work?  I see it now, but it took a few miutes of dinking around with <a title="Data::Dumper" href="http://search.cpan.org/~ilyam/Data-Dumper-2.121/Dumper.pm" target="_blank">Data::Dumper</a> to figure out what was happening.</p>
<p>The use of $hashref-&gt;{something} autovivifies the hash in $hashref to {}, which messes up the undef check below it.</p>
<p>Now I have to decide if I&#8217;m going to change the code to check if the hash is empty rather than undef, or if I&#8217;m going to stick a &#8220;defined $hashref and&#8221; before the exists check and short-circuit the exists and autovivification.</p>
<p>Using {} will be more robust, so I should go that way.</p>
<p>How do you tell if a hash is empty, anyway?  keys gives a list, and the list in scalar context is the number of items.</p>
<p>Code is now:</p>
<pre>my $hashref = {};</pre>
<pre>
<pre>return if exists $hashref-&gt;{something};</pre>
<p>load_hashref($hashref) unless scalar keys %$hashref;</pre>
<p>Thus, nothing will come along and screw up the code by accidentally referring to the hash.</p>
<p>Yay!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2009/05/autovivification-bit-me-today/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Debugging Catalyst</title>
		<link>http://blog.laufeyjarson.com/2009/05/debugging-catalyst/</link>
		<comments>http://blog.laufeyjarson.com/2009/05/debugging-catalyst/#comments</comments>
		<pubDate>Sat, 09 May 2009 21:20:32 +0000</pubDate>
		<dc:creator>Laufeyjarson</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Catalyst]]></category>

		<guid isPermaLink="false">http://blog.laufeyjarson.com/?p=20</guid>
		<description><![CDATA[My last post discussed figuring out how part of Catalyst worked.  I had to put debug code in to a library and watch it run. How do you do tht? It&#8217;s actually pretty easy, but it wasn&#8217;t obvious, at least to me.  It is on the debugging page of the Catalyst tutorial, but I missed [...]]]></description>
			<content:encoded><![CDATA[<p>My last post discussed figuring out how part of Catalyst worked.  I had to put debug code in to a library and watch it run.  How do you do tht?</p>
<p>It&#8217;s actually pretty easy, but it wasn&#8217;t obvious, at least to me.  It is on the <a title="Catalyst::Manual::Tutorial::Debugging" href="http://search.cpan.org/~hkclark/Catalyst-Manual-5.7020/lib/Catalyst/Manual/Tutorial/Debugging.pod" target="_blank">debugging</a> page of the <a title="Catalyst::Manual::Tutorial" href="http://search.cpan.org/~hkclark/Catalyst-Manual-5.7020/lib/Catalyst/Manual/Tutorial.pod" target="_blank">Catalyst tutorial</a>, but I missed it the first dozen times I read the page.</p>
<p><span id="more-20"></span></p>
<p>As a note, if you haven&#8217;t gone all the way through the tutorial yet, it really is the best place to start.  It tries to touch most of Catalyst and gets a lot of things right.  It is extremely dense, and you&#8217;ll have to go over it a lot before you see everything on the pages.  Or at least I did.  For instance, I just noticed the <a title="Task::Catalyst::Tutorial" href="http://search.cpan.org/~mramberg/Task-Catalyst-Tutorial-0.06/lib/Task/Catalyst/Tutorial.pm" target="_blank">Task::Catalyst::Tutorial</a> module, which will install the tutorial and all the dependencies in one go.</p>
<p>Back to debugging Catalyst.</p>
<p>Catalyst is written as a large collection of modules.  Even your Catalyst app is actually a module that is used by the server application.</p>
<p>The server application is the myapp_server.pl or one of the other scripts in the scripts directory.  These are provided by the catalyst.pl.  None of my programs have needed to change them at all.</p>
<p>Your code, like the rest of Catalyst, is libraries.</p>
<p>The server program sticks &#8220;lib&#8221; in @INC so all the modules you have written as part of your application are read.  It puts that early in @INC so that your programs are loaded before other library paths.</p>
<p>You can use this to debug the Catalyst libraries as well.</p>
<p>Find the library module you want to edit.  My most recent example was ConfigLoader.  The full name of that module is Catalyst::Plugin::ConfigLoader.  It should be in Catalyst/Plugin/ConfigLoader.pm, either in your local library path (such as ~/perl) or in the system library path (something awful like /usr/lib/perl5/site_perl/&lt;version number&gt;/), depending on where you installed it.</p>
<p>In your Catalyst application&#8217;s lib directory, create that same hierarchy, and copy .pm file there.  Instead of finding the one in the system path, it&#8217;ll find the one in myapp/lib/Catalyst/&#8230; first.</p>
<p>The example above was copied from /usr/lib/perl5/site_perl/5.8.8/Catalyst/Plugin/ConfigLoader.pm to ~/projects/MyApp/lib/Catalyst/Plugin/ConfigLoader.pm.  Then I scribbled a bunch of &#8220;print STDERR&#8221; statements in my copy so I could see what it was doing.</p>
<p>In my last post, I mentioned how the Catalyst documentation uses MyApp as the sample name for your application.  My note up there is actually literally correct, because I created a new, empty Catalyst app to test with.  I called it MyApp.  I erased it when I was done.  It&#8217;s a handy technique to simplify testing.</p>
<p>To recap, you can copy any part of Catlyst from the place it is installed to myapp/lib, maintaining the directory structure, and the one in the application will be loaded before the one in the library paths.  You can then use and edit that file as much as you like, without messing with the installed copy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.laufeyjarson.com/2009/05/debugging-catalyst/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

