1. do find => rescue
2. model operation more than 3 lines => define class method in model
3. def current_user
4. render_as_form
5. more than one relation in one table
6. composite primary key => hook
Tuesday, April 28, 2009
Tuesday, April 7, 2009
Class::Implant - No &import() !
Class::implant is a experimental little helper implemented when I developed Railsish with gugod. Manipulating mixin and inheritance outside package is its primary function, also with abilities to select methods which would import.
Original idea is inspire by the purpose: we want to import whole Helper methods into Controller which the Helper is named after. And it is should not be left to framework users to do it by themself. In Ruby, we just need to write
Even use Exporter and edit
Everything done! All methods in XxxHelper is imported into XxxController!
If call
In the release 0.02_01, two other options work.
For example,
means import methods whose name start with h in Foo and Bar into Cat.
I also write UNIVERSAL::Implant. As its name, require once, and write as follow everywhere.
Do the same thing as previous example. That means, caller package Cat assign
Chinese Version is @ Chupei.pm.org
Original idea is inspire by the purpose: we want to import whole Helper methods into Controller which the Helper is named after. And it is should not be left to framework users to do it by themself. In Ruby, we just need to write
XxxController.send(:include, XxxHelper)
In Perl, it can also be written aseval qq{ package XxxController; use XxxHelper; }
But a tedious &import() should be write in XxxHelper as follow.and edit the export methods list by hand.sub import {
for (qw(hello world foo bar method...)) {
*{blah::$_} = \&$_
}
}
Even use Exporter and edit
@EXPORT
and export by symbol :all
, users still need to do follow by handClass::Implant provide simplified equivalent.use base Exporter;
our @EXPORT = qw(..);
package main;
use Class::Implant;
implant "XxxHelper", { into => "XxxController" };
Everything done! All methods in XxxHelper is imported into XxxController!
If call
use Class::Implant
in other package, default import target would become it. That means, above code is the same as follow:package XxxController;
use Class::Implant;
implant "XxxHelper";
In the release 0.02_01, two other options work.
{ inherit => 1 }
make imported packages appear in @ISA
of import target. { match => pattern }
filter, and import methods conform to pattern.For example,
package main;
use Class::Implant;
implant qw(Foo Bar), { into => "Cat", match => qr{h\w+} };
means import methods whose name start with h in Foo and Bar into Cat.
I also write UNIVERSAL::Implant. As its name, require once, and write as follow everywhere.
Cat->implant qw(Foo Bar), { match => qr{h\w+} }
Do the same thing as previous example. That means, caller package Cat assign
{ into => "Cat" }
.Chinese Version is @ Chupei.pm.org
Labels:
perl,
perl module
Wednesday, March 25, 2009
Rails on FreeBSD 7.1
Today I was first time trying to install rails on freebsd 7.1. Neither the ports version nor the gem file version, rails could not work, even only simply creating a new project. It returns message as following.
I had try to reinstall ruby, rubygem, and try other version rails but a nonsense. And finally I forgot how did I discover it needs ruby-iconv ports in fact. It seems occurring at the time I was using rails 2.2.2, some keyword appeared in the error message.
One post on the mailing list [Ruby on Rails : Talk] show the same problem. If you also have the same problem, try it.
undefined method `camelize' for "app":String
I had try to reinstall ruby, rubygem, and try other version rails but a nonsense. And finally I forgot how did I discover it needs ruby-iconv ports in fact. It seems occurring at the time I was using rails 2.2.2, some keyword appeared in the error message.
One post on the mailing list [Ruby on Rails : Talk] show the same problem. If you also have the same problem, try it.
Saturday, March 14, 2009
REPL in Perl
Read-Evaluate-Print Loop 在現代語言中非常常見,諸如 Scheme, Haskell, Ruby, 與 Python 都有內建,實際工作時是非常實用的工具,Perl 6 也即將內建 REPL Shell,Perl 5 則沒有。
這幾天偶然想在 Perl 中使用 REPL,搜尋了一下,在 use.perl.org 得到 2007 年發表的這篇文章,介紹了四個以 Perl 5 實做的 REPL Shell,翻譯如下。
Continue reading REPL in Perl.
這幾天偶然想在 Perl 中使用 REPL,搜尋了一下,在 use.perl.org 得到 2007 年發表的這篇文章,介紹了四個以 Perl 5 實做的 REPL Shell,翻譯如下。
Continue reading REPL in Perl.
Labels:
perl
Monday, March 2, 2009
Friday, January 16, 2009
Thursday, January 8, 2009
摩羯座老公使用說明書
hmmm 只能說很中肯 XDDD
品名:
摩羯座老公
生產日期:
摩羯月(12月22日——1月19日),年份憑個人喜好。
主要成分:
奮鬥力51%,忠誠29%,正直13%,樸實木訥7%。
主要功能:
1、本產品能動性很強,可大量減少用戶勞作時間。
2、能為用戶的生活、情感、物質提供穩定保障。
3、能默默地儘量實現用戶需要。
適用人群:
適用於溫順嫻雅、勤儉節約的女性。
注意事項:
1、不要對該產品的浪漫因子抱有太多期望,不然失望的人一定是用戶。
2、本品在運作時,請別隨意打擾。
3、用戶在使用時,儘量少做錯事,否則要承受其冰冷外殼下的噪音騷擾。
4、別強行把該產品推到熱鬧、繁雜的環境中去。
5、請尊重本產品的勞作能力和對工作的偏愛。
6、用戶如遇到無法解決的障礙時,請立即諮詢「科技紫微星座網」,以免搶修不及時,要到民政局申請繁雜的換貨手續。
禁忌:
太以自我為中心、缺乏家庭經營觀念、無法理解本品事業心的人,為拒絕往來戶;本品對於「小心眼」之類的用戶評鑑頗為敏感,當面使用容易導致突發慘案,慎之。
貯藏:
該產品適宜在可施展抱負的工作環境中生存。
包裝:
看上去嚴謹、正式的包裝材料為宜。
備註:
使用一段時間後,本品的中部易出現膨脹,屬正常現象,不影響正常使用;如有其他影響使用之故障,可送至醫院相關科室進行維修。
Labels:
quote
Saturday, January 3, 2009
GitHub Creator
Install
Setting in ~/.github_creator.ini
Arguments are optional in a Perl module with META.yml.
GitHub Creator's repository and manual on cpan
# cpan Git::Github::Creator
Setting in ~/.github_creator.ini
[github]Then, in local git repository
login_page="https://github.com/login"
account=joe@example.com
password=foobar
remote_name=origin
debug=1
github_creator --name my-project --desc "an awesome thing"
Arguments are optional in a Perl module with META.yml.
GitHub Creator's repository and manual on cpan
Tuesday, December 30, 2008
Subscribe to:
Posts (Atom)