2009-10-27
websequencediagrams をPerlでごにょごにょ
http://www.websequencediagrams.com というサイトを知ってますか?ZIGOROuさんがブログで使っていたので知ったんですが、実に便利っぽいです。専用のダイアグラム構文を書いてサイトにHTTP POSTするとPNGやPDFでシーケンス図を生成して返してくれる代物です。
構文自体とてもシンプルです。
Alice->Bob: Authentication Request
Bob->Alice: Authentication Response
こんな感じでとても簡単&スマートなものなんですが、さらにこいつをプログラマブルに書けたら便利かなー、なんて思ってしまい、Perlでモジュール化してみました。
WebService::WebSequenceDiagrams
github: http://github.com/miki/WebService-WebSequenceDiagrams
使い方
こんな感じです。
use strict; use warnings; use WebService::WebSequenceDiagrams; my $wsd = WebService::WebSequenceDiagrams->new; $wsd->participant( name => 'Bob' ); $wsd->participant( name => 'Alice' ); $wsd->participant( name => 'I have a really\nlong name', as => 'L' ); $wsd->signal( from => 'Alice', to => 'Bob', text => 'Authentication Request', ); $wsd->signal( from => 'Bob', to => 'Alice', text => 'Authentication Response', ); $wsd->signal( from => 'Bob', to => 'L', text => 'Log transaction', ); $wsd->draw( style => "omegapple", outfile => "out.png" );
他にも色々なスタイルで絵が作れます。
use strict; use warnings; use WebService::WebSequenceDiagrams; my $wsd = WebService::WebSequenceDiagrams->new; $wsd->participant( name => "Alice" ); $wsd->participant( name => "Bob" ); $wsd->note( position => "left_of", name => "Alice", text => "This is displayed\nleft of Alice" ); $wsd->note( position => "right_of", name => "Alice", text => "This is displayed right of Alice." ); $wsd->note( position => "over", name => "Alice", text => "This is displayed over Alice." ); $wsd->note( position => "over", name => [ "Alice", "Bob" ], text => "This is displayed over Bob and Alice." ); $wsd->draw( style => 'roundgreen', outfile => "out.png" );
こんなのも出来ます。
use strict; use warnings; use WebService::WebSequenceDiagrams; my $wsd = WebService::WebSequenceDiagrams->new; $wsd->signal( from => "User", to => "A", text => "DoWork" ); $wsd->activate("A"); $wsd->signal( from => "A", to => "B", text => "<<createRequest>>" ); $wsd->activate("B"); $wsd->signal( from => "B", to => "C", text => "DoWork" ); $wsd->activate("C"); $wsd->signal( from => "C", to => "B", text => "WorkDone" ); $wsd->destroy("C"); $wsd->signal( from => "B", to => "A", text => "RequestCreated" ); $wsd->deactivate("B"); $wsd->signal( from => "A", to => "User", text => "Done" ); $wsd->draw( style => 'modern-blue', outfile => "out/ex6.png" );
構文を直接入出力
オリジナルの構文をそのまま入出力することも可能です。
use strict; use warnings; use WebService::WebSequenceDiagrams; my $wsd = WebService::WebSequenceDiagrams->new; my $message =<<"END"; Alice->Bob: Authentication Request alt successful case Bob->Alice: Authentication Accepted else some kind of failure Bob->Alice: Authentication Failure opt loop 1000 times Alice->Bob: DNS Attack end end else Another type of failure Bob->Alice: Please repeat end END $wsd->message($message); $wsd->draw( style => 'modern-blue', outfile => "out.png" );
いちいちプログラマブルに書くのは面倒だよ、という場合はこの方法が楽です。
ちなみに$wsd->message()で出力もできます。
簡単&奇麗なので、ぜひ使ってみてください。
トラックバック - http://d.hatena.ne.jp/download_takeshi/20091027/1256667913
リンク元
- 76 http://d.hatena.ne.jp/
- 71 http://www.google.co.jp/search?hl=ja&client=firefox-a&rls=org.mozilla:ja:official&hs=1Xm&q=gungho+クローラ 使い方&btnG=検索&lr=lang_ja&aq=f&oq=
- 68 http://reader.livedoor.com/reader/
- 64 http://b.hatena.ne.jp/entry/d.hatena.ne.jp/download_takeshi/20091027/1256667913
- 54 http://www.google.co.jp/search?sourceid=navclient&hl=ja&ie=UTF-8&rlz=1T4GGLL_jaJP351JP351&q=git+ダウンロード
- 48 http://b.hatena.ne.jp/entry/d.hatena.ne.jp/download_takeshi/20081124/1227539934
- 25 http://www.google.co.jp/search?hl=ja&lr=lang_ja&client=firefox-a&rls=org.mozilla:ja:official&q=ナイーブ ベイズ分類器 フリー Perl&start=10&sa
- 20 http://search.yahoo.co.jp/search?p=rtmp&search.x=1&fr=top_ga1_sa&tid=top_ga1_sa&ei=UTF-8&aq=&oq=
- 17 http://www.google.co.jp/search?q=ベイズ&lr=lang_ja&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:ja:official&client=firefox-a
- 15 http://okyuu.com/ja/tips/4124




