<?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; Catalyst</title>
	<atom:link href="http://blog.laufeyjarson.com/tag/catalyst/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>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>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>

