D-7 <altijd in beweging>

Day to day life of a Perl/Go/C/C++/whatever hacker. May include anything from tech, food, and family.

2010年06月

株式会社ノア様よりJPAに研修の依頼をいただいたので、先週北海道に行ってきました!

何を隠そう、初北海道。日本住まいもやっと6年目の僕にとって北海道のイメージはじゃがいも、とうもろこし、鮭にミルクくらいで、もうあとは北海道はでっかいどうくらいしかでてきません。そんな状況の中、色々と公私にわたって忙しかったのも相まってスライド類を用意した以外はなんの下調べもせずに北海道は札幌に行ったわけです。

とりあえず前の晩に現地に着き、チェックインして飯を食いがてら街へ繰り出すと、場所がすすきのだからでしょうね、もうホストとホステスばかり。別にあなたたちの職業に関しては文句は言わないからせめて道を占拠しないでくれないか。ともあれ、適当に入った回転寿司ははずれ。このあたりからもう少し下調べをしておけばよかったと大分後悔。

二日目は研修。札幌は碁盤の目で、住所も「南2西2」とかわかりやすいので自分みたいな初めての人には大変嬉しい。というわけで時間に若干余裕を持って歩いていった。研修はCatalystに関して。Catalystに限らずWAFとかを教える時に思うのはフレームワークの使い方だけわかってても効率的な開発や問題を解くことに繋がらないからどうしても話題が広がってしまう。本当はもう少しピンポイントでやったほうが教えるほうも教えられるほうも良いかな、とは思う。まぁ時間がない中ではあまり選択肢はないんだけどね。

ともあれ、研修自体は朝からみっちり。また機会があったら是非続きをしたいですね。

夜はLOCALの澤田さん達とお食事。初対面の方達ばかりで正直向こうもどう接したらいいのかとまどったとは思うけどw、いいお話ができたのでよかったです。北海道はある意味関東よりもオープンソースのコミュニティが良い感じで活動できてるんじゃないか・・・?とうっすら思ってしまったくらい良いお話が聞けました。今度活動開始するHokkaido.pmの事も皆様で見守ってあげてください!

ちなみに連れて行ってもらったお店で予約をすると必ず人数分山盛りの刺身盛り合わせが出てくるらしいのだが、それを今まで食べきって他の料理を注文したことがないとのこと。ところがこの日は4人で予約して後から1人増えたのでみんなが「他のものが注文できるぞ!」と沸き立ち、餃子を注文。大変貴重な瞬間に立ち会えた。

その後お腹いっぱいだったのもあったけど、もうワールドカップが始まるのでホテルに帰る。帰り道は大学生くらいの集団があちこちかけずり回ってた。YOSAKOIソーラン祭りってやつだったらしい。街中すごいことになってた。自分は帰ってずっとサッカー観戦。この晩寝たのは午前4時くらい。

そして最終日はなぜか朝6時くらいに起きてしまった。どういうことだ。ともあれ、11時半の飛行機に乗るのに、空いてる時間が微妙。ちょっとぐぐってみたらこの時間にやってそうな施設は札幌中央市場くらいしかなさそうだったのでホテルをチェックアウトしてタクシーで一路市場へ。

タクシーの運転手さんが待っててくれるっていうので貴重品だけもって外部市場をふらふら。適当な店で海鮮丼食ったら2800円。どんなのかと思って期待してたら結構ふつー。うーむ、うまいが・・・2000円くらいにしてくれ・・・。相方にスルメのお土産を買って、一路札幌駅へ。

札幌駅ではトイレに入ったらトイレットペーパーがなくて右往左往したりとかそれなりに色々あったのだが、まぁとりあえず普通に飛行機に乗って帰京。

なお次回8月にまた北海道に行く予定なのだが、気をつけようと思ったこと:

  • ズボンを下げる前にトイレットペーパー(っていうかホルダーさえなかったのだが)の有無を確かめること
  • 新千歳空港から札幌まで意外と電車賃がかかるので現金をちゃんと持ってること。
  • YOSAKOIソーラン祭りの時にはすすきのに近寄らない


写真も結構とったんだけど、またあとで載せる。





    このエントリーをはてなブックマークに追加 mixiチェック


あくまで自分はどうしてるか、って話ですが、最近はCatalystでなんか書くときはこんな感じで使ってます。

my_catalyst_model_setup.png
色んな事がこの図に詰まっているので、箇条書きしてみる:

  • Model::APIがAPIオブジェクトを作成して、使用時にはModel::APIに対して`find()`というメソッドを使って実際のAPIオブジェクトを持ってくる
  • Schema等はMyApp::Schemaに定義し、Model::APIのアトリビュートとして持っている。cacheも同等。これらの初期化引数は設定ファイルのModel::APIから取れるようにしておく
  • Catalyst::Model::DBIC::Schemaは*使ってない*
  • Model::APIではACCEPT_CONTEXTが呼ばれた時点で、もしまだ初期化が行われていなければ、SchemaやAPIの初期化を行っている。Catalyst::Model::Adaptorは*使ってない*
蛇足だけど、Catalyst::Plugin::AuthenticationでStore::DBIx::Classを使うときはどうしてもDBIC::Schema的な形で認証データが入っているモデルを要求されるので、DBIC::Schemaを使いたくなってしまう・・・が、実は単純にその認証データが入っているresultsetが欲しいだけなので、こんな感じの小さいモデルを一個作ってやりすごしている:
    package MyApp::Web::Model::DBIC::Member;
    use Moose;
    use namespace::autoclean;
    BEGIN { extends "Catalyst::Model" }

    has schema => (is => 'rw');

    sub ACCEPT_CONTEXT {
          my ($self, $c) = @_;
          if (! $self->schema) {
              $self->schema( $c->model('API')->schema ); # Model::APIからschemaを盗んでくる
          }
          return $self->schema->resultset('Member');
    }
    __PACKAGE__->meta->make_immutable();
    1;

