View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
劉康民 > Kwiki-DB > Kwiki::DB::ClassDBI



Annotate this POD


New  1
Open  0
View/Report Bugs
Module Version: 0.03   Source  


  Kwiki::DB::ClassDBI - A Class::DBI wrapper for Kwiki


  package Kwiki::MyPlugin;
  use Kwiki::Plugin -Base;

  # setup Music::Artist and Music::CD as in Class::DBI pod.
  sub init {
      $self->hub->config->add_field("db_class" => 'Kwiki::DB::DBI');
      field db => -init => "\$self->hub->load_class('db')";

      $self->db->entity( artist => 'Music::Artist' );
      $self->db->entity(     cd => 'Music::CD'     );

  sub my_action {


This module privdes a bridge between Class::DBI and Kwiki programming environment. After adding Kwiki::DB::ClassDBI into your plugins file, there will be a convienent $self->hub->cdbi reference to an instantiated object which acts as the door to all your Class::DBI based classes.

Instead of using class name to access data, this module requires you give several "entity" names in the init phrase. Each entity has a short name, and a corresponding Class::DBI based class name. Writing

    $self->hub->cdbi->entity( artist => 'Music::Artist' );

would create a object held in $self->db->artist, and delegates all methods to Music::Artist. So these two lines are doing the same work:

    $self->hub->cdbi->artist->create({ artistid => 1, name => 'U2' });
    Music::Artist->create({ artistid => 1, name => 'U2' });

They return the same type of value, because $self->db->artist only delegates the create method to Music::Artist.

People could even directly use the $hub->db to access database in their kwiki template like this:

    The band is [% hub.db.artist.retrieve(1).name %].

Also, you may want to read the test t/02.classdbi-sqlite.t and t/lib/Kwiki/DB/Music* as a live example for how to use this bridge.


Class::DBI, Kwiki::DB::DBI


Copyright 2005 by Kang-min Liu <>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <>

syntax highlighting: