原消息在這裡

2009 年的 YAPC::Asia 將在九月10號、11號舉辨,場地將在東京市目黑區大岡山的東京工業大學校區。已於上周開放講者投稿,目前需要的是 20 分鐘或 40 分鐘的演講,七月 17 日將截止。有興趣參與、順便到東京一遊的讀者,敬請密切注意。

除此之外,目前也正在募款中,請參考這裡。也已經有一些有名的 Perl 社群黑客受邀演講,請參考 JPA Blog

自 2006 年舉辨以來,YAPC::Asia 就一直是規模最大的 YAPC。Perl 之父 Larry Wall、狂人 Damian Conway Ruby 之父松本行弘、日本 Ruby 協會會長高橋征義,都曾經參與過這場盛會。

HTTP::Engine is an abstraction layer over several environments that an web application might be deployed under. For example, CGI, FastCGI, mod_perl, or stand-alone application server. It’s not a full-featured web-appication framework, but a helpful library when writing applications. This kinds of idea is especially tasteful when it comes to testing — because it’s often cumbersome to fully prepare the environment for testing.

Read more…

Poppler 模組

| No Comments | No TrackBacks
最近幾天我寫了一個 Poppler 模組。 將一些 Poppler 主要功能透過 xs 做連結,在裝此模組時,請確定你已經安裝 poppler library , gcc 等等,因為你需要在安裝的時候執行一些編譯動作來將模組編譯並安裝。

Poppler 是一個以 xpdf-3.0 為基礎的 PDF Rendering 函式庫
所以我們可以輕易的利用 poppler 來將 pdf 繪製到 Cairo Context 上頭 (cairo_t*) , 以下是範例:

more progress later...

SD - peer-to-peer bug tracking system

| No Comments | No TrackBacks
今年的 OSDC.TW , Jesse Vincent 的 topic 為 BestPractical 最近的產品 SD ( peer-to-peer bug tracking system )

也是 BugTracking 可以 decentralized 、可以 offline working,不直接相依於中央集成的 WebService。 並且有完整的 Shell 可以使用 (再也不用開煩人的 browser 了) 且每個 SD 的 repository 之間都可以 sync ,甚至或是啟動自己的 WebServer。相當的吸引人。

目前 SD 也支援 Trac , Hiveminder 以及 RT。意思就是說 Perl Module Authors 可以使用 SD 來使用 rt.cpan.org。而下一個階段是要做 GoogleCode 服務的整合,也相當歡迎大家幫忙整合 Github 以及 BugZilla 至 SD。

