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

<channel>
	<title>ものぐさ備忘録 &#187; interactive mode</title>
	<atom:link href="http://www.ginriki.net/wd/category/interactive-mode/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ginriki.net/wd</link>
	<description>ソフトウェア関係の話を中心とした備忘録的日記</description>
	<lastBuildDate>Sun, 11 Jul 2010 15:48:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Perlの補完機能付きインタラクティブモード perlsh</title>
		<link>http://www.ginriki.net/wd/2008/09/28/42/</link>
		<comments>http://www.ginriki.net/wd/2008/09/28/42/#comments</comments>
		<pubDate>Sat, 27 Sep 2008 16:11:15 +0000</pubDate>
		<dc:creator>ginriki</dc:creator>
				<category><![CDATA[interactive mode]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[インタラクティブモード]]></category>

		<guid isPermaLink="false">http://www.gikogeek.net/wd/?p=42</guid>
		<description><![CDATA[前回の記事の続き。
今回はperl。
探してみると、やっぱり対話型インターフェイスを作ってる方がいますね。
メソッド名などの補完も行ってくれるものとして、perlshがありました。
perlshは、Term::ReadL [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.gikogeek.net/wd/2008/09/25/41/'>前回の記事</a>の続き。</p>
<p>今回はperl。</p>
<p>探してみると、やっぱり対話型インターフェイスを作ってる方がいますね。<br />
メソッド名などの補完も行ってくれるものとして、perlshがありました。<br />
perlshは、Term::ReadLine::Gnuライブラリに付属してます。</p>
<p>Term::ReadLine::Gnuのインストールには、cpanを使うと便利です。<br />
普通にyum install perlとかしとけば、cpanコマンドも付いてくるっぽい。</p>
<p>ただ、私のCentOS 5.1だと、cpan経由のライブラリダウンロードURL (urllist)の<br />
設定がされてなかったので、下記リンク先を参考にしてurllistを設定しました。<br />
<a href='http://www.drk7.jp/MT/archives/000885.html'>http://www.drk7.jp/MT/archives/000885.html</a></p>
<p>そして、Term::ReadLine::Gnuライブラリをインストールするわけなんですが、<br />
事前にreadlineライブラリ等をyumなどを使ってインストールしとかないと、うまくインストールできないらしいです<sup>1</sup>。<br />
私の環境では、すでにインストール済みだったので、特に問題ありませんでした。</p>
<p>Term::ReadLine::Gnuライブラリのインストールからperlshを使うまでの流れは以下、</p>
<pre>
$ cpan install Term::ReadLine::Gnu
$ perl ~/.cpan/build/Term-ReadLine-Gnu-1.17/eg/perlsh
main[1]$ use utf8
main[2]$ utf8::　[TAB]
utf8::             downgrade          is_utf8            unimport
AUTOLOAD           encode             native_to_unicode  upgrade
decode             import             unicode_to_native  valid
main[2]$ exit   #終了
</pre>
<p>perlshファイルは、実行パスの通ってるディレクトリに入れておくと起動が楽です。</p>
<ol class="footnotes"><li id="footnote_0_42" class="footnote"><a href='http://www.hasta-pronto.org/archives/2006/08/20-0408.php'>http://www.hasta-pronto.org/archives/2006/08/20-0408.php</a>参照</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.ginriki.net/wd/2008/09/28/42/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PythonのインタラクティブモードでTab補完を使う</title>
		<link>http://www.ginriki.net/wd/2008/09/25/41/</link>
		<comments>http://www.ginriki.net/wd/2008/09/25/41/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 16:31:54 +0000</pubDate>
		<dc:creator>ginriki</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[interactive mode]]></category>
		<category><![CDATA[インタラクティブモード]]></category>

		<guid isPermaLink="false">http://www.gikogeek.net/wd/?p=41</guid>
		<description><![CDATA[昨日の記事の続き
このまま、各言語のインタラクティブモードの補完機能について書いてけば、
しばらくネタに困らないので続けよう。
今回はPythonです。
pythonの場合、引数なしで起動すればインタラクティブモードにな [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.gikogeek.net/wd/2008/09/24/40/'>昨日の記事</a>の続き</p>
<p>このまま、各言語のインタラクティブモードの補完機能について書いてけば、<br />
しばらくネタに困らないので続けよう。</p>
<p>今回はPythonです。</p>
<p>pythonの場合、引数なしで起動すればインタラクティブモードになりますが、<br />
下記のようにrlcompleterをimportすることで、補完機能が使えます。<br />
ただし、readlineライブラリが必要です。Linuxとかなら、yum install pythonで普通に入るようです。</p>
<div class="igBar"><span id="lpython-2"><a href="#" onclick="javascript:showPlainTxt('python-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PYTHON:</span>
<div id="python-2">
<div class="python">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$ python</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&gt;&gt;&gt; <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">rlcompleter</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&gt;&gt;&gt; <span style="color: #dc143c;">rlcompleter</span>.<span style="color: #dc143c;">readline</span>.<span style="color: black;">parse_and_bind</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'tab: complete'</span><span style="color: black;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&gt;&gt;&gt; di <span style="color: black;">&#91;</span>TAB<span style="color: black;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008000;">dict</span>&nbsp; &nbsp; <span style="color: #008000;">dir</span>&nbsp; &nbsp; &nbsp;<span style="color: #008000;">divmod</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&gt;&gt;&gt; di </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Windowsの人は、<a href='http://newcenturycomputers.net/projects/readline.html'>Python Alternative Readline</a>をインストールするのが楽だと思います。</p>
<p>若干、通常のreadlineと挙動が違うのがアレですが・・・。</p>
<h4>参考サイト</h4>
<ul>
<li><a href='http://d.hatena.ne.jp/maedana/20070813/1186992559'>http://d.hatena.ne.jp/maedana/20070813/1186992559</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ginriki.net/wd/2008/09/25/41/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Interactive ShellによるPHP対話入力補完</title>
		<link>http://www.ginriki.net/wd/2008/09/24/40/</link>
		<comments>http://www.ginriki.net/wd/2008/09/24/40/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 18:39:59 +0000</pubDate>
		<dc:creator>ginriki</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[interactive mode]]></category>
		<category><![CDATA[インタラクティブモード]]></category>

		<guid isPermaLink="false">http://www.gikogeek.net/wd/?p=40</guid>
		<description><![CDATA[この前の記事の続き。
rubyには、irbっていうinteractive modeあります。
irb実行中に、 require 'irb/completion' すると、TABでメソッド名等の補完ができるようになって大変 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gikogeek.net/wd/2008/09/08/10/">この前の記事</a>の続き。</p>
<p>rubyには、irbっていうinteractive modeあります。<br />
irb実行中に、 require 'irb/completion' すると、TABでメソッド名等の補完ができるようになって大変便利です。</p>
<p>PHPのinteractive modeでも同じことができないかなと思い、<br />
探してみたところ、PHP5.1 から標準で導入されてることがわかりました<sup>1</sup>。</p>
<p>ただし、--with-readline付きでＰＨＰをコンパイルした場合に限ります。<sup>2</sup></p>
<p>yumでインストールしたPHPは、--with-readlineが付いてないので、<sup>3</sup><br />
PHP-cliだけソースコードからもう一度コンパイルしてみました。</p>
<p>環境は、CentOS 5.1です。</p>
<pre>
$ wget http://jp2.php.net/get/php-5.2.6.tar.gz/from/jp.php.net/mirror
$ tar xzvf php-5.2.6.tar.gz
$ cd php-5.2.6/
$ yum install libxml2-devel
$ yum install readline-devel
$ ./configure --prefix=~/local --disable-cgi --with-readline
$ make
$ make install
$ ~/local/bin/php -a
Interactive shell

php &gt; get_class  [TAB]
get_class          get_class_methods  get_class_vars
php &gt; get_class
</pre>
<p>うむ、便利だ。</p>
<ol class="footnotes"><li id="footnote_0_40" class="footnote">補完機能付きのinteractive modeは、Interactive Shellっていう名称が付いてます。</li><li id="footnote_1_40" class="footnote">なんで、readlineを動的リンクするだけで使えるようにしてないんだー</li><li id="footnote_2_40" class="footnote">少なくとも、CentOS 5.1のyumでインストールしたPHPは--with-readlineはついてませんでした。</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.ginriki.net/wd/2008/09/24/40/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHPインタラクティブモードの便利な使い方</title>
		<link>http://www.ginriki.net/wd/2008/09/08/10/</link>
		<comments>http://www.ginriki.net/wd/2008/09/08/10/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 17:28:44 +0000</pubDate>
		<dc:creator>ginriki</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[interactive mode]]></category>
		<category><![CDATA[LL]]></category>
		<category><![CDATA[インタラクティブモード]]></category>

		<guid isPermaLink="false">http://www.gikogeek.net/wd/?p=10</guid>
		<description><![CDATA[ブログに書くネタは結構あるんだけど、整理してから書こうとするとなかなか書けない・・・。
しょうがないんで、ネタは小出しに書くことにしよう。
PHPで何かのライブラリのオブジェクトを使う際、どんなメソッドがある]]></description>
			<content:encoded><![CDATA[<p>ブログに書くネタは結構あるんだけど、整理してから書こうとするとなかなか書けない・・・。</p>
<p>しょうがないんで、ネタは小出しに書くことにしよう。</p>
<p>PHPで何かのライブラリのオブジェクトを使う際、どんなメソッドがあるのかよくわからにことが多々あります。リファレンスを見りゃいいんですが、それが面倒な時は、PHP (CLI)のインタラクティブモードを使うと便利です。</p>
<p>インタラクティブモードの場合、statementが完成するたびに(セミコロンで区切られるたびに）処理が実行されるようです。</p>
<div class="igBar"><span id="lphp-4"><a href="#" onclick="javascript:showPlainTxt('php-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-4">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$ php -a</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$methods</span> = <a href="http://www.php.net/get_class_methods"><span style="color:#000066;">get_class_methods</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">new</span> XMLReader<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/print_r"><span style="color:#000066;">print_r</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$methods</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/array"><span style="color:#000066;">Array</span></a></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> =&gt; close</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> =&gt; getAttribute</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">...</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC66CC;color:#800000;">24</span><span style="color:#006600; font-weight:bold;">&#93;</span> =&gt; expand</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#40;</span>Windowsだと Ctrl-Zで終了<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">$ </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>インタラクティブモードで、よく利用する関数は以下　（全部、リフレクション系関数）、</p>
<ul>
<li>get_class_methods( mixed $class_name )  [クラスのメソッドを配列として返す]</li>
<li>get_object_vars ( object $object ) [オブジェクトのプロパティを配列として返す]</li>
<li>get_declared_classes(void) [定義済のクラスの名前を配列として返す]</li>
<li>get_defined_functions(void) [定義済の関数の名前を配列として返す]</li>
<li>get_defined_vars(void) [定義済の変数の名前を配列として返す]</li>
<li>get_loaded_extensions(void) [コンパイル/ロードされている全てのモジュールの名前を配列として返す]</li>
<li>get_extension_funcs ( string $module_name ) [あるモジュールの関数名を配列として返す]</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ginriki.net/wd/2008/09/08/10/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
