<?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/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>clicktx::Tech::Memo &#187; perlモジュール</title>
	<atom:link href="http://perl.no-tubo.net/category/web%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0/perl/perl%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab/feed/" rel="self" type="application/rss+xml" />
	<link>http://perl.no-tubo.net</link>
	<description>perl、 MySQL、オープンソース系、ウェブ系ネタ。なぜか鯖管メモがほとんどを占めている...</description>
	<lastBuildDate>Mon, 23 Jan 2012 10:51:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/category/web%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%9f%e3%83%b3%e3%82%b0/perl/perl%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab/feed/" />
		<item>
		<title>MojoliciousでDBIx::CustomやDBIx::Connectorを使う時</title>
		<link>http://perl.no-tubo.net/2011/10/14/mojolicious%e3%81%a7dbixcustom%e3%82%84dbixconnector%e3%82%92%e4%bd%bf%e3%81%86%e6%99%82/</link>
		<comments>http://perl.no-tubo.net/2011/10/14/mojolicious%e3%81%a7dbixcustom%e3%82%84dbixconnector%e3%82%92%e4%bd%bf%e3%81%86%e6%99%82/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 08:42:33 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[Mojolicious]]></category>
		<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[DBIx::Custom]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=2085</guid>
		<description><![CDATA[すぐ忘れるし、どこにあったか分からなくなるのでメモ。
Mojolicious &#8211; GitHubより引用

Selec All Code:    package MyApp;
&#160;
    use Mo [...]]]></description>
			<content:encoded><![CDATA[<p>すぐ忘れるし、どこにあったか分からなくなるのでメモ。</p>
<p><a href="https://github.com/yuki-kimoto/DBIx-Custom/wiki/Mojolicious">Mojolicious &#8211; GitHub</a>より引用</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">    <span style="color: #000066;">package</span> MyApp<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">use</span> Mojo<span style="color: #339933;">::</span><span style="color: #006600;">Base</span> <span style="color: #ff0000;">'Mojolicious'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">use</span> DBIx<span style="color: #339933;">::</span><span style="color: #006600;">Custom</span><span style="color: #339933;">;</span>
&nbsp;
    has dbi <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbi</span> <span style="color: #339933;">=</span> DBIx<span style="color: #339933;">::</span><span style="color: #006600;">Custom</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">...</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">return</span> <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">sub</span> startup <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">### YOU MUST NOT CALL dbi() method in starup().</span>
    <span style="color: #009900;">&#125;</span></pre></div></div></div>

<p>リンク先にはBad Exampleもあるので参考に。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/10/14/mojolicious%e3%81%a7dbixcustom%e3%82%84dbixconnector%e3%82%92%e4%bd%bf%e3%81%86%e6%99%82/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/10/14/mojolicious%e3%81%a7dbixcustom%e3%82%84dbixconnector%e3%82%92%e4%bd%bf%e3%81%86%e6%99%82/" />
	</item>
		<item>
		<title>DBIx::Customで where を設定する時の注意点</title>
		<link>http://perl.no-tubo.net/2011/07/30/dbixcustom%e3%81%a7-where-%e3%82%92%e8%a8%ad%e5%ae%9a%e3%81%99%e3%82%8b%e6%99%82%e3%81%ae%e6%b3%a8%e6%84%8f%e7%82%b9/</link>
		<comments>http://perl.no-tubo.net/2011/07/30/dbixcustom%e3%81%a7-where-%e3%82%92%e8%a8%ad%e5%ae%9a%e3%81%99%e3%82%8b%e6%99%82%e3%81%ae%e6%b3%a8%e6%84%8f%e7%82%b9/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 06:30:26 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[DBIx::Custom]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1906</guid>
		<description><![CDATA[DBIx::Custom &#8211; search.cpan.org
DBIx-Custom-0.1705
DBIx::Custom select メソッドの whereの項目を見ると様々な指定方法が出来ることが分か [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://search.cpan.org/dist/DBIx-Custom/lib/DBIx/Custom.pm">DBIx::Custom &#8211; search.cpan.org</a><br />
DBIx-Custom-0.1705</p>
<p><a href="http://search.cpan.org/dist/DBIx-Custom/lib/DBIx/Custom.pm#select">DBIx::Custom select メソッドの whereの項目</a>を見ると様々な指定方法が出来ることが分かる。</p>
<p>注意する点はStringを渡す時。</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">where <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;url = 'http://hoge.com/huga.cgi?key=value' &quot;</span><span style="color: #339933;">,</span></pre></div></div></div>

<p>上のように条件に ? が含まれる場合、SQLの作成に失敗する。（DBIx::Custom::QueryBuilder::build_queryでかな？）</p>
<p>? がメタ文字として扱われるため？（\?とエスケープしてもダメ）</p>
<p>Hashリファレンスで渡すと大丈夫です。</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">where <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>url <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'http://hoge.com/huga.cgi?key=value'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></div></div></div>

<p>これを踏まえてコードにすると、安全なのはこんな感じのコードになるのかな。</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$id</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$url</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'http://hoge.com/huga.cgi?key=value'</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">select</span><span style="color: #009900;">&#40;</span>
        table   <span style="color: #339933;">=&gt;</span>  <span style="color: #ff0000;">'table_name'</span><span style="color: #339933;">,</span>
        column  <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #000066;">qw</span><span style="color: #339933;">/</span>title content url<span style="color: #339933;">/</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        where <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>
                    <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">&quot;and&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;{= id}&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;url = :url&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;update_time &gt; SUBDATE( NOW(), interval 7 day )&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                    <span style="color: #009900;">&#123;</span> id <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$id</span><span style="color: #339933;">,</span> url <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$url</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></div>

<p>※ {= id} は &#8220;id = :id&#8221; とも書ける（url = :urlも同様）。あえて両方含めてみた。</p>
<p>where にはDBIx::Custom::Whereオブジェクトも指定できますが、DBIx::Custom::Whereオブジェクトを生成する時にも同様で、? を含めた条件には注意が必要。</p>
<p>追記：タグ機能は廃止予定だそうです。<br />
<a href="http://twitter.com/#!/perlcodesample/status/97162783644319744">http://twitter.com/#!/perlcodesample/status/97162783644319744</a></p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/07/30/dbixcustom%e3%81%a7-where-%e3%82%92%e8%a8%ad%e5%ae%9a%e3%81%99%e3%82%8b%e6%99%82%e3%81%ae%e6%b3%a8%e6%84%8f%e7%82%b9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/07/30/dbixcustom%e3%81%a7-where-%e3%82%92%e8%a8%ad%e5%ae%9a%e3%81%99%e3%82%8b%e6%99%82%e3%81%ae%e6%b3%a8%e6%84%8f%e7%82%b9/" />
	</item>
		<item>
		<title>perlモジュールのバージョンを調べる便利なコマンド pmvers</title>
		<link>http://perl.no-tubo.net/2011/07/29/perl%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%81%ae%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%82%92%e8%aa%bf%e3%81%b9%e3%82%8b-pmvers/</link>
		<comments>http://perl.no-tubo.net/2011/07/29/perl%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%81%ae%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%82%92%e8%aa%bf%e3%81%b9%e3%82%8b-pmvers/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 11:08:28 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1899</guid>
		<description><![CDATA[perlモジュールのバージョンを一発で調べられるコマンド
$ pmvers DBIx::Cutom
0.168
cpanmがインストールしてあれば
$ cpanm pmvers
でインストールできます。
もうこんな事しな [...]]]></description>
			<content:encoded><![CDATA[<p>perlモジュールのバージョンを一発で調べられるコマンド</p>
<pre>$ pmvers DBIx::Cutom
0.168</pre>
<p>cpanmがインストールしてあれば</p>
<pre>$ cpanm pmvers</pre>
<p>でインストールできます。</p>
<p>もうこんな事しなくていいんです。</p>
<pre>perl -MDBI -e 'print $DBIx::Custom::VERSION'</pre>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/07/29/perl%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%81%ae%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%82%92%e8%aa%bf%e3%81%b9%e3%82%8b-pmvers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/07/29/perl%e3%83%a2%e3%82%b8%e3%83%a5%e3%83%bc%e3%83%ab%e3%81%ae%e3%83%90%e3%83%bc%e3%82%b8%e3%83%a7%e3%83%b3%e3%82%92%e8%aa%bf%e3%81%b9%e3%82%8b-pmvers/" />
	</item>
		<item>
		<title>DBIx::Customでデータベースの関数（MySQLのADDDATE()とかSUBDATE()とか）を使う</title>
		<link>http://perl.no-tubo.net/2011/07/29/dbixcustom%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e9%96%a2%e6%95%b0%ef%bc%88mysql%e3%81%aeadddate%e3%81%a8%e3%81%8bsubdate%e3%81%a8%e3%81%8b%ef%bc%89%e3%82%92/</link>
		<comments>http://perl.no-tubo.net/2011/07/29/dbixcustom%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e9%96%a2%e6%95%b0%ef%bc%88mysql%e3%81%aeadddate%e3%81%a8%e3%81%8bsubdate%e3%81%a8%e3%81%8b%ef%bc%89%e3%82%92/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 10:00:38 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[DBIx::Custom]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1869</guid>
		<description><![CDATA[DBIx::Customが生SQL感覚でも使えてお気に入りなのだけれど、ちょっこしハマったのでメモ。
DBIx::Custom &#8211; search.cpan.org 
MySQL（に限らないと思う）でwhere [...]]]></description>
			<content:encoded><![CDATA[<p>DBIx::Customが生SQL感覚でも使えてお気に入りなのだけれど、ちょっこしハマったのでメモ。</p>
<p><a href="http://search.cpan.org/~kimoto/DBIx-Custom/lib/DBIx/Custom.pm">DBIx::Custom &#8211; search.cpan.org</a> </p>
<p>MySQL（に限らないと思う）でwhereに関数を利用したい時は多々あると思います。<br />
例えば、更新時刻を見て7日以上古ければ選択しないという条件をwhereに指定したい時、</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span>  <span style="color: #ff0000;">`table`</span> <span style="color: #66cc66;">&#40;</span>
    <span style="color: #ff0000;">`name`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">5</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span>
    <span style="color: #ff0000;">`update_time`</span> <span style="color: #993333; font-weight: bold;">TIMESTAMP</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`table`</span> <span style="color: #993333; font-weight: bold;">WHERE</span> update_time <span style="color: #66cc66;">&gt;</span> SUBDATE<span style="color: #66cc66;">&#40;</span>NOW<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">INTERVAL</span> <span style="color: #cc66cc;">7</span> <span style="color: #993333; font-weight: bold;">DAY</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div></div>

<p>このようなSQLだとします。</p>
<p><a href="http://d.hatena.ne.jp/perlcodesample/20110210/1300165343">行の選択 select / DBIx::Custom リファレンス &#8211; サンプルコードによるPerl入門</a>によれば、where句の設定は、</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">where <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span></pre></div></div></div>

<p>と、ハッシュリファレンスで渡すことになっています。</p>
<p>=  以外での比較は DBIx::Custom::Whereオブジェクト を作成して渡すことになっているのですが、ハッシュリファレンスで SUBDATE(NOW(),  interval 7 day) を渡すとうまくいかないので悩んでいました。</p>
<p>append =&gt; &#8221; で文字列を追加できるので、無理やり実装してみたのですが作者にツイートしてみたところ、</p>
<p><a href="http://perl.no-tubo.net/wp-content/uploads/2011/07/2bfc96a45921677282a36721a07709ca1.png"><img src="http://perl.no-tubo.net/wp-content/uploads/2011/07/2bfc96a45921677282a36721a07709ca1-500x307.png" alt="twitterのキャプチャ" title="twitterのキャプチャ" width="500" height="307" class="alignnone size-medium wp-image-1881" /></a></p>
<p>がーん、そうなのか。恥ずかしい。。さらに、</p>
<p><a href="http://perl.no-tubo.net/wp-content/uploads/2011/07/d8eddf5329882d76f0b5323c6fd8e79a.png"><img src="http://perl.no-tubo.net/wp-content/uploads/2011/07/d8eddf5329882d76f0b5323c6fd8e79a-500x319.png" alt="twitterのキャプチャ2" title="twitterのキャプチャ2" width="500" height="319" class="alignnone size-medium wp-image-1883" /></a></p>
<p>がーん、DBIx::Custom::Where でも文字列が指定できたのか。。。（恥恥</p>
<p>という事で、</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> DBIx<span style="color: #339933;">::</span><span style="color: #006600;">Custom</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dbi</span> <span style="color: #339933;">=</span> DBIx<span style="color: #339933;">::</span><span style="color: #006600;">Custom</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">connect</span><span style="color: #009900;">&#40;</span>
    <span style="color: #339933;">...........</span>  端折ります
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">select</span><span style="color: #009900;">&#40;</span>
    table <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'table'</span><span style="color: #339933;">,</span>
    where <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'create_time &gt; SUBDATE(NOW(),  interval 7 day)'</span><span style="color: #339933;">,</span> 
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></div>

<p>あるいは、</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> DBIx<span style="color: #339933;">::</span><span style="color: #006600;">Custom</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$where</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">where</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$where</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">clause</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
    <span style="color: #ff0000;">'and'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'create_time &gt; SUBDATE(NOW(),  interval 7 day)'</span>
<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">select</span><span style="color: #009900;">&#40;</span>
    table <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'table'</span><span style="color: #339933;">,</span>
    where <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$where</span><span style="color: #339933;">,</span> 
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></div>

<p>で、出来るって事なんですね。（ソース嫁！）</p>
<p>id:perlcodesampleさんありがとうございました！<br />
DBIx::Customいいよー。</p>
<h3>ところで </h3>
<p>SYNOPSYSにあるinsertとかupdateとかが失敗するのはボクの日頃の行いが悪いせいでしょうか？</p>

<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;"># Insert </span>
    <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> table  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'book'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Update </span>
    <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">update</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> table  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'book'</span><span style="color: #339933;">,</span>
      where  <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>id <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></div>


<div class="my_syntax_box"><span class="my_syntax_selecall"><a href="javascript:;" onclick="selectCode(this); return false;">Selec All</a> </span><span class="my_syntax_Bar">Code:</span><div class="my_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;"># Insert </span>
    <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">insert</span><span style="color: #009900;">&#40;</span> param <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> table  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'book'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Update </span>
    <span style="color: #0000ff;">$dbi</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">update</span><span style="color: #009900;">&#40;</span> param <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>title <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Perl'</span><span style="color: #339933;">,</span> author <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Ken'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> table  <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'book'</span><span style="color: #339933;">,</span>
      where  <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>id <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div></div>

<p>だと性交いや、成功するのですが。<br />
param が必要？？（だからソース嫁！）</p>
<p>追記：DBIx::Customのバージョンが 0.168 だったからのようです&#8230;APIが追加された模様。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/07/29/dbixcustom%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e9%96%a2%e6%95%b0%ef%bc%88mysql%e3%81%aeadddate%e3%81%a8%e3%81%8bsubdate%e3%81%a8%e3%81%8b%ef%bc%89%e3%82%92/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/07/29/dbixcustom%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e9%96%a2%e6%95%b0%ef%bc%88mysql%e3%81%aeadddate%e3%81%a8%e3%81%8bsubdate%e3%81%a8%e3%81%8b%ef%bc%89%e3%82%92/" />
	</item>
		<item>
		<title>Mojolicious::LiteなアプリケーションをSpeedyCGIで動かす</title>
		<link>http://perl.no-tubo.net/2011/04/13/mojoliciouslite%e3%81%aa%e3%82%a2%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92speedycgi%e3%81%a7%e5%8b%95%e3%81%8b%e3%81%99/</link>
		<comments>http://perl.no-tubo.net/2011/04/13/mojoliciouslite%e3%81%aa%e3%82%a2%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92speedycgi%e3%81%a7%e5%8b%95%e3%81%8b%e3%81%99/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 10:34:34 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[Mojolicious]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[Mojolicious::Lite]]></category>
		<category><![CDATA[speedyCGI]]></category>
		<category><![CDATA[WAF]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1647</guid>
		<description><![CDATA[やっと出来たのでメモ。
起動スクリプト mojo.cgiを
#!/usr/bin/env perl

use strict;
use warnings;
use lib "../lib";
use App;

app-&#038; [...]]]></description>
			<content:encoded><![CDATA[<p>やっと出来たのでメモ。<br />
起動スクリプト mojo.cgiを</p>
<pre>#!/usr/bin/env perl

use strict;
use warnings;
use lib "../lib";
use App;

app-&gt;start('cgi');
exit;</pre>
<p>こんな感じで呼び出すと通常のCGIとしてならなんの問題もなく実行出来るのだけれど、SpeedyCGIで実行しようとすると初回実行時に不具合が出る（テンプレートが読み込まれない？）上記実行方法でも２回目以降（キャッシュ後）は動作している感じ。</p>
<p>FastCGIやmod_perlでのエントリーは見かけるんだけど、いかんせんマイナーなSpeedyCGI。結構便利なのにあまり使われていないのかなぁ。</p>
<p>で、とりあえず解決方法が見つかったのでメモ。結論から言えば起動スクリプトで Mojo::Server::CGI を使ってアプリを実行すればいいみたい。</p>
<h3>ApacheでCGI（SpeedyCGI）としてデプロイする</h3>
<p>起動用スクリプトを mojoアプリケーション本体と同じディレクトリに置く。これは必須ではないので公開するときには配置を変えたり出来る。<br />
（例えば App/public/mojo.cgi として  App/public を公開ディレクトリにするなど）</p>
<p>__DATA__セクションにテンプレートを書けるけど、ここではテストのため外部ファイル化している。</p>
<h4>最小構成</h4>
<pre>App +
    - App.pm
    - mojo.cgi
    - templates +
                - index.html.ep</pre>
<h4>スクリプト</h4>
<p>起動用スクリプト mojo.cgi</p>
<pre>#!/usr/bin/env speedy

use strict;
use warnings;

use Mojo::Server::CGI;
$ENV{MOJO_APP} = 'App';
<span style="color: #ff9900;">#$ENV{SCRIPT_NAME} = '';</span>
Mojo::Server::CGI-&gt;new-&gt;run;
exit;</pre>
<p>App.pm と 起動スクリプトが同じディレクトリの場合は use lib; しなくても大丈夫のようだ。別のディレクトリに起動スクリプトを置く場合、例えばApp/public/mojo.cgi とするなら use &#8220;../&#8221;; が必要になる。</p>
<p>mojoアプリケーション本体 App.pm</p>
<pre>package App;

use strict;    <span style="color: #ff9900;"># use Mojolicious::Lite;で自動でされるが明示的に</span>
use warnings;  <span style="color: #ff9900;"># しておく。</span>
use utf8;
use Mojolicious::Lite;

<span style="color: #ff9900;"># テンプレートへ渡すハッシュリファレンス</span>
my $params = {};

<span style="color: #ff9900;"># インデックスページ</span>
get '/' =&gt; sub {
    my $self = shift;

    $params-&gt;{title}="Hello World!";
    $params-&gt;{messe} = "ようこそ 世界へ！";
    $self-&gt;stash(params =&gt; $params);
} =&gt; 'index';

<span style="color: #ff9900;"># mojo.cgi/任意の文字に対応</span>
get '/:foo' =&gt; sub {
    my $self = shift;

    $params-&gt;{title}= $self-&gt;param('foo');
    $params-&gt;{messe} = "このページは" . $self-&gt;param('foo') . "です";
    $self-&gt;stash(params =&gt; $params);
} =&gt; 'index';</pre>
<p>テンプレートファイル templates/index.html.ep</p>
<pre>&lt;!doctype html&gt;
&lt;html&gt;
    &lt;head&gt;
    &lt;title&gt;&lt;%= $params-&gt;{title} %&gt;&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;h1&gt;&lt;%= $params-&gt;{messe} %&gt;&lt;/h1&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre>
<p>上記は最低限のファイル構成だけれど、テンプレートでレイアウト使っても動作していたのでSpeedyCGI化もこの方法なら大丈夫そう。</p>
<p>参考</p>
<li><a href="http://yanor.net/wiki/?Perl-Mojolicious%2FApacheにCGIでデプロイ">Perl-Mojolicious/ApacheにCGIでデプロイ &#8211; yanor.net/wiki</a></li>
<li><a href="http://d.hatena.ne.jp/rightgo09/20100101/p2">Mojoことはじめ &#8211; Perl日記</a></li>
<li><a href="http://d.hatena.ne.jp/charsbar/20081105/1225820041">Mojoを使ってみた &#8211; Charsbar::Note<br />
</a></li>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/04/13/mojoliciouslite%e3%81%aa%e3%82%a2%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92speedycgi%e3%81%a7%e5%8b%95%e3%81%8b%e3%81%99/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/04/13/mojoliciouslite%e3%81%aa%e3%82%a2%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%92speedycgi%e3%81%a7%e5%8b%95%e3%81%8b%e3%81%99/" />
	</item>
		<item>
		<title>perl メール送信にテンプレートを使う Email::MIME::MobileJP::Template</title>
		<link>http://perl.no-tubo.net/2011/04/05/perl-%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1%e3%81%ab%e3%83%86%e3%83%b3%e3%83%97%e3%83%ac%e3%83%bc%e3%83%88%e3%82%92%e4%bd%bf%e3%81%86-emailmimemobilejptemplate/</link>
		<comments>http://perl.no-tubo.net/2011/04/05/perl-%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1%e3%81%ab%e3%83%86%e3%83%b3%e3%83%97%e3%83%ac%e3%83%bc%e3%83%88%e3%82%92%e4%bd%bf%e3%81%86-emailmimemobilejptemplate/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 04:58:46 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[メール]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1567</guid>
		<description><![CDATA[id:tokuhirom氏作の Email::MIME::MobileJP::Template を発見したので使ってみる。
PODにあるコードは動作しないので注意。renderメソッドのAPIが変わったのかな？ソースを見 [...]]]></description>
			<content:encoded><![CDATA[<p>id:tokuhirom氏作の <a href="http://search.cpan.org/~tokuhirom/Email-MIME-MobileJP-0.05/lib/Email/MIME/MobileJP/Template.pm">Email::MIME::MobileJP::Template</a> を発見したので使ってみる。</p>
<p>PODにあるコードは動作しないので注意。renderメソッドのAPIが変わったのかな？ソースを見ると引数の最初に送り先のメールアドレスを指定しないとダメみたい。</p>
<p>それと、<a href="http://search.cpan.org/~tokuhirom/Email-MIME-MobileJP-0.05/lib/Email/MIME/MobileJP.pm#Email::MIME::MobileJP::Template_(12398)(12420)(12388)(12434)(12388)(12363)(12358)(12497)(12479)(12540)(12531)">Email::MIME::MobileJP</a> にあるソースも間違えているので注意。syntax=&gt;&#8217;TTerse&#8217; は newする時に引数で指定する事。</p>
<pre>use Email::MIME::MobileJP::Template;
use Email::Sender::Simple;

    my $token='123';
    my $to_email = '&lt;foo@hoge.jp&gt;'; <span style="color: #ff0000;"># &lt;&gt;で囲わないとdocomoで受信したときToがおかしなことに。</span>

    my $mail_maker = Email::MIME::MobileJP::Template-&gt;new(
                    'Text::Xslate' =&gt; {
                            syntax =&gt; 'TTerse',
                            path =&gt; ['email_tmpl/']     <span style="color: #ff0000;"># テンプレートの保存場所</span>
                    }
    );

    my $mail = $mail_maker-&gt;render(
                    <span style="color: #ff9900;"><strong>$to_email,</strong></span>                  <span style="color: #ff0000;"># 送信先</span>
                    'signup.eml',               <span style="color: #ff0000;"># テンプレートファイル</span>
                    {token =&gt; $token}    <span style="color: #ff0000;"># テンプレートで利用する変数</span>
    );
    <span style="color: #ff0000;"># メールを送信</span>
    Email::Sender::Simple-&gt;send($mail);</pre>
<h3>テンプレートファイル</h3>
<p>path で指定したディレクトリにテンプレートファイルを作成する。MIMEヘッダはテンプレートでしか指定できない。Fromは記述しないと致命的なエラーとなるので注意。</p>
<p>./email_tmpl/signup.eml</p>
<pre>Subject: [Example] サインアップ!
<span style="color: #ff9900;">From: &lt;name@hoge.com&gt;
</span>
    以下をクリックせよ
    http://example.com/signup/[% token %]</pre>
<h3>携帯電話宛のメールが正しく送れない？</h3>
<p><span id="more-1567"></span><br />
メールテンプレートで、Fromに指定するメールアドレスは&lt;&gt;で囲わないとdocomoへ送ったときにUnknown user となってしまった。from=&lt;&gt; となっている。これは自分の環境の問題？</p>
<p>エラーになったテンプレートファイル例</p>
<pre>Subject: [Example] サインアップ!
<span style="color: #ff9900;">From: name@hoge.com
</span>
    以下をクリックせよ
    http://example.com/signup/[% token %]</pre>
<p>Postfixのエラーログ</p>
<pre>Apr  5 17:44:56 vm postfix/smtp[24073]: 7D4ED32358D: to=&lt;xxxxx.@docomo.ne.jp&gt;, relay=mfsmax.docomo.ne.jp[203.138.180.112]:25, delay=0.17, delays=0.09/0.01/0.03/0.04, dsn=5.0.0, status=bounced (host mfsmax.docomo.ne.jp[203.138.180.112] said: 550 Unknown user xxxxx.@docomo.ne.jp (in reply to end of DATA command))
Apr  5 17:44:56 vm postfix/cleanup[23741]: A169832358F: message-id=&lt;20110405084456.A169832358F@mail.hoge.jp&gt;
Apr  5 17:44:56 vm postfix/qmgr[1698]: A169832358F: <span style="color: #ff9900;">from=&lt;&gt;</span>, size=2480, nrcpt=1 (queue active)</pre>
<p>あと、送信先のメールアドレスは</p>
<pre>my $to_email = '&lt;foo@hoge.jp&gt;';</pre>
<p>のように指定しないと携帯（docomoムーバ）で受信したときにおかしな挙動となる。メールを開くと返信不可マークのToヘッダが表示されている（メールアドレスは送った携帯のメアド）。返信しようとすると返信先を選択する画面になる。</p>
<p>メール送信の実装はガラケーとカオスな文字コードのおかげでやたらと面倒なことが多い。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/04/05/perl-%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1%e3%81%ab%e3%83%86%e3%83%b3%e3%83%97%e3%83%ac%e3%83%bc%e3%83%88%e3%82%92%e4%bd%bf%e3%81%86-emailmimemobilejptemplate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/04/05/perl-%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1%e3%81%ab%e3%83%86%e3%83%b3%e3%83%97%e3%83%ac%e3%83%bc%e3%83%88%e3%82%92%e4%bd%bf%e3%81%86-emailmimemobilejptemplate/" />
	</item>
		<item>
		<title>Mojolicious::Liteな perl CGI をレンサバにアップロードするだけで動かす。</title>
		<link>http://perl.no-tubo.net/2011/03/09/mojoliciouslite%e3%81%aa-perl-cgi-%e3%82%92%e3%83%ac%e3%83%b3%e3%82%b5%e3%83%90%e3%81%ab%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91%e3%81%a7%e5%8b%95/</link>
		<comments>http://perl.no-tubo.net/2011/03/09/mojoliciouslite%e3%81%aa-perl-cgi-%e3%82%92%e3%83%ac%e3%83%b3%e3%82%b5%e3%83%90%e3%81%ab%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91%e3%81%a7%e5%8b%95/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 12:42:16 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[Mojolicious]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[CGI]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1481</guid>
		<description><![CDATA[perlのWAF（ウェブアプリケーションフレームワーク）である Mojolicious（Mojolicious::Lite）をアップロードだけで使えるのか試してみる。
簡単に使えるフレームワークとして、とりあえず Lin [...]]]></description>
			<content:encoded><![CDATA[<p>perlのWAF（ウェブアプリケーションフレームワーク）である Mojolicious（Mojolicious::Lite）をアップロードだけで使えるのか試してみる。</p>
<p>簡単に使えるフレームワークとして、とりあえず Linux+Apacheで動けばおｋという前提で。</p>
<p>なにせフレームワーク初心者の戯事なのでそのあたりは察してください。</p>
<p><span id="more-1481"></span></p>
<h3>準備</h3>
<p>httpでアクセス可能な場所にappというディレクトリを作成。<br />
その中にapp.cgiファイルを作る。<br />
ソース的にはこんな感じ。</p>
<pre>#!/usr/bin/perl
##  又は、#!/usr/bin/env perl

use lib './lib';
use Mojolicious::Lite;

#use strict;         # use Mojolicious::Lite;の時点で
#use warnings;   # 両方共適用される
use utf8;

my $contents = {};

# Hello World!!
get '/' =&gt; sub {
    my $self = shift;

    $contents -&gt;{messe} = "Hello World!!";
    $self-&gt;stash(contents=&gt;$contents);

}=&gt;'index';

app-&gt;start('cgi');

__DATA__

@@ index.html.ep
&lt;html&gt;
  &lt;body&gt;
    &lt;h1&gt;index page&lt;/h1&gt;
    &lt;%= $contents-&gt;{messe} %&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>
<p>構成</p>
<pre>app（ディレクトリ）
  |- app.cgi（perl cgi）</pre>
<h4>lib以下にmojo関連のモジュールを置く</h4>
<p>ダウンロード先もリンクに掲載されています。</p>
<li><a href="http://d.hatena.ne.jp/perlcodesample/20091210/1260183022">Mojoliciousマニュアル &#8211; サンプルコードによるPerl入門</a></li>
<p>解凍したmojoディレクトリの中にlibというディレクトリがあるのでまるっとアップロードする（1.2MB程ある）</p>
<pre>app（ディレクトリ）
  |- app.cgi（perl cgi）
  |- lib
      |- mojo
      |-  .... 他たくさん</pre>
<h3>動作確認</h3>
<p>app.cgi に実行権限を与える（700や705など）</p>
<p>http://hoge.com/app/app.cgi<br />
にアクセスして無事indexページが表示されれば成功。</p>
<p>以下に全てのファイルが入ったzipがダウンロードできます。<br />
<a href="http://perl.no-tubo.net/wp-content/uploads/2011/03/app.zip">appのサンプル</a></p>
<h3>これでよいのか？</h3>
<p>このような使い方は邪道なのかもしれないけど、手軽に簡単にフレームワークを使ったPerlスクリプトを書きたいとか、設置したいとかの要望はあると思うのですよ。</p>
<p>ただし、すべての機能が使えるかどうかは試していないのであしからず。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/03/09/mojoliciouslite%e3%81%aa-perl-cgi-%e3%82%92%e3%83%ac%e3%83%b3%e3%82%b5%e3%83%90%e3%81%ab%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91%e3%81%a7%e5%8b%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/03/09/mojoliciouslite%e3%81%aa-perl-cgi-%e3%82%92%e3%83%ac%e3%83%b3%e3%82%b5%e3%83%90%e3%81%ab%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89%e3%81%99%e3%82%8b%e3%81%a0%e3%81%91%e3%81%a7%e5%8b%95/" />
	</item>
		<item>
		<title>perl Mail::Sendmail はRFC違反の携帯メールアドレスに送信出来ない</title>
		<link>http://perl.no-tubo.net/2011/03/08/perl-mailsendmail-%e3%81%afrfc%e9%81%95%e5%8f%8d%e3%81%ae%e6%90%ba%e5%b8%af%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%a2%e3%83%89%e3%83%ac%e3%82%b9%e3%81%ab%e9%80%81%e4%bf%a1%e5%87%ba%e6%9d%a5%e3%81%aa/</link>
		<comments>http://perl.no-tubo.net/2011/03/08/perl-mailsendmail-%e3%81%afrfc%e9%81%95%e5%8f%8d%e3%81%ae%e6%90%ba%e5%b8%af%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%a2%e3%83%89%e3%83%ac%e3%82%b9%e3%81%ab%e9%80%81%e4%bf%a1%e5%87%ba%e6%9d%a5%e3%81%aa/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 04:49:53 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[携帯メール]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1464</guid>
		<description><![CDATA[メール送信に便利な Mail::Sendmail
大変便利なモジュールだけど、RFCに違反しているメールアドレスでは内部のエラーチェックに引っかかり送信出来ない。
例えばこんなメールアドレスには送信出来ない。
例）rea [...]]]></description>
			<content:encoded><![CDATA[<p>メール送信に便利な Mail::Sendmail<br />
大変便利なモジュールだけど、RFCに違反しているメールアドレスでは内部のエラーチェックに引っかかり送信出来ない。</p>
<p>例えばこんなメールアドレスには送信出来ない。<br />
例）read_rfc822.@docomo.ne.jp</p>
<p>元ソースの正規表現部分</p>
<pre># regex for e-mail addresses where full=$1, user=$2, domain=$3
# see pod documentation about this regex

my $word_rx = '[\x21\x23-\x27\x2A-\x2B\x2D\x2F\w\x3D\x3F]+';
my $user_rx = $word_rx         # valid chars
             .'(?:\.' . $word_rx . ')*' # possibly more words preceded by a dot
             ;
my $dom_rx = '\w[-\w]*(?:\.\w[-\w]*)*'; # less valid chars in domain names
my $ip_rx = '\[\d{1,3}(?:\.\d{1,3}){3}\]';

$address_rx = '((' . $user_rx . ')\@(' . $dom_rx . '|' . $ip_rx . '))';
; # v. 0.61</pre>
<p>@EXPORT_OK に $address_rx が設定されているので、$Mail::Sendmail::address_rx の正規表現を変更すればエラーチェックに引っかからないようになる。</p>
<pre>my $word_rx = '[\x21\x23-\x27\x2A-\x2B\x2D\x2F\w\x3D\x3F<span style="color: #ff9900;">\.</span>]+'; <span style="color: #ff9900;"># \.を追記する</span>
my $user_rx = $word_rx . '(?:\.' . $word_rx . ')*' ;
my $dom_rx = '\w[-\w]*(?:\.\w[-\w]*)*'; # less valid chars in domain names
my $ip_rx = '\[\d{1,3}(?:\.\d{1,3}){3}\]';
my $address_rx = '((' . $user_rx . ')\@(' . $dom_rx . '|' . $ip_rx . '))';
$Mail::Sendmail::address_rx= $address_rx;</pre>
<p>正規表現を無効にした場合、当然の事ながらその前にメールアドレスの正当性をチェックしておく必要があると思う。（携帯メールアドレスを有効にするなら Email::Valid::Loose 等）</p>
<li>関連記事：<a href="http://perl.no-tubo.net/category/webプログラミング/perl/page/3/">perl でメールアドレスの有効性をチェックするモジュール</a></li>
<h3>モダンなperlモジュール</h3>
<p>メール送信系のモジュールは山ほどあるので何がいいか悩むところ。Mail::Sendmail のエントリーだけど、 Email::Sender がモダンなモジュールとして紹介されているのでリンクを載せておく。</p>
<li><a href="http://gihyo.jp/dev/serial/01/modern-perl/0020">モダンPerlの世界へようこそ：第20回　Email::Sender：メールを送信する｜gihyo.jp … 技術評論社</a></li>
<li><a href="http://d.hatena.ne.jp/punitan/20100220/1266680547">[Email::Sender]Perlでメールを送信するときはEmail::Senderを使いましょうというお話 &#8211; punitanのメモ</a></li>
<p>気になる点は Moose に依存しているという事。</p>
<li><a href="http://d.hatena.ne.jp/tokuhirom/20100719/1279543292">Perl5 によるメール送信 &#8211; 実践的な Email::Sender の利用方法</a></li>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/03/08/perl-mailsendmail-%e3%81%afrfc%e9%81%95%e5%8f%8d%e3%81%ae%e6%90%ba%e5%b8%af%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%a2%e3%83%89%e3%83%ac%e3%82%b9%e3%81%ab%e9%80%81%e4%bf%a1%e5%87%ba%e6%9d%a5%e3%81%aa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/03/08/perl-mailsendmail-%e3%81%afrfc%e9%81%95%e5%8f%8d%e3%81%ae%e6%90%ba%e5%b8%af%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%a2%e3%83%89%e3%83%ac%e3%82%b9%e3%81%ab%e9%80%81%e4%bf%a1%e5%87%ba%e6%9d%a5%e3%81%aa/" />
	</item>
		<item>
		<title>Apache2.2にmod_SpeedyCGIを組込むにはパッチが必要</title>
		<link>http://perl.no-tubo.net/2011/02/07/apache2-2%e3%81%abmod_speedycgi%e3%82%92%e7%b5%84%e8%be%bc%e3%82%80%e3%81%ab%e3%81%af%e3%83%91%e3%83%83%e3%83%81%e3%81%8c%e5%bf%85%e8%a6%81/</link>
		<comments>http://perl.no-tubo.net/2011/02/07/apache2-2%e3%81%abmod_speedycgi%e3%82%92%e7%b5%84%e8%be%bc%e3%82%80%e3%81%ab%e3%81%af%e3%83%91%e3%83%83%e3%83%81%e3%81%8c%e5%bf%85%e8%a6%81/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 04:16:26 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[speedyCGI]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1356</guid>
		<description><![CDATA[Apache2.2でSpeedyCGIのperlモジュールを使うのならyumなりで一発インストールできるけど、mod_SpeedyCGIをインストールしようとするとmakeでコケる。
どうやらパッチを当ててからmakeす [...]]]></description>
			<content:encoded><![CDATA[<p>Apache2.2でSpeedyCGIのperlモジュールを使うのならyumなりで一発インストールできるけど、mod_SpeedyCGIをインストールしようとするとmakeでコケる。</p>
<p>どうやらパッチを当ててからmakeする必要があるようだ。<br />
参考：<a href="http://www.maido3.com/server/support/apache2speedy.html">Apache2.2にmod_SpeedyCGIを組み込む方法（パッチファイルのあて方） / レンタルサーバー BIG-server.com</a></p>
<h3>パッチファイルのダウンロード</h3>
<p>パッチファイル：<a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=1111235&amp;group_id=2208&amp;atid=302208">CGI::SpeedyCGI with apr-1.0 </a></p>
<p>※パッチファイルはwgetで入手できないのでダウンロードしておいてFTP等でアップロードする必要がある。<span id="more-1356"></span></p>
<h3>SpeedyCGIのインストール</h3>
<pre>$ wget http://www.cpan.org/modules/by-authors/id/H/HO/HORROCKS/CGI-SpeedyCGI-2.22.tar.gz
$ tar zxvf CGI-SpeedyCGI-2.22.tar.gz

<span style="color: #ff9900;">#####
CGI-SpeedyCGI-2.22/mod_speedycgi2 に
ダウンロードしたパッチをFTP等でアップロードする
#####</span>

$ cd CGI-SpeedyCGI-2.22/mod_speedycgi2
$ patch -p1 &lt; patch-mod_speedycgi2.c	<span style="color: #ff9900;">＃パッチをあてる</span>
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- src/mod_speedycgi2.c.orig	Tue Oct  7 13:03:48 2003
|+++ src/mod_speedycgi2.c	Sun Jan 23 20:42:43 2005
--------------------------
File to patch: <span style="color: #ff9900;">../src/mod_speedycgi2.c    # パッチをあてるファイルを指定</span>

$ cd ../
$ perl Makefile.PL

Optional mod_speedycgi support.

Mod_speedycgi increases performance under Apache by avoiding the fork/exec
overhead associated with each request under normal SpeedyCGI.  However, it
requires a working copy of "apxs" in your path, Apache with mod_so
support, and additional Apache configuration.

Compile mod_speedycgi (default no)? <span style="color: #ff9900;">yes    # yesを入力</span>

$ make
$ make test
$ sudo make install</pre>
<h3>・・・エラー。</h3>
<pre>make[1]: apxs: コマンドが見つかりませんでした
make[1]: *** [install] エラー 127

sudo make install -i   # エラーを無視するオプションをつけてインストール。</pre>
<p>mod_SpeedyCGIがインストールされないので、Apacheモジュールディレクトリにコピーする。<br />
README通り、CGI-SpeedyCGI-2.22/mod_speedycgi2/.libs に mod_speedycgi.so が作成されているので /usr/lib/httpd/modules にコピーする（CentOSの場合）</p>
<pre>$ cd mod_speedycgi2/.libs
$ sudo cp mod_speedycgi.so /usr/lib/httpd/modules</pre>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/02/07/apache2-2%e3%81%abmod_speedycgi%e3%82%92%e7%b5%84%e8%be%bc%e3%82%80%e3%81%ab%e3%81%af%e3%83%91%e3%83%83%e3%83%81%e3%81%8c%e5%bf%85%e8%a6%81/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/02/07/apache2-2%e3%81%abmod_speedycgi%e3%82%92%e7%b5%84%e8%be%bc%e3%82%80%e3%81%ab%e3%81%af%e3%83%91%e3%83%83%e3%83%81%e3%81%8c%e5%bf%85%e8%a6%81/" />
	</item>
		<item>
		<title>perlで日付算出にはDate::Calc 日数計算や前月1日〜月末など</title>
		<link>http://perl.no-tubo.net/2011/01/21/perl%e3%81%a7%e6%97%a5%e4%bb%98%e7%ae%97%e5%87%ba%e3%81%ab%e3%81%afdatecalc-%e6%97%a5%e6%95%b0%e8%a8%88%e7%ae%97%e3%82%84%e5%89%8d%e6%9c%881%e6%97%a5%e3%80%9c%e6%9c%88%e6%9c%ab%e3%81%aa%e3%81%a9/</link>
		<comments>http://perl.no-tubo.net/2011/01/21/perl%e3%81%a7%e6%97%a5%e4%bb%98%e7%ae%97%e5%87%ba%e3%81%ab%e3%81%afdatecalc-%e6%97%a5%e6%95%b0%e8%a8%88%e7%ae%97%e3%82%84%e5%89%8d%e6%9c%881%e6%97%a5%e3%80%9c%e6%9c%88%e6%9c%ab%e3%81%aa%e3%81%a9/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 02:35:15 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[perlモジュール]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[モジュール]]></category>
		<category><![CDATA[日付]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1291</guid>
		<description><![CDATA[&#68;&#97;&#116;&#101;::&#67;&#97;&#108;&#99; &#8211; search.cpan.org
基本
use Date::Calc qw(:all);

# 今日
my ($y [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://search.cpan.org/~stbey/Date-Calc-6.3/lib/Date/Calc.pod">&#68;&#97;&#116;&#101;::&#67;&#97;&#108;&#99; &#8211; search.cpan.org</a></p>
<h3>基本</h3>
<pre>use Date::Calc qw(:all);

<span style="color: #ff9900;"># 今日</span>
my ($yyyy,$mm,$dd) = Today();
print "$yyyy/$mm/$dd"; 

<span style="color: #ff9900;"># 実行結果</span>
2011/1/21</pre>
<h3>昨日の日付（日付計算）</h3>
<pre>use Date::Calc;

my ($yyyy,$mm,$dd) = Date::Calc::Today();
@y = Date::Calc::Add_Delta_Days($yyyy, $mm, $dd, -1);
my $yesterday= join('/',@y);

print "昨日=$yesterday\n";

<span style="color: #ff9900;"># 実行結果</span>
昨日=2011/1/20</pre>
<p><em>Date::Calc::Add_Delta_Days($yyyy, $mm, $dd, -1);</em>の-1を-7にすれば7日前、5にすれば5日後となる。</p>
<h3>前月1日と月末を算出</h3>
<pre>use Date::Calc;

@y = Date::Calc::Add_Delta_YMD($yyyy, $mm, 1, 0 ,-1, 0); <span style="color: #ff9900;">#前月1日</span>
$start = join('/',@y);
@y = Date::Calc::Add_Delta_YMD($yyyy, $mm, 1, 0, 0, -1); <span style="color: #ff9900;">#前月末日</span>
$end = join('/',@y);

print "前月1日=$start\n";
print "前月末日=$end\n";

<span style="color: #ff9900;"># 実行結果</span>
前月1日=2010/12/1
前月末日=2010/12/31</pre>
<p><a href="http://www.ksknet.net/perl/datecalc.html">Date::Calc &#8211; 日付の計算</a>にもサンプルが。<br />
日付の不正を確認、指定した月の日数を取得、タイムスタンプを取得など。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/01/21/perl%e3%81%a7%e6%97%a5%e4%bb%98%e7%ae%97%e5%87%ba%e3%81%ab%e3%81%afdatecalc-%e6%97%a5%e6%95%b0%e8%a8%88%e7%ae%97%e3%82%84%e5%89%8d%e6%9c%881%e6%97%a5%e3%80%9c%e6%9c%88%e6%9c%ab%e3%81%aa%e3%81%a9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/01/21/perl%e3%81%a7%e6%97%a5%e4%bb%98%e7%ae%97%e5%87%ba%e3%81%ab%e3%81%afdatecalc-%e6%97%a5%e6%95%b0%e8%a8%88%e7%ae%97%e3%82%84%e5%89%8d%e6%9c%881%e6%97%a5%e3%80%9c%e6%9c%88%e6%9c%ab%e3%81%aa%e3%81%a9/" />
	</item>
	</channel>
</rss>