SD 使用 Perl 所寫成的 Prophet Database,也相當有趣,Module 的說明如下:
Prophet is a distributed database system designed for small to medium scale database applications (currently up to around 50,000 records of Our early targets include things such as bug tracking.

Jesse 的 slide 在這: http://www.slideshare.net/obrajesse/sd-a-p2p-bug-tracking-system
SD 以及 Prophet 的 source code 可以在 github.com 上頭找到。

本篇文章同步刊登於 http://c9s.blogspot.com

Class::Implant - No &import()

| No Comments | No TrackBacks
Class::Implant 是最近和 gugod 寫 Railsish 時,順手實做的模組,可以從 package 外部做 mixin 或是 inheritance,並挑選你想匯入的函式。

最初的目的是因為需要為 Controller 引入同名 Helper 的函式,但是又不想讓使用者在 Controller 裡面寫 use XxxHelper ,在 Rails 裡面,這只要在載入類別時進行
XxxController.send(:include, XxxHelper)
就可以辦到,雖然 Perl 裡面也可以寫
eval qq{ package XxxController; use XxxHelper; };
但是這樣還需要自己定義 XxxHelper::import(),在裡面指定想匯入的函式,實在相當不便。

使用 Class::Implant 的話,可以有比較簡單的等價寫法,
pacakge main;
use Class::Implant;
implant "XxxHelper", { into => "XxxController" };
如同其字面的意思,把 XxxHelper 中所有的函式都注入了 XxxController。

如果在 main 以外的模組內的話,預設的匯入目標就會變成該模組。也就是說,以上範例可以等價寫成如下:
package XxxController;
use Class::Implant;
implant "XxxHelper";
目前 0.02_01 版的實做還有 match 和 inherit 兩個選項可以使用,{ inherit => 1 } 可以讓匯入的模組出現在匯入目標的 @ISA 中,{ match => pattern } 則是只匯入符合 pattern 的函式。

如:
package main;
use Class::Implant;
implant qw(Foo Bar), { into => "Cat", match => qr{h\w+} };

代表只把 Foo,Bar 中 h 開頭的函式匯入 Cat 中。

同時還有 UNIVERSAL::Implant 模組,如同字面意思,這個模組只需要匯入一次,就可以在任何地方這樣寫:

Cat->implant qw(Foo Bar), { match => qr{h\w+} } 

這上一個範例是一樣的效果,也就是由呼叫類別 Cat 指定了 { into => "Cat" }。

Parrot 1.0.0 "Haru Tatsu" Released!

| No Comments | No TrackBacks
Perl 6 實做品之一的 Parrot 已於 2009/3/17 釋出 1.0.0 版本,消息發佈於 http://www.parrot.org/news/2009/Parrot-1.0.0

***
allison 著, shelling

代表 Parrot 開發團隊,我很榮幸在此發佈 Parrot 1.0.0 "Haru Tatsu"。Parrot 是一個支援多種動態語言的虛擬機 (virtual machine)。

Parrot 1.0.0 可以從 Parrot 的 FTP 站下載引導頁來下載,對於想要在 Parrot 上開發或是協助開發 Parrot 的人,我們建議使用 Subversion 從我們的源碼庫取得最新的原始碼。

Parrot 1.0.0 新特色如下:

- 文件
  + 給使用者的新版例外處理文件
  + 更新 Parrot Book 的第四和第五章
  + 改善和擴充自動生成的文件,如 http://docs.parrot.org/ 所示
  + 新增 CHM 格式的 Help 文件
  + 修正和改善許多部份
- 語言
  + Pynie
    - 獨立出來置於 http://pynie.googlecode.com/
  + Cardinal
    - 獨立出來置於 http://github.com/cardinal
  + APL
    - 獨立出來置於 http://paraplegic.googlecode.com/
  + ABC, Squaak 和 Befunge 移到 examples/
  + 剩下的語言移至 https://svn.parrot.org/languages/
- 工具
  + 支援從已安裝的 Parrot 進行 language builds 
  + 擴充給新語言使用的 language shell generator
  + 新增 'parrotbug' 工具集對 Trac 的介面
- 準廢棄
  + 移除準廢棄的 Tqueue 和 Closure PMCs
  + String, Key, NCI, LexPad, Sub, Contnuation,
    RetContinuation, ExceptionHandler, ParrotLibrary,
    ParrotInterpreter, ParrotThread, ParrotRunningThread,
    Rational, FixedPMCArray, ResizablePMCArray, and GDBMHash
    PMCs now use declared attributes (ATTR), in place of the
    deprecated UnionVal .
***

REPL in Perl

| No Comments | No TrackBacks
Read-Evaluate-Print Loop 在現代語言中非常常見,諸如 Scheme, Haskell, Ruby, 與 Python 都有內建,實際工作時是非常實用的工具,Perl 6 也即將內建 REPL Shell,Perl 5 則沒有。

這幾天偶然想在 Perl 中使用 REPL,搜尋了一下,在 use.perl.org 得到 2007 年發表的這篇文章,介紹了四個以 Perl 5 實做的 REPL Shell,翻譯如下。

2009 年由於二月、三月都是 13 號星期五,所以還搞了部電影出來。不過讓我比較好奇的是:一年之中最多會有幾個十三號星期五?

大致上翻了一下月曆發現好像都不會超過三個。於是寫了個程式來測試一下:

輸出大約是這樣

1 black Friday in the year 2000: 2000-10-13
2 black Fridays in the year 2001: 2001-4-13 2001-7-13
2 black Fridays in the year 2002: 2002-9-13 2002-12-13
1 black Friday in the year 2003: 2003-6-13
2 black Fridays in the year 2004: 2004-2-13 2004-8-13
1 black Friday in the year 2005: 2005-5-13
2 black Fridays in the year 2006: 2006-1-13 2006-10-13
2 black Fridays in the year 2007: 2007-4-13 2007-7-13
1 black Friday in the year 2008: 2008-6-13
3 black Fridays in the year 2009: 2009-2-13 2009-3-13 2009-11-13
1 black Friday in the year 2010: 2010-8-13
1 black Friday in the year 2011: 2011-5-13
3 black Fridays in the year 2012: 2012-1-13 2012-4-13 2012-7-13
2 black Fridays in the year 2013: 2013-9-13 2013-12-13
1 black Friday in the year 2014: 2014-6-13
3 black Fridays in the year 2015: 2015-2-13 2015-3-13 2015-11-13
1 black Friday in the year 2016: 2016-5-13
2 black Fridays in the year 2017: 2017-1-13 2017-10-13
2 black Fridays in the year 2018: 2018-4-13 2018-7-13
2 black Fridays in the year 2019: 2019-9-13 2019-12-13
2 black Fridays in the year 2020: 2020-3-13 2020-11-13
1 black Friday in the year 2021: 2021-8-13
1 black Friday in the year 2022: 2022-5-13
.... (略)

跑完這個程式發現未來一萬年之中都不會有超過三個黑色星期五的年份。似乎三個就是上限了。這感覺起來是個不錯的數學證明題目。

而其中有三個黑色星期五的年份,佔了約整體的七分之一。換句話說每七年中就有一年會是三個星色星期五。但從 2009 年開始算的話,未來七年當中的 2012 跟 2015 也都是有三個黑色星期五的年份。比例還真是高。

另一個有趣的事實則是:每年都至少會有一個十三號星期五。

miyagawalopnortypester 都指出,剛剛釋出的 Mac OSX Security Update 2009-001 可能會把你機器上的 Perl / cpan 搞壞了。如果你平常工作的 Perl 環境是:

  • Mac OSX 10.5 Leopard
  • 使用 Mac 內附的 Perl
  • 曾經利用 CPAN 升級過幾個核心模組

使用 MacPorts 的 Perl 者,或從未使用 cpan 更新模組的者,則無需擔心。

可以使用以下這一行指令來測試是是否正常

/usr/bin/perl -MIO -le 'print "ok"'

如果你看見它印出 “ok” 則沒問題,若看見像這樣的訊息,就表示壞了:

IO object version 1.22 does not match bootstrap parameter 1.23
at /System/Library/Perl/5.8.8/darwin-thread-multi-2level/XSLoader.pm
line 94.

Compilation failed in require.
BEGIN failed--compilation aborted.

這段訊息出現的原因,乃是因為核心模組 IO.bundle 1.22 版被包含在 Mac OSX Security Update 2009-001 當中。只要你曾經升級 IO.pm 到 1.23 版,那就會出現如上的「版本不符」的死亡錯誤訊息。

解決辨法是再裝一次 1.23 版的 IO 模組。

但糟的是,由於它是 IO 模組,所以你無法使用一般的 cpan 指令(因為一執行 cpan 就要載入 IO 模組),所以只能手動下載 IO-1.2301 tarball ,解開之後執行 perl Makefile.PL; make; make install

IO-1.2301 早在 2006 年就已經釋出了,是個非常穩定的版本,Apple 你為什麼要故意散佈一個 1.22 版的 IO.bundle 呢?

Sub::Alias - 替函式取別名

| No Comments | 1 TrackBack

最近在寫的 Sub::Alias 模組能夠很便利地替函式取別名:

use Sub::Alias;

sub name { "..." }

alias get_name => 'name';