今さらTheSchwartzを使い始めました。
で、jobの状態を監視するWebインターフェースをCatalystで作ることになったのですが、いちいちTheSchwartzのインスタンスを作るのが面倒くさい。
でもそのためにModel作るのもアホらしい。
で、Catalyst::Model::Adaptorを使ってMyApp::Model::TheSchwartzを作ってモデルとして使うのをやってみたのでメモ。

HelperスクリプトでMyApp::Model::TheSchwartzを作成
script/myapp_create.pl model TheSchwartz Adaptor TheSchwartz
出来上がったMyApp::Model::TheSchwartzを変更
package MyApp::Model::TheSchwartz;
use strict;
use warnings;
use base 'Catalyst::Model::Adaptor';

__PACKAGE__->config(
    class       => 'TheSchwartz',
    constructor => 'new',
);

sub prepare_arguments {
    my ( $self, $app ) = @_;

    my $args = $app->config->{"Model::TheSchwartz"};
    return $args;
}

sub mangle_arguments {
    my ( $self, $args ) = @_;

    return %$args;
}

1;
myapp.ymlに接続情報を追加
Model::TheSchwartz:
  databases:
    -
      dsn: dbi:mysql:theschwartz
      user: root
      pass:

コントローラとかで

jobを登録
$c->model('TheSchwartz')->insert($job);
jobのリストを取得
my @jobs = $c->model('TheSchwartz')->list_jobs({'funcname' => 'MyApp::Worker'});

楽勝。

              

              

トラックバック(1)

トラックバックURL: http://mt.hide-k.net/mt-tb.cgi/732

TheSchwartz.pmをCatalyst::Model::AdaptorでModel化して扱う時のメモ。次のURLを参考にして設定を行ったのだが問題... 続きを読む

コメントする

プロフィール

このブログ記事について

このページは、hideが2008年2月14日 16:51に書いたブログ記事です。

ひとつ前のブログ記事は「雪だるま」です。

次のブログ記事は「巻き込み重要」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。