<?xml version="1.0" encoding="windows-1252"?>
<node id="995523" title="Re: Setting up helper objects in App::Cmd" created="2012-09-25 06:21:33" updated="2012-09-25 06:21:33">
<type id="11">
note</type>
<author id="757127">
tobyink</author>
<data>
<field name="doctext">
&lt;p&gt;I'd generally name my modules things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MyApp::Command::Foo&lt;/li&gt;
&lt;li&gt;MyApp::Command::Bar&lt;/li&gt;
&lt;li&gt;MyApp::Lib::Foobar&lt;/li&gt;
&lt;li&gt;MyApp::Lib::Database&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And instead of loading library modules at compile time with &lt;c&gt;use MyApp::Lib::Database&lt;/c&gt;, defer loading to run-time (with &lt;c&gt;require MyApp::Lib::Database&lt;/c&gt;) &lt;em&gt;inside&lt;/em&gt; your command's &lt;c&gt;execute&lt;/c&gt; method. This means that you can avoid loading up database connections, etc when the user is just running, say, &lt;c&gt;myapp help&lt;/c&gt;. Load them only once they're needed.&lt;/p&gt;

&lt;p&gt;PS: a release using this technique is &lt;a href="https://metacpan.org/release/P5U"&gt;P5U&lt;/a&gt;.&lt;/p&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-757127"&gt;
&lt;small&gt;&lt;small&gt;
&lt;tt&gt;perl -E'sub Monkey::do{say$_,for@_,do{($monkey=&amp;#x5B;caller(0)]-&gt;&amp;#x5B;3])=~s{::}{ }and$monkey}}"Monkey say"-&gt;Monkey::do'
&lt;/tt&gt;&lt;/small&gt;&lt;/small&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
995520</field>
<field name="parent_node">
995520</field>
</data>
</node>
