WWW::CheckPad::Cookbook - WWW::CheckPadのクックブック
このドキュメントにはWWW::CheckPadの典型的な使い方を示すいくつかのサンプルが入っています。
現在、すべての処理は最初にログインしてあることを前提に作られています。 ログイン済みでない場合、dieしてしまいますので、あなたのアプリケーションの中で 最初にログイン処理を実行してください。
なお、将来のバージョンでログインせずに実行できる機能が実装される可能性があります。 例えば、公開されたリストへのアクセス等が考えられるでしょう。
check*padへのログインはWWW::CheckPad->connectで完了します。それが成功したかの判断を 含めて次の例のように書くのが一般的でしょう。
my $checkpad_conenction = WWW::CheckPad->connect( email => 'your@email.com', password => 'password' ); if (not $checkpad_connection->has_logged_in()) { die "ログインに失敗しました。"; }
これだけです。
my @checklists = WWW::CheckList->retrieve_all(); foreach my $checklist (@checklists) { printf ">> %s\n", $checklist->title; }
retrieve_allではすべてが取得されてしまいますが、retrieveを使えば、特定の チェックリストのみを取得できます。
retrieve_all
retrieve
my $checklist = WWW::CheckList->retrieve(111111); # IDを指定する。 # このチェックリストに含まれる、チェック項目を取得する。 my @checkitems = $checklist->checkitems(); # 表示しよう printf "CheckList : %s\n", $checklist->title; foreach my $checkitem (@checkitems) { printf "\t> %s\n", $checkitem->title; }
my $checklist = WWW::CheckList->retrieve(111111); # IDを指定する。 my @unfinished_items = grep { not $_->is_finished() } $checklist->checkitems();
ソースコードを見れば分かるようにチェック項目にはis_finished()というメソッドが あるので、それを利用して、grepすることが出来る。逆に終了済み一覧が欲しければもちろん こうやって書く事が出来る。
is_finished()
grep
my @finished_items = grep { $_->is_finished() } $checklist->checkitems();
もう、何もかもが嫌になったとしよう。Todoなんて糞食らえだ。全部終わった事にしてしまおう。 (作者注:クックブックなんてみてないて、人生をやり直す事を考える事をお勧めする。)
my @checkitems = $checklist->checkitems(); foreach my $checkitem (grep { not $_->is_finished() } @checkitems) { $checkitem->finish(); }
人生をやり直す事以外のアドバイスとしては、finishメソッドを終了済みのチェック項目 に対して呼び出すとエラーとしてdieするので、前もって調べるか、この例のように 最初にgrepすることをお勧めする。
finish
WWW::CheckPad, WWW::CheckPad::CheckList, WWW::CheckPad::CheckItem
Copyright 2006 Ken Takeshige
This text is free document; you can redistribute it and/or modify it under the same terms as Perl itself.
To install WWW::CheckPad, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::CheckPad
CPAN shell
perl -MCPAN -e shell install WWW::CheckPad
For more information on module installation, please visit the detailed CPAN module installation guide.