<?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/tag/perl/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/tag/perl/feed/" />
		<item>
		<title>MAMP(Apache+MySQL)を使ってローカルでらくらくperl開発</title>
		<link>http://perl.no-tubo.net/2011/12/15/manmpapachemysql%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%83%bc%e3%82%ab%e3%83%ab%e3%81%a7%e3%82%89%e3%81%8f%e3%82%89%e3%81%8fperl%e9%96%8b%e7%99%ba/</link>
		<comments>http://perl.no-tubo.net/2011/12/15/manmpapachemysql%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%83%bc%e3%82%ab%e3%83%ab%e3%81%a7%e3%82%89%e3%81%8f%e3%82%89%e3%81%8fperl%e9%96%8b%e7%99%ba/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 03:34:59 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[webプログラミング]]></category>
		<category><![CDATA[cpanm]]></category>
		<category><![CDATA[MacPorts]]></category>
		<category><![CDATA[MANP]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[開発環境]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=2177</guid>
		<description><![CDATA[MAMP
Apache+MySQLサーバをmacで動作させる事ができる。macにはもともとApacheもperlもインストールされているけど、バージョンが古いし、管理も面倒なのでMANPを使うメリットはおおいにあると思う [...]]]></description>
			<content:encoded><![CDATA[<h3>MAMP</h3>
<p>Apache+MySQLサーバをmacで動作させる事ができる。macにはもともとApacheもperlもインストールされているけど、バージョンが古いし、管理も面倒なのでMANPを使うメリットはおおいにあると思う。もともとはPHP+MySQLのローカル環境を構築するためのもの&#8230;かな？</p>
<p>参考：<a href="http://gabs.cc/blog/bun/topic20090608-1456.php">Mac OS Xのローカル環境(MAMP+MacPorts)で Movable Typeを動かしてみよう &#8211; 準備編　 [ 09.06.24 update ] 【 gabs.log｜おしゃべり好きなWEB制作者のたわごと 】</a></p>
<h4>MAMPをインストール</h4>
<p><a href="http://perl.no-tubo.net/wp-content/uploads/2011/11/ad742af065c3a8cba15a777a8bb696dd.png"><img src="http://perl.no-tubo.net/wp-content/uploads/2011/11/ad742af065c3a8cba15a777a8bb696dd-499x346.png" alt="MAMP" title="MAMP" width="499" height="346" class="alignnone size-medium wp-image-2180" /></a></p>
<p><a href="http://www.mamp.info/en/index.html">MAMP</a>からダウンロードしてインストールする。</p>
<h3>MacPortsのインストール</h3>
<p>makeとか使うのでXCodeが必要。OSのバージョンにあったものをダウンロードする。</p>
<li><a href="http://www.macports.org/install.php">The MacPorts Project &#8212; Download &#038; Installation</a></li>
<h4>MacPortsの初期化＆設定</h4>
<p>Terminalでコマンドを実行</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="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'export PATH=$PATH:/opt/local/bin:/opt/local/sbin/'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'export MANPATH=$MANPATH:/opt/local/man'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'source ~/.bashrc'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bash_profile
<span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #660033;">-d</span> selfupdate
<span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #660033;">-d</span> <span style="color: #c20cb9; font-weight: bold;">sync</span></pre></div></div></div>

<h4>perlのPATHを変更</h4>
<p>元のperlをperl.bakにリネームして、シンボリックリンクを貼る。これをしておかないと元々インストールしてあるperl(/usr/bin/perl)を参照してしまうため。</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="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> perl.bak
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">perl</span></pre></div></div></div>

<h3>cpanmをインストール</h3>
<p>perlモジュールを簡単にインストールできるcpanmをインストールする。</p>
<li><a href="http://artifactsauce.blogspot.com/2010/10/cpanmmac-os-x.html">ArtifactSauce: cpanmをMac OS Xにインストールする</a></li>
<p>sudoでインストールすると /opt/local/lib 以下にインストールされる。</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="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> cpanm Mojolicious
or
cpanm <span style="color: #660033;">-S</span> Mojolicious</pre></div></div></div>

<p>ユーザー権限でインストールした場合は、ホームディレクトリ ~/perl5/lib/ 以下にインストールされるので、この場合はPATHの指定が必要。コード側に書くか、あらかじめ設定しておく必要がある。<br />
Apacheのconfigに設定するのが吉かな？</p>
<p>httpd.confに記述</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="apache" style="font-family:monospace;"><span style="color: #00007f;">SetEnv</span> PERL5LIB /Users/clicktx/perl5/lib/perl5</pre></div></div></div>

<li><a href="http://www.xdelta.net/wiki/Perl/@INC.html">KMsWiki: Perl/@INC &#8211; Perlのライブラリの検索PATHを格納した配列のこと。 例えば、コマンド&#8230;</a></li>
<li><a href="http://okwave.jp/qa/q3543374.html">CGIでの環境変数PERL5LIBの設定 | OKWave</a></li>
<h4>MAMPでCGI(perl)を実行できるようにする</h4>
<p>/Applications/MAMP/conf/apache/httpd.conf を編集する。自分の場合は /Applications/MAMP/htdocs以下全部で実行したいので以下の場所を変更。</p>
<p>453行目付近</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="apache" style="font-family:monospace;">    <span style="color: #adadad; font-style: italic;">#AddHandler cgi-script .cgi</span>
    <span style="color: #00007f;">AddHandler</span> cgi-<span style="color: #00007f;">script</span> .cgi .pl .pm ←追記</pre></div></div></div>

<p>httpd.confを編集したらMANPを再起動して設定を反映させる。</p>
<h3>CGI実行テスト</h3>
<p>/アプリケーション/MAMP/htdocs/ に test.cgiを作成する。</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;">#!/usr/bin/env perl</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Content-type:text/html<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Hello, World!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">exit</span><span style="color: #339933;">;</span></pre></div></div></div>

<p>test.cgi に実行権を与える。</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="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>MANP<span style="color: #000000; font-weight: bold;">/</span>htdocs
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> test.cgi</pre></div></div></div>

<p>webブラウザで http://localhost/test.cgi にアクセスして表示されたら成功。</p>
<p>ちなみにMAMPの読み方はまんｐーでいいんじゃないでしょうか？</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/12/15/manmpapachemysql%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%83%bc%e3%82%ab%e3%83%ab%e3%81%a7%e3%82%89%e3%81%8f%e3%82%89%e3%81%8fperl%e9%96%8b%e7%99%ba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://perl.no-tubo.net/2011/12/15/manmpapachemysql%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%83%bc%e3%82%ab%e3%83%ab%e3%81%a7%e3%82%89%e3%81%8f%e3%82%89%e3%81%8fperl%e9%96%8b%e7%99%ba/" />
	</item>
		<item>
		<title>Business::PayPal::API::ExpressCheckoutで住所とか氏名とかの日本語が正しく送れない理由</title>
		<link>http://perl.no-tubo.net/2011/12/12/businesspaypalapiexpresscheckout%e3%81%a7%e4%bd%8f%e6%89%80%e3%81%a8%e3%81%8b%e6%b0%8f%e5%90%8d%e3%81%a8%e3%81%8b%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%81%8c%e6%ad%a3%e3%81%97%e3%81%8f%e9%80%81/</link>
		<comments>http://perl.no-tubo.net/2011/12/12/businesspaypalapiexpresscheckout%e3%81%a7%e4%bd%8f%e6%89%80%e3%81%a8%e3%81%8b%e6%b0%8f%e5%90%8d%e3%81%a8%e3%81%8b%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%81%8c%e6%ad%a3%e3%81%97%e3%81%8f%e9%80%81/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 12:24:36 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[PayPal]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[Business::PayPal::API]]></category>
		<category><![CDATA[SOAP::Lite]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1851</guid>
		<description><![CDATA[PerlでPayPalのExpressCheckoutを実装するのにBusiness::PayPal::APIを使っているのだけれど、日本語（2byte文字）がうまく送信できない。
UTF-8で送ろうが、フラグ付きにしよ [...]]]></description>
			<content:encoded><![CDATA[<p>PerlでPayPalのExpressCheckoutを実装するのにBusiness::PayPal::APIを使っているのだけれど、日本語（2byte文字）がうまく送信できない。</p>
<p>UTF-8で送ろうが、フラグ付きにしようが、だ。</p>
<p>散々悩んだ挙句、原因はSOAP::Liteが勝手にbase64エンコードするからだと判明。</p>
<p>Business::PayPal::APIは内部でSOAP::Liteを使用していて、Asciiだとそのままなのだけれど、それ以外はbase64にエンコードする仕様の様子。</p>
<p>前々から、例えば、OrderDescription に日本語を使うと上手くいかないと思っていたのだけれど、、、。<br />
仕方がないから Business::PayPal::API::ExpressCheckoutをカスタマイズする。</p>
<p>/usr/lib/perl5/site_perl/5.8.8/Business/PayPal/API/ExpressCheckout.pm</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;">## add all the other fields</span>
    <span style="color: #b1b100;">for</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$field</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066;">keys</span> <span style="color: #0000ff;">%types</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">next</span> <span style="color: #b1b100;">unless</span> <span style="color: #000066;">defined</span> <span style="color: #0000ff;">$args</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$field</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$field</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'MaxAmount'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">push</span> <span style="color: #0000ff;">@secrd</span><span style="color: #339933;">,</span> SOAP<span style="color: #339933;">::</span><span style="color: #006600;">Data</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">name</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$field</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$args</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$field</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">type</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$types</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$field</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span>
              <span style="color: #339933;">-&gt;</span><span style="color: #006600;">attr</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span>currencyID <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$currencyID</span><span style="color: #339933;">,</span> xmlns <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">C_xmlns_ebay</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #666666; font-style: italic;">## 追記ココから</span>
        <span style="color: #b1b100;">elsif</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$field</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'Address'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@addr</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$hash</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$args</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$field</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">for</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$f</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066;">keys</span> <span style="color: #0000ff;">%$hash</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000066;">push</span> <span style="color: #0000ff;">@addr</span><span style="color: #339933;">,</span>  SOAP<span style="color: #339933;">::</span><span style="color: #006600;">Data</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">name</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$f</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">type</span><span style="color: #009900;">&#40;</span>string <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$args</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$field</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$f</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$obj</span> <span style="color: #339933;">=</span> SOAP<span style="color: #339933;">::</span><span style="color: #006600;">Data</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">name</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$field</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">\SOAP</span><span style="color: #339933;">::</span><span style="color: #006600;">Data</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">value</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@addr</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">push</span> <span style="color: #0000ff;">@secrd</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$obj</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #666666; font-style: italic;">## 追記ココまで</span>
        <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">push</span> <span style="color: #0000ff;">@secrd</span><span style="color: #339933;">,</span> SOAP<span style="color: #339933;">::</span><span style="color: #006600;">Data</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">name</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$field</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$args</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$field</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">type</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$types</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$field</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div></div>

<p>SOAPなんて使ってたらダメだね&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/12/12/businesspaypalapiexpresscheckout%e3%81%a7%e4%bd%8f%e6%89%80%e3%81%a8%e3%81%8b%e6%b0%8f%e5%90%8d%e3%81%a8%e3%81%8b%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%81%8c%e6%ad%a3%e3%81%97%e3%81%8f%e9%80%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/12/12/businesspaypalapiexpresscheckout%e3%81%a7%e4%bd%8f%e6%89%80%e3%81%a8%e3%81%8b%e6%b0%8f%e5%90%8d%e3%81%a8%e3%81%8b%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%81%8c%e6%ad%a3%e3%81%97%e3%81%8f%e9%80%81/" />
	</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>perl SpeedyCGIでデータベースの接続を永続化する</title>
		<link>http://perl.no-tubo.net/2011/04/01/perl-speedycgi%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e6%8e%a5%e7%b6%9a%e3%82%92%e6%b0%b8%e7%b6%9a%e5%8c%96%e3%81%99%e3%82%8b/</link>
		<comments>http://perl.no-tubo.net/2011/04/01/perl-speedycgi%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e6%8e%a5%e7%b6%9a%e3%82%92%e6%b0%b8%e7%b6%9a%e5%8c%96%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 07:36:53 +0000</pubDate>
		<dc:creator>clicktx</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[DBI]]></category>
		<category><![CDATA[speedyCGI]]></category>
		<category><![CDATA[データベース]]></category>

		<guid isPermaLink="false">http://perl.no-tubo.net/?p=1555</guid>
		<description><![CDATA[perlスクリプトをSpeedyCGIスクリプトとして動作させる場合、グローバル変数の値は保持され続ける。なので、一度接続したデータベースハンドルを使い回すことでデータベースへの接続コストを削減できる。
テスト用スクリプ [...]]]></description>
			<content:encoded><![CDATA[<p>perlスクリプトをSpeedyCGIスクリプトとして動作させる場合、グローバル変数の値は保持され続ける。なので、一度接続したデータベースハンドルを使い回すことでデータベースへの接続コストを削減できる。</p>
<p>テスト用スクリプト<span id="more-1555"></span></p>
<pre>#!/usr/bin/speedy

use strict;
use warnings;
use DBI;

<span style="color: #ff9900;">#DB用設定</span>
my $db_user = 'db_user_name';
my $db_pass = 'db_password';
my $db_name = 'db_name';
my $db_host = 'localhost';
my $dbi = "DBI:mysql:$db_name:$db_host";

<span style="color: #ff9900;"># テスト用</span>
print "content-type:text/html;\n\n";
our $c;
$c=1 if !$c;
print "($c回目)\n";
$c++;

our $dbh;    <span style="color: #ff9900;"># データベースハンドルは our でグローバル変数を宣言する必要がある。</span>
my  $db_connect_flag;

<span style="color: #ff9900;"># $dbhがある場合データベースハンドルが有効かチェック</span>
eval{
    $db_connect_flag = $dbh-&gt;ping;
    print "DB check.\n";  <span style="color: #ff9900;"># ２回目以降はチェック(テスト用)</span>
} if defined($dbh);

<span style="color: #ff9900;"># 未接続ならDBに接続する</span>
if(!$db_connect_flag){
    eval {
        $dbh = DBI-&gt;connect($dbi, $db_user, $db_pass)|| die $dbh-&gt;errstr;
    };
    <span style="color: #ff9900;"># 接続エラーならエラー処理</span>
    error("DB could not connect.")  if $@;
    print "DB conect OK.\n";   <span style="color: #ff9900;"># 初回は接続(テスト用)</span>
}
exit;</pre>
<p>ポイントとしては our $dbh; としてグローバル変数宣言する事。my でレキシカル変数を宣言してしまうと毎回初期化されてしまう。</p>
<p>defined で $dbh が定義済みか調べて、定義済みなら ping を送って有効か調べる。無効ならデータベースへ接続する。</p>
<p>必要な部分はこんな感じ。</p>
<pre>our $dbh;
my  $db_connect_flag;

<span style="color: #ff9900;"># $dbhがある場合データベースハンドルが有効かチェック</span>
eval{ $db_connect_flag = $dbh-&gt;ping; } if defined($dbh);

<span style="color: #ff9900;"># 未接続ならDBに接続する</span>
if(!$db_connect_flag){
    eval {
        $dbh = DBI-&gt;connect($dbi, $db_user, $db_pass) || die $dbh-&gt;errstr;
    };
    <span style="color: #ff9900;"># 接続エラーならエラー処理</span>
    error("DB could not connect.")  if $@;
}</pre>
<p>あくまでSpeedyCGIでのスクリプトで、FastCGIの場合とかは違うかも。</p>
]]></content:encoded>
			<wfw:commentRss>http://perl.no-tubo.net/2011/04/01/perl-speedycgi%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e6%8e%a5%e7%b6%9a%e3%82%92%e6%b0%b8%e7%b6%9a%e5%8c%96%e3%81%99%e3%82%8b/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/01/perl-speedycgi%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e6%8e%a5%e7%b6%9a%e3%82%92%e6%b0%b8%e7%b6%9a%e5%8c%96%e3%81%99%e3%82%8b/" />
	</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>
	</channel>
</rss>