ちなみに MyApp::CLI::Hogeとかを書くときには、以下のような感じのでやっている:

  • 全部のAPIが必要じゃないことのほうが多いので適時スクリプトの中身によって必要なSchemaやらAPIやらを作成している。(Model::APIに相当するものはない)
  • WithDBICっていうRoleを作って、DBスキーマが必要な場合のSchema生成等のコードを一元化している
  • 引数等はCatalystの設定ファイルを流用するようなことは*してない*。MooseX::Getopt(もしくはMooseX::SimpleConfig)を使ってコマンドラインで --connect_info=dbi:mysql:dbname=hoge と指定できるようにしている
Orochiとか使えたほうがもっと楽な気はするんだけど、とりあえず依存関係を増やすのもあれなのでこんな感じでやっております。
    このエントリーをはてなブックマークに追加 mixiチェック

(This post is posted on my personal blog, since it contains personal rants and what not -- JPA will probably issue some statements after we've talked to the specialists handling these cases)

So since it's probably of general interest, I'm here to let you know that Testuya Kitahara of the Apache Foundation fiasco fame has filed (and has been accepted!!!!) for the trademark of "Perl" in Japan. WTF? Although it's in Japanese, a more detailed history of events can be found around here.

Weee. So some dude is trying to claim that the name "Perl", a language that has been around, used and abused for the past 20+ years, is his to claim. 

(.oO Just to give you some context, this same person is claimed to have been involved with pyramid sales scheme, has attempted to squat on and sell the domain twitter.co.jp to twitter, and is also currently applying to register the words "Ruby" and "Opensource" as his trademark as well )

As the head director of Japan Perl Association (JPA), I'm having to deal with this crud. Sigh. I really don't understand the mind twisting that these kind of people go through to persuade themselves that this is a Good Idea -- and I really hate the fact that both JPA and myself have to spend a significant amount of time and resource on this silly issue.


Anyways, unfortunately the trademark is already accepted. We now have to formally work on repealing it or at least make sure that it does not make working with Perl problematic going forward. So we're going work with specialists, and do the legal dance :/



BTW I've already sent emails to The Perl Foundation's trademark mailing list as well as to friends who I know involved in TPF, but currently no official response has been heard. I wonder what The Perl Foundation is willing to do with all of this. 

I'm not trying to blame TPF or anybody here, but a guidance as to what they want to do with this situation would be most welcome, so here's my public plea :)

Also, this is probably going to cost some amount of money -- probably in the thousands of dollars range. We may have to ask for assistance then. oh well.



Anyway, just a heads up for Perl mongers all over the world, so you know the current situation. Stay tuned.

    このエントリーをはてなブックマークに追加 mixiチェック

Text::Xslate is one of the latest inventions by Goro Fuji. It's yet another template engine -- and since it is yet another template engine, I could easily see everybody going "oh, *another* one....". Yeah, I get the idea. I feel the same for most new template engines.

But I have to say, this time... this one /is/ worth looking at.

First off, it's blazing fast. For trivial tasks, Text::Xslate (ex-slate) is 10 ~ 20 times faster than Template::Toolkit. Check out some of the benchmark scripts in the benchmark directory.

For example, here's demo-tt.pl ran on my Mac OS X:

daisuke@beefcake p5-Text-Xslate$ perl benchmark/demo-tt.pl 
Perl/5.12.1 darwin-2level
Text::Xslate/0.1030
Template/2.22
Template-Toolkit's process() x 1000
1000
Used: 3.457 sec.
Text::Xslate's render() x 1000
1000
Used: 0.207 sec.
In this benchmark, Xslate is about 16.7 times faster than Template-Tookit.

Now usually that kind of speed comes with a significant hit on the template language's usability. 

For example, templates like Mason or Text::MicroTemplate allows you to write raw Perl -- which /is/ good in some situations, but in my line of work, you need a moderately easy language for designers to work on. You can't quite expect designers to be able to decipher Perl code in the templates.

The really cool thing about Text::Xslate is that now it supports a 80 ~ 90% Template-Toolkit compatible template language, with all the variable methods and what not. I just switched my Template::Toolkit based Catalyst app to Text::Xslate with only minor changes in the template -- it was an easy task. And now the template rendering is blazing fast!

To use Text::Xslate in a sort-of-TT-compatible mode, do the following:
use strict;
use Text::Xslate;

my $xslate = Text::Xslate->new(
    syntax => "TTerse",
    module => [
        'Text::Xslate::Bridge::TT2Like',
        # or 'Text::Xslate::Bridge::TT2'
    ]
);
print $xslate->render_string( <<EOT, { foo=> "bar" } );
The value of foo is '[% foo %]'
Its length is [% foo.length() %]
If I perform s/foo/bar/, it becomes [% foo.replace('foo', 'bar') %]
EOT

The use of "TTerse" enables the use of TT compatible template tokens ('[%', '%]'), and enables TT like syntax like WRAPPER, INCLUDE, FOREACH, WHILE, SET, etc. DEFAULT and PROCESS are not supported, but from what I can tell you can live with it.

If you suspect you might have some performance bottleneck in your template rendering, I suggest you seriously consider this template engine. If you are a Catalyst-head like me, you can use my Catalyst::View::Xslate to easily integrate Text::Xslate and Catalyst.


Happy Xslate-ing!
    このエントリーをはてなブックマークに追加 mixiチェック

このページのトップヘ